Skip to content

Commit c4a79ef

Browse files
authored
fix: add some missing annotations and fix equals/hashcode for DatastoreOptions (#1106)
* chore(multi db): add some missing annotations and fix equals/hashcode on DatastoreOptions * add some tests
1 parent 7887f32 commit c4a79ef

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

datastore-v1-proto-client/src/main/java/com/google/datastore/v1/client/DatastoreOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public String getProjectId() {
188188
return projectId;
189189
}
190190

191+
@BetaApi
191192
public String getDatabaseId() {
192193
return databaseId;
193194
}

google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseKey.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public String getNamespace() {
148148
return namespace;
149149
}
150150

151+
@BetaApi
151152
public String getDatabaseId() {
152153
return databaseId;
153154
}

google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public String getNamespace() {
155155
return namespace;
156156
}
157157

158+
@BetaApi
158159
public String getDatabaseId() {
159160
return this.databaseId;
160161
}
@@ -193,7 +194,7 @@ public Builder toBuilder() {
193194

194195
@Override
195196
public int hashCode() {
196-
return Objects.hash(baseHashCode(), namespace);
197+
return Objects.hash(baseHashCode(), namespace, databaseId);
197198
}
198199

199200
@Override
@@ -202,7 +203,9 @@ public boolean equals(Object obj) {
202203
return false;
203204
}
204205
DatastoreOptions other = (DatastoreOptions) obj;
205-
return baseEquals(other) && Objects.equals(namespace, other.namespace);
206+
return baseEquals(other)
207+
&& Objects.equals(namespace, other.namespace)
208+
&& Objects.equals(databaseId, other.databaseId);
206209
}
207210

208211
public static Builder newBuilder() {

google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.datastore;
1818

1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotEquals;
2021
import static org.junit.Assert.assertNotNull;
2122
import static org.junit.Assert.assertSame;
2223
import static org.junit.Assert.assertTrue;
@@ -38,7 +39,6 @@ public class DatastoreOptionsTest {
3839
private DatastoreRpc datastoreRpc;
3940
private DatastoreOptions.Builder options;
4041

41-
// todo parameterize
4242
@Before
4343
public void setUp() {
4444
datastoreRpcFactory = EasyMock.createMock(DatastoreRpcFactory.class);
@@ -90,6 +90,12 @@ public void testToBuilder() {
9090
assertEquals(original.getHost(), copy.getHost());
9191
assertEquals(original.getRetrySettings(), copy.getRetrySettings());
9292
assertEquals(original.getCredentials(), copy.getCredentials());
93+
assertEquals(original, copy);
94+
assertEquals(original.hashCode(), copy.hashCode());
95+
96+
DatastoreOptions newOptions = options.setDatabaseId("new-database-id").build();
97+
assertNotEquals(original, newOptions);
98+
assertNotEquals(original.hashCode(), newOptions.hashCode());
9399
}
94100

95101
@Test

0 commit comments

Comments
 (0)