Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable mocking of functional classes and configurations #892

Merged
merged 3 commits into from
Apr 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* {@link BigQueryException} is thrown the BigQuery Error that caused it, if any, can be accessed
* with {@link BigQueryException#error()}.
*/
public class BigQueryError implements Serializable {
public final class BigQueryError implements Serializable {

static final Function<ErrorProto, BigQueryError> FROM_PB_FUNCTION =
new Function<ErrorProto, BigQueryError>() {
Expand Down Expand Up @@ -98,7 +98,9 @@ public String toString() {

@Override
public boolean equals(Object obj) {
return obj instanceof BigQueryError && Objects.equals(toPb(), ((BigQueryError) obj).toPb());
return obj == this
|| obj instanceof BigQueryError
&& Objects.equals(toPb(), ((BigQueryError) obj).toPb());
}

ErrorProto toPb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ ToStringHelper toStringHelper() {

@Override
public boolean equals(Object obj) {
return obj instanceof CopyJobConfiguration && baseEquals((CopyJobConfiguration) obj);
return obj == this
|| obj instanceof CopyJobConfiguration
&& baseEquals((CopyJobConfiguration) obj);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Google BigQuery options for CSV format. This class wraps some properties of CSV files used by
* BigQuery to parse external data.
*/
public class CsvOptions extends FormatOptions {
public final class CsvOptions extends FormatOptions {

private static final long serialVersionUID = 2193570529308612708L;

Expand Down Expand Up @@ -224,7 +224,9 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
return obj instanceof CsvOptions && Objects.equals(toPb(), ((CsvOptions) obj).toPb());
return obj == this
|| obj instanceof CsvOptions
&& Objects.equals(toPb(), ((CsvOptions) obj).toPb());
}

com.google.api.services.bigquery.model.CsvOptions toPb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* {@link DatasetInfo}.
* </p>
*/
public final class Dataset extends DatasetInfo {
public class Dataset extends DatasetInfo {

private static final long serialVersionUID = -4272921483363065593L;

Expand Down Expand Up @@ -230,14 +230,20 @@ public Builder toBuilder() {
}

@Override
public boolean equals(Object obj) {
return obj instanceof Dataset
&& Objects.equals(toPb(), ((Dataset) obj).toPb())
&& Objects.equals(options, ((Dataset) obj).options);
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !obj.getClass().equals(Dataset.class)) {
return false;
}
Dataset other = (Dataset) obj;
return Objects.equals(toPb(), other.toPb())
&& Objects.equals(options, other.options);
}

@Override
public int hashCode() {
public final int hashCode() {
return Objects.hash(super.hashCode(), options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* Google BigQuery Dataset identity.
*/
public class DatasetId implements Serializable {
public final class DatasetId implements Serializable {

private static final long serialVersionUID = -6186254820908152300L;

Expand Down Expand Up @@ -68,7 +68,9 @@ public static DatasetId of(String dataset) {

@Override
public boolean equals(Object obj) {
return obj instanceof DatasetId && Objects.equals(toPb(), ((DatasetId) obj).toPb());
return obj == this
|| obj instanceof DatasetId
&& Objects.equals(toPb(), ((DatasetId) obj).toPb());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
return obj != null
return obj == this
|| obj != null
&& obj.getClass().equals(DatasetInfo.class)
&& Objects.equals(toPb(), ((DatasetInfo) obj).toPb());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,15 @@ ToStringHelper toStringHelper() {
}

@Override
public boolean equals(Object obj) {
return obj instanceof ExternalTableDefinition && baseEquals((ExternalTableDefinition) obj);
public final boolean equals(Object obj) {

This comment was marked as spam.

return obj == this
|| obj != null
&& obj.getClass().equals(ExternalTableDefinition.class)
&& baseEquals((ExternalTableDefinition) obj);
}

@Override
public int hashCode() {
public final int hashCode() {
return Objects.hash(baseHashCode(), compression, ignoreUnknownValues, maxBadRecords,
formatOptions, sourceUris);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ ToStringHelper toStringHelper() {

@Override
public boolean equals(Object obj) {
return obj instanceof ExtractJobConfiguration && baseEquals((ExtractJobConfiguration) obj);
return obj == this
|| obj instanceof ExtractJobConfiguration
&& baseEquals((ExtractJobConfiguration) obj);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import java.util.Objects;

/**
* Google BigQuery Table field. A table field has a name, a value, a mode and possibly a
* description. Supported types are: {@link Type#integer()}, {@link Type#bool()},
* {@link Type#string()}, {@link Type#floatingPoint()}, {@link Type#timestamp()} and
* {@link Type#record(Field...)}. One or more fields form a table's schema.
* Google BigQuery Table field. A table field has a name, a type, a mode and possibly a description.
* Supported types are: {@link Type#integer()}, {@link Type#bool()}, {@link Type#string()},
* {@link Type#floatingPoint()}, {@link Type#timestamp()} and {@link Type#record(Field...)}. One or
* more fields form a table's schema.
*/
public class Field implements Serializable {
public final class Field implements Serializable {

static final Function<TableFieldSchema, Field> FROM_PB_FUNCTION =
new Function<TableFieldSchema, Field>() {
Expand All @@ -56,6 +56,11 @@ public TableFieldSchema apply(Field field) {

private static final long serialVersionUID = -8154262932305199256L;

private final String name;
private final Type type;
private final String mode;
private final String description;

/**
* Data Types for a BigQuery Table field. This class provides factory methods for all BigQuery
* field types. To instantiate a RECORD value the list of sub-fields must be provided.
Expand Down Expand Up @@ -185,11 +190,6 @@ public enum Mode {
NULLABLE, REQUIRED, REPEATED
}

private final String name;
private final Type type;
private final String mode;
private final String description;

public static final class Builder {

private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,16 @@ public String toString() {
}

@Override
public int hashCode() {
public final int hashCode() {
return Objects.hash(attribute, value);
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof FieldValue)) {
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !obj.getClass().equals(FieldValue.class)) {
return false;
}
FieldValue other = (FieldValue) obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
return obj instanceof FormatOptions && Objects.equals(type, ((FormatOptions) obj).type());
return obj == this
|| obj != null
&& obj.getClass().equals(FormatOptions.class)
&& Objects.equals(type, ((FormatOptions) obj).type());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @see <a href="https://cloud.google.com/bigquery/streaming-data-into-bigquery">Streaming Data into
* BigQuery</a>
*/
public class InsertAllRequest implements Serializable {
public final class InsertAllRequest implements Serializable {

private static final long serialVersionUID = 211200307773853078L;

Expand Down Expand Up @@ -443,6 +443,9 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof InsertAllRequest)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ public boolean hasErrors() {
}

@Override
public int hashCode() {
public final int hashCode() {
return Objects.hash(insertErrors);
}

@Override
public boolean equals(Object obj) {
return obj instanceof InsertAllResponse
public final boolean equals(Object obj) {
return obj == this
|| obj != null
&& obj.getClass().equals(InsertAllResponse.class)
&& Objects.equals(insertErrors, ((InsertAllResponse) obj).insertErrors);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* {@link JobInfo}.
* </p>
*/
public final class Job extends JobInfo {
public class Job extends JobInfo {

private static final long serialVersionUID = -4324100991693024704L;

Expand Down Expand Up @@ -178,14 +178,20 @@ public Builder toBuilder() {
}

@Override
public boolean equals(Object obj) {
return obj instanceof Job
&& Objects.equals(toPb(), ((Job) obj).toPb())
&& Objects.equals(options, ((Job) obj).options);
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !obj.getClass().equals(Job.class)) {
return false;
}
Job other = (Job) obj;
return Objects.equals(toPb(), other.toPb())
&& Objects.equals(options, other.options);
}

@Override
public int hashCode() {
public final int hashCode() {
return Objects.hash(super.hashCode(), options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* Google BigQuery Job identity.
*/
public class JobId implements Serializable {
public final class JobId implements Serializable {

private static final long serialVersionUID = 1225914835379688976L;

Expand Down Expand Up @@ -68,7 +68,9 @@ public static JobId of(String job) {

@Override
public boolean equals(Object obj) {
return obj instanceof JobId && Objects.equals(toPb(), ((JobId) obj).toPb());
return obj == this
|| obj instanceof JobId
&& Objects.equals(toPb(), ((JobId) obj).toPb());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
return obj != null
return obj == this
|| obj != null
&& obj.getClass().equals(JobInfo.class)
&& Objects.equals(toPb(), ((JobInfo) obj).toPb());
}
Expand Down
Loading