diff --git a/datastore-v1-proto-client/pom.xml b/datastore-v1-proto-client/pom.xml
index cadbbea61..3ce284c3f 100644
--- a/datastore-v1-proto-client/pom.xml
+++ b/datastore-v1-proto-client/pom.xml
@@ -91,8 +91,13 @@
- junit
- junit
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
test
diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/ChecksumEnforcingInputStreamTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/ChecksumEnforcingInputStreamTest.java
index dbe0e766a..68a27f06e 100644
--- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/ChecksumEnforcingInputStreamTest.java
+++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/ChecksumEnforcingInputStreamTest.java
@@ -16,33 +16,32 @@
package com.google.datastore.v1.client;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Test for {@link ChecksumEnforcingInputStream}. */
-@RunWith(JUnit4.class)
-public class ChecksumEnforcingInputStreamTest {
- public void test(int payloadSize) throws Exception {
+class ChecksumEnforcingInputStreamTest {
+ void test(int payloadSize) throws Exception {
// read 1000 bytes at a time
// Since checksum should be correct, do not expect IOException
- try (ChecksumEnforcingInputStream testInstance = setUpData(payloadSize)) {
- byte[] buf = new byte[1000];
- while (testInstance.read(buf, 0, 1000) != -1) {
- // do nothing with the bytes read
- }
- } catch (IOException e) {
- fail("checksum verification failed! " + e.getMessage());
- }
+ assertDoesNotThrow(
+ () -> {
+ try (ChecksumEnforcingInputStream testInstance = setUpData(payloadSize)) {
+ byte[] buf = new byte[1000];
+ while (testInstance.read(buf, 0, 1000) != -1) {
+ // do nothing with the bytes read
+ }
+ }
+ });
}
@Test
- public void read_withValidChecksum_differentPayloadSizes() throws Exception {
+ void read_withValidChecksum_differentPayloadSizes() throws Exception {
// test with various payload sizes (1, 2, 2**2, 2**3 etc upto 2**28 = 256MB)
for (int i = 0, payloadSize = 1; i < 29; i++) {
long start = System.currentTimeMillis();
@@ -57,26 +56,24 @@ public void read_withValidChecksum_differentPayloadSizes() throws Exception {
}
@Test
- public void read_withInvalidChecksum() {
- // build a test instance with invalidchecksum
- // read 1000 bytes at a time
- // Since checksum should be correct, do not expect IOException
- try (ChecksumEnforcingInputStream instance =
- new ChecksumEnforcingInputStream(
- new ByteArrayInputStream("hello there".getBytes(UTF_8)), "this checksum is invalid")) {
- byte[] buf = new byte[1000];
- while (instance.read(buf, 0, 1000) != -1) {
- // do nothing with the bytes read
- }
- } catch (IOException e) {
- // this is expected
- return;
- }
- fail("should have failed");
+ void read_withInvalidChecksum() {
+ assertThrows(
+ IOException.class,
+ () -> {
+ try (ChecksumEnforcingInputStream instance =
+ new ChecksumEnforcingInputStream(
+ new ByteArrayInputStream("hello there".getBytes(UTF_8)),
+ "this checksum is invalid")) {
+ byte[] buf = new byte[1000];
+ while (instance.read(buf, 0, 1000) != -1) {
+ // do nothing with the bytes read
+ }
+ }
+ });
}
@Test
- public void markNotSupported() throws Exception {
+ void markNotSupported() throws Exception {
try (ChecksumEnforcingInputStream testInstance = setUpData(1)) {
assertFalse(testInstance.markSupported());
}
diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java
index 16a6303bb..bfb45c633 100644
--- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java
+++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java
@@ -16,11 +16,10 @@
package com.google.datastore.v1.client;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
@@ -51,13 +50,10 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.SocketTimeoutException;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Tests for {@link DatastoreFactory} and {@link Datastore}. */
-@RunWith(JUnit4.class)
-public class DatastoreClientTest {
+class DatastoreClientTest {
private static final String PROJECT_ID = "project-id";
private DatastoreFactory factory = new MockDatastoreFactory();
@@ -65,7 +61,7 @@ public class DatastoreClientTest {
new DatastoreOptions.Builder().projectId(PROJECT_ID).credential(new MockCredential());
@Test
- public void options_NoProjectIdOrProjectEndpoint() {
+ void options_NoProjectIdOrProjectEndpoint() {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -77,7 +73,7 @@ public void options_NoProjectIdOrProjectEndpoint() {
}
@Test
- public void options_ProjectIdAndProjectEndpoint() throws Exception {
+ void options_ProjectIdAndProjectEndpoint() throws Exception {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -92,7 +88,7 @@ public void options_ProjectIdAndProjectEndpoint() throws Exception {
}
@Test
- public void options_LocalHostAndProjectEndpoint() throws Exception {
+ void options_LocalHostAndProjectEndpoint() throws Exception {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -107,7 +103,7 @@ public void options_LocalHostAndProjectEndpoint() throws Exception {
}
@Test
- public void options_HostAndProjectEndpoint() throws Exception {
+ void options_HostAndProjectEndpoint() throws Exception {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -122,7 +118,7 @@ public void options_HostAndProjectEndpoint() throws Exception {
}
@Test
- public void options_HostAndLocalHost() throws Exception {
+ void options_HostAndLocalHost() throws Exception {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -136,7 +132,7 @@ public void options_HostAndLocalHost() throws Exception {
}
@Test
- public void options_InvalidLocalHost() throws Exception {
+ void options_InvalidLocalHost() throws Exception {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -150,7 +146,7 @@ public void options_InvalidLocalHost() throws Exception {
}
@Test
- public void options_SchemeInLocalHost() {
+ void options_SchemeInLocalHost() {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -161,7 +157,7 @@ public void options_SchemeInLocalHost() {
}
@Test
- public void options_InvalidHost() {
+ void options_InvalidHost() {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -175,7 +171,7 @@ public void options_InvalidHost() {
}
@Test
- public void options_SchemeInHost() {
+ void options_SchemeInHost() {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -187,12 +183,12 @@ public void options_SchemeInHost() {
}
@Test
- public void create_NullOptions() throws Exception {
+ void create_NullOptions() throws Exception {
assertThrows(NullPointerException.class, () -> factory.create(null));
}
@Test
- public void create_Host() {
+ void create_Host() {
Datastore datastore =
factory.create(
new DatastoreOptions.Builder()
@@ -204,7 +200,7 @@ public void create_Host() {
}
@Test
- public void create_LocalHost() {
+ void create_LocalHost() {
Datastore datastore =
factory.create(
new DatastoreOptions.Builder()
@@ -216,7 +212,7 @@ public void create_LocalHost() {
}
@Test
- public void create_LocalHostIp() {
+ void create_LocalHostIp() {
Datastore datastore =
factory.create(
new DatastoreOptions.Builder()
@@ -228,7 +224,7 @@ public void create_LocalHostIp() {
}
@Test
- public void create_DefaultHost() {
+ void create_DefaultHost() {
Datastore datastore =
factory.create(new DatastoreOptions.Builder().projectId(PROJECT_ID).build());
assertThat(datastore.remoteRpc.getUrl())
@@ -236,7 +232,7 @@ public void create_DefaultHost() {
}
@Test
- public void create_ProjectEndpoint() {
+ void create_ProjectEndpoint() {
Datastore datastore =
factory.create(
new DatastoreOptions.Builder()
@@ -247,7 +243,7 @@ public void create_ProjectEndpoint() {
}
@Test
- public void create_ProjectEndpointNoScheme() {
+ void create_ProjectEndpointNoScheme() {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -264,7 +260,7 @@ public void create_ProjectEndpointNoScheme() {
}
@Test
- public void initializer() throws Exception {
+ void initializer() throws Exception {
options.initializer(
new HttpRequestInitializer() {
@Override
@@ -282,21 +278,21 @@ public void initialize(HttpRequest request) {
}
@Test
- public void allocateIds() throws Exception {
+ void allocateIds() throws Exception {
AllocateIdsRequest.Builder request = AllocateIdsRequest.newBuilder();
AllocateIdsResponse.Builder response = AllocateIdsResponse.newBuilder();
expectRpc("allocateIds", request.build(), response.build());
}
@Test
- public void lookup() throws Exception {
+ void lookup() throws Exception {
LookupRequest.Builder request = LookupRequest.newBuilder();
LookupResponse.Builder response = LookupResponse.newBuilder();
expectRpc("lookup", request.build(), response.build());
}
@Test
- public void beginTransaction() throws Exception {
+ void beginTransaction() throws Exception {
BeginTransactionRequest.Builder request = BeginTransactionRequest.newBuilder();
BeginTransactionResponse.Builder response = BeginTransactionResponse.newBuilder();
response.setTransaction(ByteString.copyFromUtf8("project-id"));
@@ -304,7 +300,7 @@ public void beginTransaction() throws Exception {
}
@Test
- public void commit() throws Exception {
+ void commit() throws Exception {
CommitRequest.Builder request = CommitRequest.newBuilder();
request.setTransaction(ByteString.copyFromUtf8("project-id"));
CommitResponse.Builder response = CommitResponse.newBuilder();
@@ -312,14 +308,14 @@ public void commit() throws Exception {
}
@Test
- public void reserveIds() throws Exception {
+ void reserveIds() throws Exception {
ReserveIdsRequest.Builder request = ReserveIdsRequest.newBuilder();
ReserveIdsResponse.Builder response = ReserveIdsResponse.newBuilder();
expectRpc("reserveIds", request.build(), response.build());
}
@Test
- public void rollback() throws Exception {
+ void rollback() throws Exception {
RollbackRequest.Builder request = RollbackRequest.newBuilder();
request.setTransaction(ByteString.copyFromUtf8("project-id"));
RollbackResponse.Builder response = RollbackResponse.newBuilder();
@@ -327,7 +323,7 @@ public void rollback() throws Exception {
}
@Test
- public void runQuery() throws Exception {
+ void runQuery() throws Exception {
RunQueryRequest.Builder request = RunQueryRequest.newBuilder();
request.getQueryBuilder();
RunQueryResponse.Builder response = RunQueryResponse.newBuilder();
@@ -339,7 +335,7 @@ public void runQuery() throws Exception {
}
@Test
- public void runAggregationQuery() throws Exception {
+ void runAggregationQuery() throws Exception {
RunAggregationQueryRequest.Builder request = RunAggregationQueryRequest.newBuilder();
RunAggregationQueryResponse.Builder response = RunAggregationQueryResponse.newBuilder();
expectRpc("runAggregationQuery", request.build(), response.build());
@@ -366,41 +362,46 @@ private void expectRpc(String methodName, Message request, Message response) thr
assertEquals(0, datastore.getRpcCount());
mockClient.setNextError(400, Code.INVALID_ARGUMENT, "oops");
- try {
- call.invoke(datastore, callArgs);
- fail();
- } catch (InvocationTargetException targetException) {
- DatastoreException exception = (DatastoreException) targetException.getCause();
- assertEquals(Code.INVALID_ARGUMENT, exception.getCode());
- assertEquals(methodName, exception.getMethodName());
- assertEquals("oops", exception.getMessage());
- }
+ InvocationTargetException ex1 =
+ assertThrows(InvocationTargetException.class, () -> call.invoke(datastore, callArgs));
+ DatastoreException exception = (DatastoreException) ex1.getCause();
+ assertEquals(Code.INVALID_ARGUMENT, exception.getCode());
+ assertEquals(methodName, exception.getMethodName());
+ assertEquals("oops", exception.getMessage());
SocketTimeoutException socketTimeoutException = new SocketTimeoutException("ste");
mockClient.setNextException(socketTimeoutException);
- try {
- call.invoke(datastore, callArgs);
- fail();
- } catch (InvocationTargetException targetException) {
- DatastoreException exception = (DatastoreException) targetException.getCause();
- assertEquals(Code.DEADLINE_EXCEEDED, exception.getCode());
- assertEquals(methodName, exception.getMethodName());
- assertEquals("Deadline exceeded", exception.getMessage());
- assertSame(socketTimeoutException, exception.getCause());
- }
+ DatastoreException exception1 =
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ try {
+ call.invoke(datastore, callArgs);
+ } catch (InvocationTargetException e) {
+ throw (Exception) e.getCause();
+ }
+ });
+ assertEquals(Code.DEADLINE_EXCEEDED, exception1.getCode());
+ assertEquals(methodName, exception1.getMethodName());
+ assertEquals("Deadline exceeded", exception1.getMessage());
+ assertSame(socketTimeoutException, exception1.getCause());
IOException ioException = new IOException("ioe");
mockClient.setNextException(ioException);
- try {
- call.invoke(datastore, callArgs);
- fail();
- } catch (InvocationTargetException targetException) {
- DatastoreException exception = (DatastoreException) targetException.getCause();
- assertEquals(Code.UNAVAILABLE, exception.getCode());
- assertEquals(methodName, exception.getMethodName());
- assertEquals("I/O error", exception.getMessage());
- assertSame(ioException, exception.getCause());
- }
+ DatastoreException exception2 =
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ try {
+ call.invoke(datastore, callArgs);
+ } catch (InvocationTargetException e) {
+ throw (Exception) e.getCause();
+ }
+ });
+ assertEquals(Code.UNAVAILABLE, exception2.getCode());
+ assertEquals(methodName, exception2.getMethodName());
+ assertEquals("I/O error", exception2.getMessage());
+ assertSame(ioException, exception2.getCause());
assertEquals(3, datastore.getRpcCount());
}
diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreEmulatorTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreEmulatorTest.java
index f195e61c4..60f52a07a 100644
--- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreEmulatorTest.java
+++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreEmulatorTest.java
@@ -15,22 +15,19 @@
*/
package com.google.datastore.v1.client;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Tests for {@link DatastoreEmulator}. */
-@RunWith(JUnit4.class)
-public class DatastoreEmulatorTest {
+class DatastoreEmulatorTest {
private static final DatastoreEmulatorOptions options =
new DatastoreEmulatorOptions.Builder().build();
@Test
- public void testArgs() throws DatastoreEmulatorException {
+ void testArgs() throws DatastoreEmulatorException {
DatastoreEmulator datastore =
new DatastoreEmulator(null, "blar", options) {
@Override
@@ -40,25 +37,15 @@ void startEmulatorInternal(
}
};
- try {
- datastore.start(null, "projectId");
- fail("expected exception");
- } catch (NullPointerException npe) {
- // good
- }
+ assertThrows(NullPointerException.class, () -> datastore.start(null, "projectId"));
- try {
- datastore.start("path/to/emulator", null);
- fail("expected exception");
- } catch (NullPointerException npe) {
- // good
- }
+ assertThrows(NullPointerException.class, () -> datastore.start("path/to/emulator", null));
datastore.start("path/to/emulator", "projectId");
}
@Test
- public void testLifecycle() throws DatastoreEmulatorException {
+ void testLifecycle() throws DatastoreEmulatorException {
DatastoreEmulator datastore =
new DatastoreEmulator(null, "blar", options) {
@Override
@@ -77,23 +64,13 @@ protected void stopEmulatorInternal() {
String myProject = "myproject";
datastore.start(emulatorDir, myProject);
- try {
- datastore.start(emulatorDir, myProject);
- fail("expected exception");
- } catch (IllegalStateException e) {
- // good
- }
+ assertThrows(IllegalStateException.class, () -> datastore.start(emulatorDir, myProject));
datastore.stop();
// It's ok to stop if we've already stopped.
datastore.stop();
// Once we've stopped we can't start again.
- try {
- datastore.start(emulatorDir, myProject);
- fail("expected exception");
- } catch (IllegalStateException e) {
- // good
- }
+ assertThrows(IllegalStateException.class, () -> datastore.start(emulatorDir, myProject));
}
}
diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreFactoryTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreFactoryTest.java
index 02bb44a52..679e97eeb 100644
--- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreFactoryTest.java
+++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreFactoryTest.java
@@ -15,21 +15,18 @@
*/
package com.google.datastore.v1.client;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.javanet.NetHttpTransport;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Test for {@link DatastoreFactory}. */
-@RunWith(JUnit4.class)
-public class DatastoreFactoryTest {
+class DatastoreFactoryTest {
private static final String PROJECT_ID = "project-id";
private DatastoreFactory factory = DatastoreFactory.get();
@@ -39,7 +36,7 @@ public class DatastoreFactoryTest {
* its own.
*/
@Test
- public void makeClient_Default() {
+ void makeClient_Default() {
DatastoreOptions options = new DatastoreOptions.Builder().projectId(PROJECT_ID).build();
HttpRequestFactory f = factory.makeClient(options);
assertNotNull(f.getTransport());
@@ -51,7 +48,7 @@ public void makeClient_Default() {
* credential.
*/
@Test
- public void makeClient_WithCredential() {
+ void makeClient_WithCredential() {
NetHttpTransport transport = new NetHttpTransport();
GoogleCredential credential = new GoogleCredential.Builder().setTransport(transport).build();
DatastoreOptions options =
@@ -62,7 +59,7 @@ public void makeClient_WithCredential() {
/** Specifying a transport, but not a credential, the factory will use the transport specified. */
@Test
- public void makeClient_WithTransport() {
+ void makeClient_WithTransport() {
NetHttpTransport transport = new NetHttpTransport();
DatastoreOptions options =
new DatastoreOptions.Builder().projectId(PROJECT_ID).transport(transport).build();
@@ -75,7 +72,7 @@ public void makeClient_WithTransport() {
* the one in the credential.
*/
@Test
- public void makeClient_WithCredentialTransport() {
+ void makeClient_WithCredentialTransport() {
NetHttpTransport credTransport = new NetHttpTransport();
NetHttpTransport transport = new NetHttpTransport();
GoogleCredential credential =
diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreHelperTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreHelperTest.java
index 20325a4f0..2f5a9838f 100644
--- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreHelperTest.java
+++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreHelperTest.java
@@ -19,8 +19,9 @@
import static com.google.datastore.v1.client.DatastoreHelper.makeKey;
import static com.google.datastore.v1.client.DatastoreHelper.makeValue;
import static com.google.datastore.v1.client.DatastoreHelper.toDate;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
import com.google.datastore.v1.Key;
import com.google.datastore.v1.PartitionId;
@@ -29,13 +30,10 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.Timestamp;
import java.util.Date;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Tests for {@link DatastoreHelper}. */
-@RunWith(JUnit4.class)
-public class DatastoreHelperTest {
+class DatastoreHelperTest {
private static final Key PARENT =
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Parent").setId(23L)).build();
@@ -47,65 +45,58 @@ public class DatastoreHelperTest {
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Child").setId(26L)).build();
@Test
- public void testMakeKey_BadTypeForKind() {
- try {
- DatastoreHelper.makeKey(new Object());
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ void testMakeKey_BadTypeForKind() {
+ assertThrows(IllegalArgumentException.class, () -> DatastoreHelper.makeKey(new Object()));
}
@Test
- public void testMakeKey_BadTypeForNameId() {
- try {
- DatastoreHelper.makeKey("kind", new Object());
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ void testMakeKey_BadTypeForNameId() {
+ assertThrows(
+ IllegalArgumentException.class, () -> DatastoreHelper.makeKey("kind", new Object()));
}
@Test
- public void testMakeKey_Empty() {
+ void testMakeKey_Empty() {
assertEquals(Key.newBuilder().build(), DatastoreHelper.makeKey().build());
}
@Test
- public void testMakeKey_Incomplete() {
+ void testMakeKey_Incomplete() {
assertEquals(
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Foo")).build(),
makeKey("Foo").build());
}
@Test
- public void testMakeKey_IdInt() {
+ void testMakeKey_IdInt() {
assertEquals(
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Foo").setId(1)).build(),
makeKey("Foo", 1).build());
}
@Test
- public void testMakeKey_IdLong() {
+ void testMakeKey_IdLong() {
assertEquals(
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Foo").setId(1)).build(),
makeKey("Foo", 1L).build());
}
@Test
- public void testMakeKey_IdShort() {
+ void testMakeKey_IdShort() {
assertEquals(
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Foo").setId(1)).build(),
makeKey("Foo", (short) 1).build());
}
@Test
- public void testMakeKey_Name() {
+ void testMakeKey_Name() {
assertEquals(
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Foo").setName("hi")).build(),
makeKey("Foo", "hi").build());
}
@Test
- public void testMakeKey_KindNameKind() {
+ void testMakeKey_KindNameKind() {
assertEquals(
Key.newBuilder()
.addPath(Key.PathElement.newBuilder().setKind("Foo").setName("hi"))
@@ -115,7 +106,7 @@ public void testMakeKey_KindNameKind() {
}
@Test
- public void testMakeKey_KeyKind() {
+ void testMakeKey_KeyKind() {
// 1 key at the beginning of the series
assertEquals(
Key.newBuilder()
@@ -126,7 +117,7 @@ public void testMakeKey_KeyKind() {
}
@Test
- public void testMakeKey_KindIdKeyKind() {
+ void testMakeKey_KindIdKeyKind() {
// 1 key in the middle of the series
assertEquals(
Key.newBuilder()
@@ -138,7 +129,7 @@ public void testMakeKey_KindIdKeyKind() {
}
@Test
- public void testMakeKey_KindIdKey() {
+ void testMakeKey_KindIdKey() {
// 1 key at the end of the series
assertEquals(
Key.newBuilder()
@@ -149,7 +140,7 @@ public void testMakeKey_KindIdKey() {
}
@Test
- public void testMakeKey_KeyKindIdKey() {
+ void testMakeKey_KeyKindIdKey() {
// 1 key at the beginning and 1 key at the end of the series
assertEquals(
Key.newBuilder()
@@ -161,13 +152,13 @@ public void testMakeKey_KeyKindIdKey() {
}
@Test
- public void testMakeKey_Key() {
+ void testMakeKey_Key() {
// Just 1 key
assertEquals(Key.newBuilder().addPath(CHILD.getPath(0)).build(), makeKey(CHILD).build());
}
@Test
- public void testMakeKey_KeyKey() {
+ void testMakeKey_KeyKey() {
// Just 2 keys
assertEquals(
Key.newBuilder().addPath(PARENT.getPath(0)).addPath(CHILD.getPath(0)).build(),
@@ -175,7 +166,7 @@ public void testMakeKey_KeyKey() {
}
@Test
- public void testMakeKey_KeyKeyKey() {
+ void testMakeKey_KeyKeyKey() {
// Just 3 keys
assertEquals(
Key.newBuilder()
@@ -187,7 +178,7 @@ public void testMakeKey_KeyKeyKey() {
}
@Test
- public void testMakeKey_KeyMultiLevelKey() {
+ void testMakeKey_KeyMultiLevelKey() {
// 1 key with 2 elements
assertEquals(
Key.newBuilder()
@@ -199,7 +190,7 @@ public void testMakeKey_KeyMultiLevelKey() {
}
@Test
- public void testMakeKey_MultiLevelKeyKey() {
+ void testMakeKey_MultiLevelKeyKey() {
// 1 key with 2 elements
assertEquals(
Key.newBuilder()
@@ -211,7 +202,7 @@ public void testMakeKey_MultiLevelKeyKey() {
}
@Test
- public void testMakeKey_MultiLevelKey() {
+ void testMakeKey_MultiLevelKey() {
// 1 key with 3 elements
assertEquals(
Key.newBuilder()
@@ -223,7 +214,7 @@ public void testMakeKey_MultiLevelKey() {
}
@Test
- public void testMakeKey_PartitionId() {
+ void testMakeKey_PartitionId() {
PartitionId partitionId = PartitionId.newBuilder().setNamespaceId("namespace-id").build();
Key parent = PARENT.toBuilder().setPartitionId(partitionId).build();
assertEquals(
@@ -236,7 +227,7 @@ public void testMakeKey_PartitionId() {
}
@Test
- public void testMakeKey_NonMatchingPartitionId2() {
+ void testMakeKey_NonMatchingPartitionId2() {
PartitionId partitionId1 = PartitionId.newBuilder().setNamespaceId("namespace-id").build();
PartitionId partitionId2 =
PartitionId.newBuilder().setNamespaceId("another-namespace-id").build();
@@ -250,7 +241,7 @@ public void testMakeKey_NonMatchingPartitionId2() {
}
@Test
- public void testMakeTimestampValue() throws Exception {
+ void testMakeTimestampValue() throws Exception {
// Test cases with nanos == 0.
assertConversion(-50_000, -50, 0);
assertConversion(-1_000, -1, 0);
@@ -301,20 +292,12 @@ private void assertTimestampToMilliseconds(long millis, long seconds, int nanos)
}
@Test
- public void testProjectionHandling() {
+ void testProjectionHandling() {
assertEquals(
ByteString.copyFromUtf8("hi"), getByteString(makeValue("hi").setMeaning(18).build()));
- try {
- getByteString(makeValue("hi").build());
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> getByteString(makeValue("hi").build()));
assertEquals(new Date(1), toDate(makeValue(1000).setMeaning(18).build()));
- try {
- toDate(makeValue(1000).build());
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> toDate(makeValue(1000).build()));
}
}
diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/EndToEndChecksumHandlerTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/EndToEndChecksumHandlerTest.java
index 1fdc1906a..fa308cec1 100644
--- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/EndToEndChecksumHandlerTest.java
+++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/EndToEndChecksumHandlerTest.java
@@ -16,68 +16,65 @@
package com.google.datastore.v1.client;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Test for {@link EndToEndChecksumHandler}. */
-@RunWith(JUnit4.class)
-public class EndToEndChecksumHandlerTest {
+class EndToEndChecksumHandlerTest {
private final byte[] payloadBytes =
"This is a long string with numbers 1234, 134.56 ".getBytes(UTF_8);
private final byte[] payloadForUnsignedLongChecksum = "aaa".getBytes(UTF_8);
private final String unsignedLongChecksum = "3818383321";
@Test
- public void validateChecksum_correctChecksum() {
+ void validateChecksum_correctChecksum() {
String computed = EndToEndChecksumHandler.computeChecksum(payloadBytes);
assertTrue(EndToEndChecksumHandler.validateChecksum(computed, payloadBytes));
}
@Test
- public void computeChecksum_returnsUnsignedLongAsStringValue() {
+ void computeChecksum_returnsUnsignedLongAsStringValue() {
String computed = EndToEndChecksumHandler.computeChecksum(payloadForUnsignedLongChecksum);
- assertEquals("computeChecksum return value", unsignedLongChecksum, computed);
+ assertEquals(unsignedLongChecksum, computed, "computeChecksum return value");
}
@Test
- public void validateChecksum_incorrectChecksum() {
+ void validateChecksum_incorrectChecksum() {
String computed = EndToEndChecksumHandler.computeChecksum("random string".getBytes(UTF_8));
assertFalse(EndToEndChecksumHandler.validateChecksum(computed, payloadBytes));
}
@Test
- public void validateChecksum_nullChecksum() {
+ void validateChecksum_nullChecksum() {
assertFalse(EndToEndChecksumHandler.validateChecksum(null, payloadBytes));
}
@Test
- public void validateChecksum_emptyChecksum() {
+ void validateChecksum_emptyChecksum() {
assertFalse(EndToEndChecksumHandler.validateChecksum("", payloadBytes));
}
@Test
- public void validateChecksum_nullPayload() {
+ void validateChecksum_nullPayload() {
assertFalse(EndToEndChecksumHandler.validateChecksum("foo", null));
}
@Test
- public void validateChecksum_emptyPayload() {
+ void validateChecksum_emptyPayload() {
assertFalse(EndToEndChecksumHandler.validateChecksum("foo", new byte[0]));
}
@Test
- public void computeChecksum_nullInputBytes() {
+ void computeChecksum_nullInputBytes() {
assertNull(EndToEndChecksumHandler.computeChecksum(null));
}
@Test
- public void computeChecksum_emptyArrayForInputBytes() {
+ void computeChecksum_emptyArrayForInputBytes() {
assertNull(EndToEndChecksumHandler.computeChecksum(new byte[0]));
}
}
diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/QuerySplitterTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/QuerySplitterTest.java
index 0802a62aa..31aa5326c 100644
--- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/QuerySplitterTest.java
+++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/QuerySplitterTest.java
@@ -22,8 +22,8 @@
import static com.google.datastore.v1.client.DatastoreHelper.makeOrder;
import static com.google.datastore.v1.client.DatastoreHelper.makePropertyReference;
import static com.google.datastore.v1.client.DatastoreHelper.makeValue;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.datastore.v1.Entity;
import com.google.datastore.v1.EntityResult;
@@ -46,13 +46,10 @@
import com.google.protobuf.Int32Value;
import com.google.protobuf.Timestamp;
import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Tests for {@link QuerySplitterImpl}. */
-@RunWith(JUnit4.class)
-public class QuerySplitterTest {
+class QuerySplitterTest {
private static final String PROJECT_ID = "project-id";
private static final PartitionId PARTITION =
PartitionId.newBuilder().setProjectId(PROJECT_ID).build();
@@ -86,7 +83,7 @@ public class QuerySplitterTest {
makeKey(KIND, String.format("%05d", 301)).setPartitionId(PARTITION).build();
@Test
- public void disallowsSortOrder() {
+ void disallowsSortOrder() {
Datastore datastore = factory.create(options.build());
Query queryWithOrder =
query.toBuilder().addOrder(makeOrder("bar", Direction.ASCENDING)).build();
@@ -98,7 +95,7 @@ public void disallowsSortOrder() {
}
@Test
- public void disallowsMultipleKinds() {
+ void disallowsMultipleKinds() {
Datastore datastore = factory.create(options.build());
Query queryWithMultipleKinds =
query.toBuilder()
@@ -114,7 +111,7 @@ public void disallowsMultipleKinds() {
}
@Test
- public void disallowsKindlessQuery() {
+ void disallowsKindlessQuery() {
Datastore datastore = factory.create(options.build());
Query kindlessQuery = query.toBuilder().clearKind().build();
IllegalArgumentException exception =
@@ -125,7 +122,7 @@ public void disallowsKindlessQuery() {
}
@Test
- public void disallowsInequalityFilter() {
+ void disallowsInequalityFilter() {
Datastore datastore = factory.create(options.build());
Query queryWithInequality =
query.toBuilder()
@@ -140,7 +137,7 @@ public void disallowsInequalityFilter() {
}
@Test
- public void splitsMustBePositive() {
+ void splitsMustBePositive() {
Datastore datastore = factory.create(options.build());
IllegalArgumentException exception =
assertThrows(
@@ -150,7 +147,7 @@ public void splitsMustBePositive() {
}
@Test
- public void getSplits() throws Exception {
+ void getSplits() throws Exception {
Datastore datastore = factory.create(options.build());
MockDatastoreFactory mockClient = (MockDatastoreFactory) factory;
@@ -197,7 +194,7 @@ public void getSplits() throws Exception {
}
@Test
- public void getSplitsWithDatabaseId() throws Exception {
+ void getSplitsWithDatabaseId() throws Exception {
Datastore datastore = factory.create(options.build());
MockDatastoreFactory mockClient = (MockDatastoreFactory) factory;
@@ -247,7 +244,7 @@ public void getSplitsWithDatabaseId() throws Exception {
}
@Test
- public void notEnoughSplits() throws Exception {
+ void notEnoughSplits() throws Exception {
Datastore datastore = factory.create(options.build());
MockDatastoreFactory mockClient = (MockDatastoreFactory) factory;
@@ -288,7 +285,7 @@ public void notEnoughSplits() throws Exception {
}
@Test
- public void getSplits_withReadTime() throws Exception {
+ void getSplits_withReadTime() throws Exception {
Datastore datastore = factory.create(options.build());
MockDatastoreFactory mockClient = (MockDatastoreFactory) factory;
diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/RemoteRpcTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/RemoteRpcTest.java
index 28e3f20b8..9ff665ed5 100644
--- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/RemoteRpcTest.java
+++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/RemoteRpcTest.java
@@ -15,9 +15,9 @@
*/
package com.google.datastore.v1.client;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpTransport;
@@ -36,18 +36,15 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPOutputStream;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Test for {@link RemoteRpc}. */
-@RunWith(JUnit4.class)
-public class RemoteRpcTest {
+class RemoteRpcTest {
private static final String METHOD_NAME = "methodName";
@Test
- public void testException() {
+ void testException() {
Status statusProto =
Status.newBuilder()
.setCode(Code.UNAUTHENTICATED_VALUE)
@@ -69,7 +66,7 @@ public void testException() {
}
@Test
- public void testInvalidProtoException() {
+ void testInvalidProtoException() {
DatastoreException exception =
RemoteRpc.makeException(
"url",
@@ -87,7 +84,7 @@ public void testInvalidProtoException() {
}
@Test
- public void testEmptyProtoException() {
+ void testEmptyProtoException() {
Status statusProto = Status.newBuilder().build();
DatastoreException exception =
RemoteRpc.makeException(
@@ -106,7 +103,7 @@ public void testEmptyProtoException() {
}
@Test
- public void testEmptyProtoExceptionUnauthenticated() {
+ void testEmptyProtoExceptionUnauthenticated() {
Status statusProto = Status.newBuilder().build();
DatastoreException exception =
RemoteRpc.makeException(
@@ -123,7 +120,7 @@ public void testEmptyProtoExceptionUnauthenticated() {
}
@Test
- public void testPlainTextException() {
+ void testPlainTextException() {
DatastoreException exception =
RemoteRpc.makeException(
"url",
@@ -140,7 +137,7 @@ public void testPlainTextException() {
}
@Test
- public void testGzip() throws IOException, DatastoreException {
+ void testGzip() throws IOException, DatastoreException {
BeginTransactionResponse response = newBeginTransactionResponse();
InjectedTestValues injectedTestValues =
new InjectedTestValues(gzip(response), new byte[1], true);
@@ -157,7 +154,7 @@ public void testGzip() throws IOException, DatastoreException {
}
@Test
- public void testHttpHeaders_expectE2eChecksumHeader() throws IOException {
+ void testHttpHeaders_expectE2eChecksumHeader() throws IOException {
// Enable E2E-Checksum system env variable
RemoteRpc.setSystemEnvE2EChecksum(true);
String projectId = "project-id";
@@ -180,7 +177,7 @@ public void testHttpHeaders_expectE2eChecksumHeader() throws IOException {
}
@Test
- public void testHttpHeaders_doNotExpectE2eChecksumHeader() throws IOException {
+ void testHttpHeaders_doNotExpectE2eChecksumHeader() throws IOException {
// disable E2E-Checksum system env variable
RemoteRpc.setSystemEnvE2EChecksum(false);
String projectId = "project-id";
@@ -202,7 +199,7 @@ public void testHttpHeaders_doNotExpectE2eChecksumHeader() throws IOException {
}
@Test
- public void testHttpHeaders_prefixHeader() throws IOException {
+ void testHttpHeaders_prefixHeader() throws IOException {
String projectId = "my-project";
String databaseId = "my-db";
MessageLite request =
diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/it/ITDatastoreProtoClientTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/it/ITDatastoreProtoClientTest.java
index 3e6cf025e..089e864f2 100644
--- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/it/ITDatastoreProtoClientTest.java
+++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/it/ITDatastoreProtoClientTest.java
@@ -30,10 +30,10 @@
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class ITDatastoreProtoClientTest {
+class ITDatastoreProtoClientTest {
private static Datastore DATASTORE;
@@ -42,13 +42,13 @@ public class ITDatastoreProtoClientTest {
private static final String KIND = "test-kind";
private static final String PROJECT_ID = System.getenv(DatastoreHelper.PROJECT_ID_ENV_VAR);
- @Before
- public void setUp() throws GeneralSecurityException, IOException {
+ @BeforeEach
+ void setUp() throws GeneralSecurityException, IOException {
DATASTORE = DatastoreHelper.getDatastoreFromEnv();
}
@Test
- public void testQuerySplitterWithDefaultDb() throws DatastoreException {
+ void testQuerySplitterWithDefaultDb() throws DatastoreException {
Filter propertyFilter =
makeFilter("foo", PropertyFilter.Operator.EQUAL, makeValue("value")).build();
Query query =
@@ -70,7 +70,7 @@ public void testQuerySplitterWithDefaultDb() throws DatastoreException {
}
@Test
- public void testQuerySplitterWithDb() throws DatastoreException {
+ void testQuerySplitterWithDb() throws DatastoreException {
Filter propertyFilter =
makeFilter("foo", PropertyFilter.Operator.EQUAL, makeValue("value")).build();
Query query =
diff --git a/google-cloud-datastore-utils/pom.xml b/google-cloud-datastore-utils/pom.xml
index 74f717c84..575830aab 100644
--- a/google-cloud-datastore-utils/pom.xml
+++ b/google-cloud-datastore-utils/pom.xml
@@ -69,8 +69,13 @@
- junit
- junit
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
test
diff --git a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreClientTest.java b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreClientTest.java
index 31b0f6440..0a916743e 100644
--- a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreClientTest.java
+++ b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreClientTest.java
@@ -16,11 +16,10 @@
package com.google.datastore.utils;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
@@ -51,13 +50,10 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.SocketTimeoutException;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Tests for {@link DatastoreFactory} and {@link Datastore}. */
-@RunWith(JUnit4.class)
-public class DatastoreClientTest {
+class DatastoreClientTest {
private static final String PROJECT_ID = "project-id";
private DatastoreFactory factory = new MockDatastoreFactory();
@@ -65,7 +61,7 @@ public class DatastoreClientTest {
new DatastoreOptions.Builder().projectId(PROJECT_ID).credential(new MockCredential());
@Test
- public void options_NoProjectIdOrProjectEndpoint() {
+ void options_NoProjectIdOrProjectEndpoint() {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -77,7 +73,7 @@ public void options_NoProjectIdOrProjectEndpoint() {
}
@Test
- public void options_ProjectIdAndProjectEndpoint() throws Exception {
+ void options_ProjectIdAndProjectEndpoint() throws Exception {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -92,7 +88,7 @@ public void options_ProjectIdAndProjectEndpoint() throws Exception {
}
@Test
- public void options_LocalHostAndProjectEndpoint() throws Exception {
+ void options_LocalHostAndProjectEndpoint() throws Exception {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -107,7 +103,7 @@ public void options_LocalHostAndProjectEndpoint() throws Exception {
}
@Test
- public void options_HostAndProjectEndpoint() throws Exception {
+ void options_HostAndProjectEndpoint() throws Exception {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -122,7 +118,7 @@ public void options_HostAndProjectEndpoint() throws Exception {
}
@Test
- public void options_HostAndLocalHost() throws Exception {
+ void options_HostAndLocalHost() throws Exception {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -136,7 +132,7 @@ public void options_HostAndLocalHost() throws Exception {
}
@Test
- public void options_InvalidLocalHost() throws Exception {
+ void options_InvalidLocalHost() throws Exception {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -150,7 +146,7 @@ public void options_InvalidLocalHost() throws Exception {
}
@Test
- public void options_SchemeInLocalHost() {
+ void options_SchemeInLocalHost() {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -161,7 +157,7 @@ public void options_SchemeInLocalHost() {
}
@Test
- public void options_InvalidHost() {
+ void options_InvalidHost() {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -175,7 +171,7 @@ public void options_InvalidHost() {
}
@Test
- public void options_SchemeInHost() {
+ void options_SchemeInHost() {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -187,12 +183,12 @@ public void options_SchemeInHost() {
}
@Test
- public void create_NullOptions() throws Exception {
+ void create_NullOptions() throws Exception {
assertThrows(NullPointerException.class, () -> factory.create(null));
}
@Test
- public void create_Host() {
+ void create_Host() {
Datastore datastore =
factory.create(
new DatastoreOptions.Builder()
@@ -204,7 +200,7 @@ public void create_Host() {
}
@Test
- public void create_LocalHost() {
+ void create_LocalHost() {
Datastore datastore =
factory.create(
new DatastoreOptions.Builder()
@@ -216,7 +212,7 @@ public void create_LocalHost() {
}
@Test
- public void create_LocalHostIp() {
+ void create_LocalHostIp() {
Datastore datastore =
factory.create(
new DatastoreOptions.Builder()
@@ -228,7 +224,7 @@ public void create_LocalHostIp() {
}
@Test
- public void create_DefaultHost() {
+ void create_DefaultHost() {
Datastore datastore =
factory.create(new DatastoreOptions.Builder().projectId(PROJECT_ID).build());
assertThat(datastore.remoteRpc.getUrl())
@@ -236,7 +232,7 @@ public void create_DefaultHost() {
}
@Test
- public void create_ProjectEndpoint() {
+ void create_ProjectEndpoint() {
Datastore datastore =
factory.create(
new DatastoreOptions.Builder()
@@ -247,7 +243,7 @@ public void create_ProjectEndpoint() {
}
@Test
- public void create_ProjectEndpointNoScheme() {
+ void create_ProjectEndpointNoScheme() {
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
@@ -264,7 +260,7 @@ public void create_ProjectEndpointNoScheme() {
}
@Test
- public void initializer() throws Exception {
+ void initializer() throws Exception {
options.initializer(
new HttpRequestInitializer() {
@Override
@@ -282,21 +278,21 @@ public void initialize(HttpRequest request) {
}
@Test
- public void allocateIds() throws Exception {
+ void allocateIds() throws Exception {
AllocateIdsRequest.Builder request = AllocateIdsRequest.newBuilder();
AllocateIdsResponse.Builder response = AllocateIdsResponse.newBuilder();
expectRpc("allocateIds", request.build(), response.build());
}
@Test
- public void lookup() throws Exception {
+ void lookup() throws Exception {
LookupRequest.Builder request = LookupRequest.newBuilder();
LookupResponse.Builder response = LookupResponse.newBuilder();
expectRpc("lookup", request.build(), response.build());
}
@Test
- public void beginTransaction() throws Exception {
+ void beginTransaction() throws Exception {
BeginTransactionRequest.Builder request = BeginTransactionRequest.newBuilder();
BeginTransactionResponse.Builder response = BeginTransactionResponse.newBuilder();
response.setTransaction(ByteString.copyFromUtf8("project-id"));
@@ -304,7 +300,7 @@ public void beginTransaction() throws Exception {
}
@Test
- public void commit() throws Exception {
+ void commit() throws Exception {
CommitRequest.Builder request = CommitRequest.newBuilder();
request.setTransaction(ByteString.copyFromUtf8("project-id"));
CommitResponse.Builder response = CommitResponse.newBuilder();
@@ -312,14 +308,14 @@ public void commit() throws Exception {
}
@Test
- public void reserveIds() throws Exception {
+ void reserveIds() throws Exception {
ReserveIdsRequest.Builder request = ReserveIdsRequest.newBuilder();
ReserveIdsResponse.Builder response = ReserveIdsResponse.newBuilder();
expectRpc("reserveIds", request.build(), response.build());
}
@Test
- public void rollback() throws Exception {
+ void rollback() throws Exception {
RollbackRequest.Builder request = RollbackRequest.newBuilder();
request.setTransaction(ByteString.copyFromUtf8("project-id"));
RollbackResponse.Builder response = RollbackResponse.newBuilder();
@@ -327,7 +323,7 @@ public void rollback() throws Exception {
}
@Test
- public void runQuery() throws Exception {
+ void runQuery() throws Exception {
RunQueryRequest.Builder request = RunQueryRequest.newBuilder();
request.getQueryBuilder();
RunQueryResponse.Builder response = RunQueryResponse.newBuilder();
@@ -339,7 +335,7 @@ public void runQuery() throws Exception {
}
@Test
- public void runAggregationQuery() throws Exception {
+ void runAggregationQuery() throws Exception {
RunAggregationQueryRequest.Builder request = RunAggregationQueryRequest.newBuilder();
RunAggregationQueryResponse.Builder response = RunAggregationQueryResponse.newBuilder();
expectRpc("runAggregationQuery", request.build(), response.build());
@@ -366,41 +362,39 @@ private void expectRpc(String methodName, Message request, Message response) thr
assertEquals(0, datastore.getRpcCount());
mockClient.setNextError(400, Code.INVALID_ARGUMENT, "oops");
- try {
- call.invoke(datastore, callArgs);
- fail();
- } catch (InvocationTargetException targetException) {
- DatastoreException exception = (DatastoreException) targetException.getCause();
- assertEquals(Code.INVALID_ARGUMENT, exception.getCode());
- assertEquals(methodName, exception.getMethodName());
- assertEquals("oops", exception.getMessage());
- }
+ DatastoreException exception =
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ try {
+ call.invoke(datastore, callArgs);
+ } catch (InvocationTargetException e) {
+ throw (Exception) e.getCause();
+ }
+ });
+ assertEquals(Code.INVALID_ARGUMENT, exception.getCode());
+ assertEquals(methodName, exception.getMethodName());
+ assertEquals("oops", exception.getMessage());
SocketTimeoutException socketTimeoutException = new SocketTimeoutException("ste");
mockClient.setNextException(socketTimeoutException);
- try {
- call.invoke(datastore, callArgs);
- fail();
- } catch (InvocationTargetException targetException) {
- DatastoreException exception = (DatastoreException) targetException.getCause();
- assertEquals(Code.DEADLINE_EXCEEDED, exception.getCode());
- assertEquals(methodName, exception.getMethodName());
- assertEquals("Deadline exceeded", exception.getMessage());
- assertSame(socketTimeoutException, exception.getCause());
- }
+ InvocationTargetException ex2 =
+ assertThrows(InvocationTargetException.class, () -> call.invoke(datastore, callArgs));
+ DatastoreException exception1 = (DatastoreException) ex2.getCause();
+ assertEquals(Code.DEADLINE_EXCEEDED, exception1.getCode());
+ assertEquals(methodName, exception1.getMethodName());
+ assertEquals("Deadline exceeded", exception1.getMessage());
+ assertSame(socketTimeoutException, exception1.getCause());
IOException ioException = new IOException("ioe");
mockClient.setNextException(ioException);
- try {
- call.invoke(datastore, callArgs);
- fail();
- } catch (InvocationTargetException targetException) {
- DatastoreException exception = (DatastoreException) targetException.getCause();
- assertEquals(Code.UNAVAILABLE, exception.getCode());
- assertEquals(methodName, exception.getMethodName());
- assertEquals("I/O error", exception.getMessage());
- assertSame(ioException, exception.getCause());
- }
+ InvocationTargetException ex3 =
+ assertThrows(InvocationTargetException.class, () -> call.invoke(datastore, callArgs));
+ DatastoreException exception2 = (DatastoreException) ex3.getCause();
+ assertEquals(Code.UNAVAILABLE, exception2.getCode());
+ assertEquals(methodName, exception2.getMethodName());
+ assertEquals("I/O error", exception2.getMessage());
+ assertSame(ioException, exception2.getCause());
assertEquals(3, datastore.getRpcCount());
}
diff --git a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreFactoryTest.java b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreFactoryTest.java
index 2a3d5a38f..fa8854dfa 100644
--- a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreFactoryTest.java
+++ b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreFactoryTest.java
@@ -15,21 +15,18 @@
*/
package com.google.datastore.utils;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.javanet.NetHttpTransport;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Test for {@link DatastoreFactory}. */
-@RunWith(JUnit4.class)
-public class DatastoreFactoryTest {
+class DatastoreFactoryTest {
private static final String PROJECT_ID = "project-id";
private DatastoreFactory factory = DatastoreFactory.get();
@@ -39,7 +36,7 @@ public class DatastoreFactoryTest {
* its own.
*/
@Test
- public void makeClient_Default() {
+ void makeClient_Default() {
DatastoreOptions options = new DatastoreOptions.Builder().projectId(PROJECT_ID).build();
HttpRequestFactory f = factory.makeClient(options);
assertNotNull(f.getTransport());
@@ -51,7 +48,7 @@ public void makeClient_Default() {
* credential.
*/
@Test
- public void makeClient_WithCredential() {
+ void makeClient_WithCredential() {
NetHttpTransport transport = new NetHttpTransport();
GoogleCredential credential = new GoogleCredential.Builder().setTransport(transport).build();
DatastoreOptions options =
@@ -62,7 +59,7 @@ public void makeClient_WithCredential() {
/** Specifying a transport, but not a credential, the factory will use the transport specified. */
@Test
- public void makeClient_WithTransport() {
+ void makeClient_WithTransport() {
NetHttpTransport transport = new NetHttpTransport();
DatastoreOptions options =
new DatastoreOptions.Builder().projectId(PROJECT_ID).transport(transport).build();
@@ -75,7 +72,7 @@ public void makeClient_WithTransport() {
* the one in the credential.
*/
@Test
- public void makeClient_WithCredentialTransport() {
+ void makeClient_WithCredentialTransport() {
NetHttpTransport credTransport = new NetHttpTransport();
NetHttpTransport transport = new NetHttpTransport();
GoogleCredential credential =
diff --git a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreHelperTest.java b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreHelperTest.java
index 246202444..e35008acb 100644
--- a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreHelperTest.java
+++ b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/DatastoreHelperTest.java
@@ -16,8 +16,8 @@
package com.google.datastore.utils;
import static com.google.datastore.utils.DatastoreHelper.*;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.datastore.v1.Key;
import com.google.datastore.v1.PartitionId;
@@ -26,13 +26,10 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.Timestamp;
import java.util.Date;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Tests for {@link DatastoreHelper}. */
-@RunWith(JUnit4.class)
-public class DatastoreHelperTest {
+class DatastoreHelperTest {
private static final Key PARENT =
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Parent").setId(23L)).build();
@@ -44,65 +41,58 @@ public class DatastoreHelperTest {
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Child").setId(26L)).build();
@Test
- public void testMakeKey_BadTypeForKind() {
- try {
- DatastoreHelper.makeKey(new Object());
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ void testMakeKey_BadTypeForKind() {
+ assertThrows(IllegalArgumentException.class, () -> DatastoreHelper.makeKey(new Object()));
}
@Test
- public void testMakeKey_BadTypeForNameId() {
- try {
- DatastoreHelper.makeKey("kind", new Object());
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ void testMakeKey_BadTypeForNameId() {
+ assertThrows(
+ IllegalArgumentException.class, () -> DatastoreHelper.makeKey("kind", new Object()));
}
@Test
- public void testMakeKey_Empty() {
+ void testMakeKey_Empty() {
assertEquals(Key.newBuilder().build(), DatastoreHelper.makeKey().build());
}
@Test
- public void testMakeKey_Incomplete() {
+ void testMakeKey_Incomplete() {
assertEquals(
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Foo")).build(),
makeKey("Foo").build());
}
@Test
- public void testMakeKey_IdInt() {
+ void testMakeKey_IdInt() {
assertEquals(
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Foo").setId(1)).build(),
makeKey("Foo", 1).build());
}
@Test
- public void testMakeKey_IdLong() {
+ void testMakeKey_IdLong() {
assertEquals(
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Foo").setId(1)).build(),
makeKey("Foo", 1L).build());
}
@Test
- public void testMakeKey_IdShort() {
+ void testMakeKey_IdShort() {
assertEquals(
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Foo").setId(1)).build(),
makeKey("Foo", (short) 1).build());
}
@Test
- public void testMakeKey_Name() {
+ void testMakeKey_Name() {
assertEquals(
Key.newBuilder().addPath(Key.PathElement.newBuilder().setKind("Foo").setName("hi")).build(),
makeKey("Foo", "hi").build());
}
@Test
- public void testMakeKey_KindNameKind() {
+ void testMakeKey_KindNameKind() {
assertEquals(
Key.newBuilder()
.addPath(Key.PathElement.newBuilder().setKind("Foo").setName("hi"))
@@ -112,7 +102,7 @@ public void testMakeKey_KindNameKind() {
}
@Test
- public void testMakeKey_KeyKind() {
+ void testMakeKey_KeyKind() {
// 1 key at the beginning of the series
assertEquals(
Key.newBuilder()
@@ -123,7 +113,7 @@ public void testMakeKey_KeyKind() {
}
@Test
- public void testMakeKey_KindIdKeyKind() {
+ void testMakeKey_KindIdKeyKind() {
// 1 key in the middle of the series
assertEquals(
Key.newBuilder()
@@ -135,7 +125,7 @@ public void testMakeKey_KindIdKeyKind() {
}
@Test
- public void testMakeKey_KindIdKey() {
+ void testMakeKey_KindIdKey() {
// 1 key at the end of the series
assertEquals(
Key.newBuilder()
@@ -146,7 +136,7 @@ public void testMakeKey_KindIdKey() {
}
@Test
- public void testMakeKey_KeyKindIdKey() {
+ void testMakeKey_KeyKindIdKey() {
// 1 key at the beginning and 1 key at the end of the series
assertEquals(
Key.newBuilder()
@@ -158,13 +148,13 @@ public void testMakeKey_KeyKindIdKey() {
}
@Test
- public void testMakeKey_Key() {
+ void testMakeKey_Key() {
// Just 1 key
assertEquals(Key.newBuilder().addPath(CHILD.getPath(0)).build(), makeKey(CHILD).build());
}
@Test
- public void testMakeKey_KeyKey() {
+ void testMakeKey_KeyKey() {
// Just 2 keys
assertEquals(
Key.newBuilder().addPath(PARENT.getPath(0)).addPath(CHILD.getPath(0)).build(),
@@ -172,7 +162,7 @@ public void testMakeKey_KeyKey() {
}
@Test
- public void testMakeKey_KeyKeyKey() {
+ void testMakeKey_KeyKeyKey() {
// Just 3 keys
assertEquals(
Key.newBuilder()
@@ -184,7 +174,7 @@ public void testMakeKey_KeyKeyKey() {
}
@Test
- public void testMakeKey_KeyMultiLevelKey() {
+ void testMakeKey_KeyMultiLevelKey() {
// 1 key with 2 elements
assertEquals(
Key.newBuilder()
@@ -196,7 +186,7 @@ public void testMakeKey_KeyMultiLevelKey() {
}
@Test
- public void testMakeKey_MultiLevelKeyKey() {
+ void testMakeKey_MultiLevelKeyKey() {
// 1 key with 2 elements
assertEquals(
Key.newBuilder()
@@ -208,7 +198,7 @@ public void testMakeKey_MultiLevelKeyKey() {
}
@Test
- public void testMakeKey_MultiLevelKey() {
+ void testMakeKey_MultiLevelKey() {
// 1 key with 3 elements
assertEquals(
Key.newBuilder()
@@ -220,7 +210,7 @@ public void testMakeKey_MultiLevelKey() {
}
@Test
- public void testMakeKey_PartitionId() {
+ void testMakeKey_PartitionId() {
PartitionId partitionId = PartitionId.newBuilder().setNamespaceId("namespace-id").build();
Key parent = PARENT.toBuilder().setPartitionId(partitionId).build();
assertEquals(
@@ -233,21 +223,20 @@ public void testMakeKey_PartitionId() {
}
@Test
- public void testMakeKey_NonMatchingPartitionId2() {
+ void testMakeKey_NonMatchingPartitionId2() {
PartitionId partitionId1 = PartitionId.newBuilder().setNamespaceId("namespace-id").build();
PartitionId partitionId2 =
PartitionId.newBuilder().setNamespaceId("another-namespace-id").build();
- try {
- makeKey(
- PARENT.toBuilder().setPartitionId(partitionId1).build(),
- CHILD.toBuilder().setPartitionId(partitionId2).build());
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ makeKey(
+ PARENT.toBuilder().setPartitionId(partitionId1).build(),
+ CHILD.toBuilder().setPartitionId(partitionId2).build()));
}
@Test
- public void testMakeTimestampValue() throws Exception {
+ void testMakeTimestampValue() throws Exception {
// Test cases with nanos == 0.
assertConversion(-50_000, -50, 0);
assertConversion(-1_000, -1, 0);
@@ -298,20 +287,12 @@ private void assertTimestampToMilliseconds(long millis, long seconds, int nanos)
}
@Test
- public void testProjectionHandling() {
+ void testProjectionHandling() {
assertEquals(
ByteString.copyFromUtf8("hi"), getByteString(makeValue("hi").setMeaning(18).build()));
- try {
- getByteString(makeValue("hi").build());
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> getByteString(makeValue("hi").build()));
assertEquals(new Date(1), toDate(makeValue(1000).setMeaning(18).build()));
- try {
- toDate(makeValue(1000).build());
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> toDate(makeValue(1000).build()));
}
}
diff --git a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/QuerySplitterTest.java b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/QuerySplitterTest.java
index cad9502ae..62d64e0f6 100644
--- a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/QuerySplitterTest.java
+++ b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/QuerySplitterTest.java
@@ -17,8 +17,8 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.datastore.utils.DatastoreHelper.*;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.datastore.utils.testing.MockCredential;
import com.google.datastore.utils.testing.MockDatastoreFactory;
@@ -30,13 +30,10 @@
import com.google.protobuf.Int32Value;
import com.google.protobuf.Timestamp;
import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Tests for {@link com.google.datastore.utils.QuerySplitterImpl}. */
-@RunWith(JUnit4.class)
-public class QuerySplitterTest {
+class QuerySplitterTest {
private static final String PROJECT_ID = "project-id";
private static final PartitionId PARTITION =
PartitionId.newBuilder().setProjectId(PROJECT_ID).build();
@@ -70,7 +67,7 @@ public class QuerySplitterTest {
makeKey(KIND, String.format("%05d", 301)).setPartitionId(PARTITION).build();
@Test
- public void disallowsSortOrder() {
+ void disallowsSortOrder() {
com.google.datastore.utils.Datastore datastore = factory.create(options.build());
Query queryWithOrder =
query.toBuilder().addOrder(makeOrder("bar", Direction.ASCENDING)).build();
@@ -84,7 +81,7 @@ public void disallowsSortOrder() {
}
@Test
- public void disallowsMultipleKinds() {
+ void disallowsMultipleKinds() {
com.google.datastore.utils.Datastore datastore = factory.create(options.build());
Query queryWithMultipleKinds =
query.toBuilder()
@@ -100,7 +97,7 @@ public void disallowsMultipleKinds() {
}
@Test
- public void disallowsKindlessQuery() {
+ void disallowsKindlessQuery() {
com.google.datastore.utils.Datastore datastore = factory.create(options.build());
Query kindlessQuery = query.toBuilder().clearKind().build();
IllegalArgumentException exception =
@@ -113,7 +110,7 @@ public void disallowsKindlessQuery() {
}
@Test
- public void disallowsInequalityFilter() {
+ void disallowsInequalityFilter() {
com.google.datastore.utils.Datastore datastore = factory.create(options.build());
Query queryWithInequality =
query.toBuilder()
@@ -129,7 +126,7 @@ public void disallowsInequalityFilter() {
}
@Test
- public void splitsMustBePositive() {
+ void splitsMustBePositive() {
com.google.datastore.utils.Datastore datastore = factory.create(options.build());
IllegalArgumentException exception =
assertThrows(
@@ -141,7 +138,7 @@ public void splitsMustBePositive() {
}
@Test
- public void getSplits() throws Exception {
+ void getSplits() throws Exception {
com.google.datastore.utils.Datastore datastore = factory.create(options.build());
MockDatastoreFactory mockClient = (MockDatastoreFactory) factory;
@@ -189,7 +186,7 @@ public void getSplits() throws Exception {
}
@Test
- public void getSplitsWithDatabaseId() throws Exception {
+ void getSplitsWithDatabaseId() throws Exception {
com.google.datastore.utils.Datastore datastore = factory.create(options.build());
MockDatastoreFactory mockClient = (MockDatastoreFactory) factory;
@@ -241,7 +238,7 @@ public void getSplitsWithDatabaseId() throws Exception {
}
@Test
- public void notEnoughSplits() throws Exception {
+ void notEnoughSplits() throws Exception {
com.google.datastore.utils.Datastore datastore = factory.create(options.build());
MockDatastoreFactory mockClient = (MockDatastoreFactory) factory;
@@ -283,7 +280,7 @@ public void notEnoughSplits() throws Exception {
}
@Test
- public void getSplits_withReadTime() throws Exception {
+ void getSplits_withReadTime() throws Exception {
Datastore datastore = factory.create(options.build());
MockDatastoreFactory mockClient = (MockDatastoreFactory) factory;
diff --git a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/RemoteRpcTest.java b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/RemoteRpcTest.java
index ae4d7a23e..161781273 100644
--- a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/RemoteRpcTest.java
+++ b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/RemoteRpcTest.java
@@ -15,7 +15,8 @@
*/
package com.google.datastore.utils;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpTransport;
@@ -34,18 +35,15 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPOutputStream;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Test for {@link RemoteRpc}. */
-@RunWith(JUnit4.class)
-public class RemoteRpcTest {
+class RemoteRpcTest {
private static final String METHOD_NAME = "methodName";
@Test
- public void testException() {
+ void testException() {
Status statusProto =
Status.newBuilder()
.setCode(Code.UNAUTHENTICATED_VALUE)
@@ -67,7 +65,7 @@ public void testException() {
}
@Test
- public void testInvalidProtoException() {
+ void testInvalidProtoException() {
DatastoreException exception =
RemoteRpc.makeException(
"url",
@@ -85,7 +83,7 @@ public void testInvalidProtoException() {
}
@Test
- public void testEmptyProtoException() {
+ void testEmptyProtoException() {
Status statusProto = Status.newBuilder().build();
DatastoreException exception =
RemoteRpc.makeException(
@@ -104,7 +102,7 @@ public void testEmptyProtoException() {
}
@Test
- public void testEmptyProtoExceptionUnauthenticated() {
+ void testEmptyProtoExceptionUnauthenticated() {
Status statusProto = Status.newBuilder().build();
DatastoreException exception =
RemoteRpc.makeException(
@@ -121,7 +119,7 @@ public void testEmptyProtoExceptionUnauthenticated() {
}
@Test
- public void testPlainTextException() {
+ void testPlainTextException() {
DatastoreException exception =
RemoteRpc.makeException(
"url",
@@ -138,7 +136,7 @@ public void testPlainTextException() {
}
@Test
- public void testGzip() throws IOException, DatastoreException {
+ void testGzip() throws IOException, DatastoreException {
BeginTransactionResponse response = newBeginTransactionResponse();
InjectedTestValues injectedTestValues =
new InjectedTestValues(gzip(response), new byte[1], true);
@@ -155,7 +153,7 @@ public void testGzip() throws IOException, DatastoreException {
}
@Test
- public void testHttpHeaders_apiFormat() throws IOException {
+ void testHttpHeaders_apiFormat() throws IOException {
String projectId = "project-id";
MessageLite request =
RollbackRequest.newBuilder().setTransaction(ByteString.copyFromUtf8(projectId)).build();
@@ -170,7 +168,7 @@ public void testHttpHeaders_apiFormat() throws IOException {
}
@Test
- public void testHttpHeaders_prefixHeader() throws IOException {
+ void testHttpHeaders_prefixHeader() throws IOException {
String projectId = "my-project";
String databaseId = "my-db";
MessageLite request =
diff --git a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/it/ITDatastoreProtoClientTest.java b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/it/ITDatastoreProtoClientTest.java
index d30c1cbdc..d8b172819 100644
--- a/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/it/ITDatastoreProtoClientTest.java
+++ b/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/it/ITDatastoreProtoClientTest.java
@@ -26,10 +26,10 @@
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class ITDatastoreProtoClientTest {
+class ITDatastoreProtoClientTest {
private static Datastore DATASTORE;
@@ -38,13 +38,13 @@ public class ITDatastoreProtoClientTest {
private static final String KIND = "test-kind";
private static final String PROJECT_ID = System.getenv(DatastoreHelper.PROJECT_ID_ENV_VAR);
- @Before
- public void setUp() throws GeneralSecurityException, IOException {
+ @BeforeEach
+ void setUp() throws GeneralSecurityException, IOException {
DATASTORE = DatastoreHelper.getDatastoreFromEnv();
}
@Test
- public void testQuerySplitterWithDefaultDb() throws DatastoreException {
+ void testQuerySplitterWithDefaultDb() throws DatastoreException {
Filter propertyFilter =
makeFilter("foo", PropertyFilter.Operator.EQUAL, makeValue("value")).build();
Query query =
@@ -66,7 +66,7 @@ public void testQuerySplitterWithDefaultDb() throws DatastoreException {
}
@Test
- public void testQuerySplitterWithDb() throws DatastoreException {
+ void testQuerySplitterWithDb() throws DatastoreException {
Filter propertyFilter =
makeFilter("foo", PropertyFilter.Operator.EQUAL, makeValue("value")).build();
Query query =
diff --git a/google-cloud-datastore/pom.xml b/google-cloud-datastore/pom.xml
index 30867c3e3..a498fc09a 100644
--- a/google-cloud-datastore/pom.xml
+++ b/google-cloud-datastore/pom.xml
@@ -182,9 +182,27 @@
testlib
test
+
+
junit
junit
+ 4.13.2
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+ org.junit.vintage
+ junit-vintage-engine
test
@@ -200,10 +218,11 @@
com.google.testparameterinjector
- test-parameter-injector
+ test-parameter-injector-junit5
1.17
test
+
io.opentelemetry
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AbstractDatastoreTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AbstractDatastoreTest.java
index 9d4ecac57..d3315e10c 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AbstractDatastoreTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AbstractDatastoreTest.java
@@ -24,14 +24,14 @@
import static org.easymock.EasyMock.createStrictMock;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.cloud.ServiceOptions;
import com.google.cloud.Timestamp;
@@ -78,19 +78,22 @@
import java.util.Set;
import java.util.function.Predicate;
import org.easymock.EasyMock;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-@RunWith(JUnit4.class)
-public abstract class AbstractDatastoreTest {
+abstract class AbstractDatastoreTest {
private static final LocalDatastoreHelper helper = LocalDatastoreHelper.create(1.0, 9090);
- protected static DatastoreOptions options = helper.getOptions();
- protected static Datastore datastore;
- private static final String PROJECT_ID = options.getProjectId();
+ protected static final DatastoreOptions options;
+ protected static final Datastore datastore;
+ private static final String PROJECT_ID;
+
+ static {
+ options = helper.getOptions();
+ datastore = options.getService();
+ PROJECT_ID = options.getProjectId();
+ }
+
private static final String KIND1 = "kind1";
private static final String KIND2 = "kind2";
private static final String KIND3 = "kind3";
@@ -162,13 +165,8 @@ public abstract class AbstractDatastoreTest {
private DatastoreRpcFactory rpcFactoryMock;
private DatastoreRpc rpcMock;
- public AbstractDatastoreTest(DatastoreOptions options, Datastore datastore) {
- this.options = options;
- this.datastore = datastore;
- }
-
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
rpcFactoryMock = EasyMock.createStrictMock(DatastoreRpcFactory.class);
rpcMock = EasyMock.createStrictMock(DatastoreRpc.class);
DatastoreOpenTelemetryOptions.Builder otelOptionsBuilder =
@@ -186,12 +184,12 @@ public void setUp() {
}
@Test
- public void testGetOptions() {
+ void testGetOptions() {
assertSame(options, datastore.getOptions());
}
@Test
- public void testNewTransactionCommit() {
+ void testNewTransactionCommit() {
Transaction transaction = datastore.newTransaction();
transaction.add(ENTITY3);
Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build();
@@ -205,25 +203,15 @@ public void testNewTransactionCommit() {
assertEquals(ENTITY3, list.get(2));
assertEquals(3, list.size());
- try {
- transaction.commit();
- fail("Expecting a failure");
- } catch (DatastoreException ex) {
- // expected to fail
- }
+ assertThrows(DatastoreException.class, transaction::commit);
- try {
- transaction.rollback();
- fail("Expecting a failure");
- } catch (DatastoreException ex) {
- // expected to fail
- }
+ assertThrows(DatastoreException.class, transaction::rollback);
verifyNotUsable(transaction);
}
@Test
- public void testTransactionWithRead() {
+ void testTransactionWithRead() {
Transaction transaction = datastore.newTransaction();
assertNull(transaction.get(KEY3));
transaction.add(ENTITY3);
@@ -234,17 +222,12 @@ public void testTransactionWithRead() {
assertEquals(ENTITY3, transaction.get(KEY3));
// update entity3 during the transaction
datastore.put(Entity.newBuilder(ENTITY3).clear().build());
- transaction.update(ENTITY2);
- try {
- transaction.commit();
- fail("Expecting a failure");
- } catch (DatastoreException expected) {
- assertEquals("ABORTED", expected.getReason());
- }
+ DatastoreException expected = assertThrows(DatastoreException.class, transaction::commit);
+ assertEquals("ABORTED", expected.getReason());
}
@Test
- public void testTransactionWithQuery() {
+ void testTransactionWithQuery() {
Query query =
Query.newEntityQueryBuilder()
.setKind(KIND2)
@@ -264,16 +247,12 @@ public void testTransactionWithQuery() {
transaction.delete(ENTITY3.getKey());
// update entity2 during the transaction
datastore.put(Entity.newBuilder(ENTITY2).clear().build());
- try {
- transaction.commit();
- fail("Expecting a failure");
- } catch (DatastoreException expected) {
- assertEquals("ABORTED", expected.getReason());
- }
+ DatastoreException expected = assertThrows(DatastoreException.class, transaction::commit);
+ assertEquals("ABORTED", expected.getReason());
}
@Test
- public void testNewTransactionRollback() {
+ void testNewTransactionRollback() {
Transaction transaction = datastore.newTransaction();
transaction.add(ENTITY3);
Entity entity2 =
@@ -287,12 +266,7 @@ public void testNewTransactionRollback() {
transaction.rollback();
transaction.rollback(); // should be safe to repeat rollback calls
- try {
- transaction.commit();
- fail("Expecting a failure");
- } catch (DatastoreException ex) {
- // expected to fail
- }
+ assertThrows(DatastoreException.class, transaction::commit);
verifyNotUsable(transaction);
@@ -304,7 +278,7 @@ public void testNewTransactionRollback() {
}
@Test
- public void testRunInTransactionWithReadWriteOption() {
+ void testRunInTransactionWithReadWriteOption() {
EasyMock.expect(rpcMock.beginTransaction(EasyMock.anyObject(BeginTransactionRequest.class)))
.andReturn(BeginTransactionResponse.getDefaultInstance());
@@ -345,37 +319,17 @@ public Integer run(DatastoreReaderWriter transaction) {
}
private void verifyNotUsable(DatastoreWriter writer) {
- try {
- writer.add(ENTITY3);
- fail("Expecting a failure");
- } catch (DatastoreException ex) {
- // expected to fail
- }
+ assertThrows(DatastoreException.class, () -> writer.add(ENTITY3));
- try {
- writer.put(ENTITY3);
- fail("Expecting a failure");
- } catch (DatastoreException ex) {
- // expected to fail
- }
+ assertThrows(DatastoreException.class, () -> writer.put(ENTITY3));
- try {
- writer.update(ENTITY3);
- fail("Expecting a failure");
- } catch (DatastoreException ex) {
- // expected to fail
- }
+ assertThrows(DatastoreException.class, () -> writer.update(ENTITY3));
- try {
- writer.delete(ENTITY3.getKey());
- fail("Expecting a failure");
- } catch (DatastoreException ex) {
- // expected to fail
- }
+ assertThrows(DatastoreException.class, () -> writer.delete(ENTITY3.getKey()));
}
@Test
- public void testNewBatch() {
+ void testNewBatch() {
Batch batch = datastore.newBatch();
Entity entity1 = Entity.newBuilder(ENTITY1).clear().build();
Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build();
@@ -413,12 +367,7 @@ public void testNewBatch() {
PARTIAL_ENTITY3.getProperties(), datastore.get(generatedKeys.get(0)).getProperties());
assertEquals(PARTIAL_ENTITY3.getKey(), IncompleteKey.newBuilder(generatedKeys.get(0)).build());
- try {
- batch.submit();
- fail("Expecting a failure");
- } catch (DatastoreException ex) {
- // expected to fail
- }
+ assertThrows(DatastoreException.class, batch::submit);
verifyNotUsable(batch);
batch = datastore.newBatch();
@@ -435,7 +384,7 @@ public void testNewBatch() {
}
@Test
- public void testRunGqlQueryNoCasting() {
+ void testRunGqlQueryNoCasting() {
Query query1 =
Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND1).build();
QueryResults results1 = datastore.run(query1);
@@ -489,7 +438,7 @@ public void testRunGqlQueryNoCasting() {
}
@Test
- public void testRunGqlQueryWithCasting() {
+ void testRunGqlQueryWithCasting() {
@SuppressWarnings("unchecked")
Query query1 =
(Query) Query.newGqlQueryBuilder("select * from " + KIND1).build();
@@ -509,7 +458,7 @@ public void testRunGqlQueryWithCasting() {
}
@Test
- public void testGqlQueryPagination() throws DatastoreException {
+ void testGqlQueryPagination() throws DatastoreException {
List responses = buildResponsesForQueryPagination();
for (int i = 0; i < responses.size(); i++) {
EasyMock.expect(rpcMock.runQuery(EasyMock.anyObject(RunQueryRequest.class)))
@@ -530,7 +479,7 @@ public void testGqlQueryPagination() throws DatastoreException {
}
@Test
- public void testRunAggregationQuery() {
+ void testRunAggregationQuery() {
RunAggregationQueryResponse aggregationQueryResponse = placeholderAggregationQueryResponse();
EasyMock.expect(rpcMock.runAggregationQuery(matches(aggregationQueryWithAlias("total_count"))))
.andReturn(aggregationQueryResponse);
@@ -551,7 +500,7 @@ public void testRunAggregationQuery() {
}
@Test
- public void testRunStructuredQuery() {
+ void testRunStructuredQuery() {
Query query =
Query.newEntityQueryBuilder().setKind(KIND1).setOrderBy(OrderBy.asc("__key__")).build();
QueryResults results1 = datastore.run(query);
@@ -594,7 +543,7 @@ public void testRunStructuredQuery() {
}
@Test
- public void testStructuredQueryPagination() throws DatastoreException {
+ void testStructuredQueryPagination() throws DatastoreException {
List responses = buildResponsesForQueryPagination();
for (int i = 0; i < responses.size(); i++) {
EasyMock.expect(rpcMock.runQuery(EasyMock.anyObject(RunQueryRequest.class)))
@@ -613,7 +562,7 @@ public void testStructuredQueryPagination() throws DatastoreException {
}
@Test
- public void testStructuredQueryPaginationWithMoreResults() throws DatastoreException {
+ void testStructuredQueryPaginationWithMoreResults() throws DatastoreException {
List responses = buildResponsesForQueryPagination();
for (int i = 0; i < responses.size(); i++) {
EasyMock.expect(rpcMock.runQuery(EasyMock.anyObject(RunQueryRequest.class)))
@@ -676,7 +625,7 @@ private List buildResponsesForQueryPagination() {
}
@Test
- public void testQueryPaginationWithLimit() throws DatastoreException {
+ void testQueryPaginationWithLimit() throws DatastoreException {
List responses = buildResponsesForQueryPaginationWithLimit();
List endCursors = Lists.newArrayListWithCapacity(responses.size());
for (RunQueryResponse response : responses) {
@@ -713,14 +662,14 @@ public void testQueryPaginationWithLimit() throws DatastoreException {
}
@Test
- public void testRunKeyQueryWithOffset() {
+ void testRunKeyQueryWithOffset() {
Query query = Query.newKeyQueryBuilder().setOffset(Integer.MAX_VALUE).build();
int numberOfEntities = datastore.run(query).getSkippedResults();
assertEquals(2, numberOfEntities);
}
@Test
- public void testRunKeyQueryWithLimit() {
+ void testRunKeyQueryWithLimit() {
datastore.put(ENTITY1, ENTITY2);
Query keyQuery = Query.newKeyQueryBuilder().setLimit(2).build();
QueryResults queryResults = datastore.run(keyQuery);
@@ -796,7 +745,7 @@ private List buildResponsesForQueryPaginationWithLimit() {
}
@Test
- public void testEventualConsistencyQuery() {
+ void testEventualConsistencyQuery() {
ReadOptions readOption =
ReadOptions.newBuilder().setReadConsistencyValue(ReadConsistency.EVENTUAL_VALUE).build();
com.google.datastore.v1.GqlQuery query =
@@ -817,7 +766,7 @@ public void testEventualConsistencyQuery() {
}
@Test
- public void testReadTimeQuery() {
+ void testReadTimeQuery() {
Timestamp timestamp = Timestamp.now();
ReadOptions readOption = ReadOptions.newBuilder().setReadTime(timestamp.toProto()).build();
com.google.datastore.v1.GqlQuery query =
@@ -831,14 +780,18 @@ public void testReadTimeQuery() {
EasyMock.expect(rpcMock.runQuery(expectedRequest.build()))
.andReturn(RunQueryResponse.newBuilder().build());
EasyMock.replay(rpcFactoryMock, rpcMock);
- Datastore datastore = rpcMockOptions.getService();
+ com.google.cloud.datastore.Datastore datastore = rpcMockOptions.getService();
datastore.run(
Query.newGqlQueryBuilder("FROM * SELECT *").build(), ReadOption.readTime(timestamp));
+ datastore.get(
+ ImmutableList.of(KEY1), com.google.cloud.datastore.ReadOption.readTime(timestamp));
+ datastore.fetch(
+ ImmutableList.of(KEY1), com.google.cloud.datastore.ReadOption.readTime(timestamp));
EasyMock.verify(rpcFactoryMock, rpcMock);
}
@Test
- public void testToUrlSafe() {
+ void testToUrlSafe() {
byte[][] invalidUtf8 =
new byte[][] {{(byte) 0xfe}, {(byte) 0xc1, (byte) 0xbf}, {(byte) 0xc0}, {(byte) 0x80}};
for (byte[] bytes : invalidUtf8) {
@@ -849,7 +802,7 @@ public void testToUrlSafe() {
}
@Test
- public void testAllocateId() {
+ void testAllocateId() {
KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND1);
IncompleteKey pk1 = keyFactory.newKey();
Key key1 = datastore.allocateId(pk1);
@@ -865,16 +818,13 @@ public void testAllocateId() {
assertNotEquals(key1, key2);
assertEquals(Key.newBuilder(pk1, key2.getId()).build(), key2);
- try {
- datastore.allocateId(key1);
- fail("Expecting a failure");
- } catch (IllegalArgumentException expected) {
- assertEquals(expected.getMessage(), "keys must be IncompleteKey instances");
- }
+ IllegalArgumentException expected =
+ assertThrows(IllegalArgumentException.class, () -> datastore.allocateId(key1));
+ assertEquals(expected.getMessage(), "keys must be IncompleteKey instances");
}
@Test
- public void testAllocateIdArray() {
+ void testAllocateIdArray() {
KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND1);
IncompleteKey incompleteKey1 = keyFactory.newKey();
IncompleteKey incompleteKey2 =
@@ -886,16 +836,15 @@ public void testAllocateIdArray() {
assertEquals(Key.newBuilder(incompleteKey1, result1.get(2).getId()).build(), result1.get(2));
assertEquals(Key.newBuilder(incompleteKey2, result1.get(1).getId()).build(), result1.get(1));
- try {
- datastore.allocateId(incompleteKey1, incompleteKey2, key3);
- fail("expecting a failure");
- } catch (IllegalArgumentException expected) {
- assertEquals(expected.getMessage(), "keys must be IncompleteKey instances");
- }
+ IllegalArgumentException expected =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> datastore.allocateId(incompleteKey1, incompleteKey2, key3));
+ assertEquals(expected.getMessage(), "keys must be IncompleteKey instances");
}
@Test
- public void testReserveIds() {
+ void testReserveIds() {
ReserveIdsRequest reserveIdsRequest =
ReserveIdsRequest.newBuilder().setProjectId(PROJECT_ID).addKeys(KEY1.toPb()).build();
EasyMock.expect(rpcMock.reserveIds(reserveIdsRequest))
@@ -908,7 +857,7 @@ public void testReserveIds() {
}
@Test
- public void testReserveIdsWithKeys() {
+ void testReserveIdsWithKeys() {
Datastore datastore = createStrictMock(Datastore.class);
EasyMock.expect(datastore.reserveIds(KEY1, KEY2)).andReturn(Arrays.asList(KEY1, KEY2));
replay(datastore);
@@ -919,7 +868,7 @@ public void testReserveIdsWithKeys() {
}
@Test
- public void testGet() {
+ void testGet() {
Entity entity = datastore.get(KEY3);
assertNull(entity);
@@ -944,7 +893,7 @@ public void testGet() {
}
@Test
- public void testLookupEventualConsistency() {
+ void testLookupEventualConsistency() {
ReadOptions readOption =
ReadOptions.newBuilder().setReadConsistencyValue(ReadConsistency.EVENTUAL_VALUE).build();
com.google.datastore.v1.Key key =
@@ -974,30 +923,23 @@ public void testLookupEventualConsistency() {
}
@Test
- public void testLookupReadTime() {
+ void testLookupReadTime() {
Timestamp timestamp = Timestamp.now();
ReadOptions readOption = ReadOptions.newBuilder().setReadTime(timestamp.toProto()).build();
- com.google.datastore.v1.Key key =
- com.google.datastore.v1.Key.newBuilder()
- .setPartitionId(PartitionId.newBuilder().setProjectId(PROJECT_ID).build())
- .addPath(
- com.google.datastore.v1.Key.PathElement.newBuilder()
- .setKind("kind1")
- .setName("name")
- .build())
- .build();
- LookupRequest lookupRequest =
- LookupRequest.newBuilder()
- .setProjectId(PROJECT_ID)
+ com.google.datastore.v1.GqlQuery query =
+ com.google.datastore.v1.GqlQuery.newBuilder().setQueryString("FROM * SELECT *").build();
+ RunQueryRequest.Builder expectedRequest =
+ RunQueryRequest.newBuilder()
.setReadOptions(readOption)
- .addKeys(key)
- .build();
- EasyMock.expect(rpcMock.lookup(lookupRequest))
- .andReturn(LookupResponse.newBuilder().build())
- .times(3);
+ .setGqlQuery(query)
+ .setProjectId(PROJECT_ID)
+ .setPartitionId(PartitionId.newBuilder().setProjectId(PROJECT_ID).build());
+ EasyMock.expect(rpcMock.runQuery(expectedRequest.build()))
+ .andReturn(RunQueryResponse.newBuilder().build());
EasyMock.replay(rpcFactoryMock, rpcMock);
com.google.cloud.datastore.Datastore datastore = rpcMockOptions.getService();
- datastore.get(KEY1, com.google.cloud.datastore.ReadOption.readTime(timestamp));
+ datastore.run(
+ Query.newGqlQueryBuilder("FROM * SELECT *").build(), ReadOption.readTime(timestamp));
datastore.get(
ImmutableList.of(KEY1), com.google.cloud.datastore.ReadOption.readTime(timestamp));
datastore.fetch(
@@ -1006,7 +948,7 @@ public void testLookupReadTime() {
}
@Test
- public void testGetArrayNoDeferredResults() {
+ void testGetArrayNoDeferredResults() {
datastore.put(ENTITY3);
Iterator result =
datastore.fetch(KEY1, Key.newBuilder(KEY1).setName("bla").build(), KEY2, KEY3).iterator();
@@ -1027,17 +969,13 @@ public void testGetArrayNoDeferredResults() {
assertEquals(EMPTY_LIST_VALUE, entity3.getValue("emptyList"));
assertEquals(8, entity3.getNames().size());
assertFalse(entity3.contains("bla"));
- try {
- entity3.getString("str");
- fail("Expecting a failure");
- } catch (DatastoreException expected) {
- // expected - no such property
- }
+ DatastoreException expected =
+ assertThrows(DatastoreException.class, () -> entity3.getString("str"));
assertFalse(result.hasNext());
}
@Test
- public void testGetArrayDeferredResults() throws DatastoreException {
+ void testGetArrayDeferredResults() throws DatastoreException {
Set requestedKeys = new HashSet<>();
requestedKeys.add(KEY1);
requestedKeys.add(KEY2);
@@ -1053,7 +991,7 @@ public void testGetArrayDeferredResults() throws DatastoreException {
}
@Test
- public void testFetchArrayDeferredResults() throws DatastoreException {
+ void testFetchArrayDeferredResults() throws DatastoreException {
List foundEntities =
createDatastoreForDeferredLookup().fetch(KEY1, KEY2, KEY3, KEY4, KEY5);
assertEquals(foundEntities.get(0).getKey(), KEY1);
@@ -1112,18 +1050,13 @@ private Datastore createDatastoreForDeferredLookup() throws DatastoreException {
}
@Test
- public void testAddEntity() {
+ void testAddEntity() {
List keys = datastore.fetch(ENTITY1.getKey(), ENTITY3.getKey());
assertEquals(ENTITY1, keys.get(0));
assertNull(keys.get(1));
assertEquals(2, keys.size());
- try {
- datastore.add(ENTITY1);
- fail("Expecting a failure");
- } catch (DatastoreException expected) {
- // expected;
- }
+ assertThrows(DatastoreException.class, () -> datastore.add(ENTITY1));
List entities = datastore.add(ENTITY3, PARTIAL_ENTITY1, PARTIAL_ENTITY2);
assertEquals(ENTITY3, datastore.get(ENTITY3.getKey()));
@@ -1137,18 +1070,13 @@ public void testAddEntity() {
}
@Test
- public void testUpdate() {
+ void testUpdate() {
List keys = datastore.fetch(ENTITY1.getKey(), ENTITY3.getKey());
assertEquals(ENTITY1, keys.get(0));
assertNull(keys.get(1));
assertEquals(2, keys.size());
- try {
- datastore.update(ENTITY3);
- fail("Expecting a failure");
- } catch (DatastoreException expected) {
- // expected;
- }
+ assertThrows(DatastoreException.class, () -> datastore.update(ENTITY3));
datastore.add(ENTITY3);
assertEquals(ENTITY3, datastore.get(ENTITY3.getKey()));
Entity entity3 = Entity.newBuilder(ENTITY3).clear().set("bla", new NullValue()).build();
@@ -1158,7 +1086,7 @@ public void testUpdate() {
}
@Test
- public void testPut() {
+ void testPut() {
Entity updatedEntity = Entity.newBuilder(ENTITY1).set("new_property", 42L).build();
assertEquals(updatedEntity, datastore.put(updatedEntity));
assertEquals(updatedEntity, datastore.get(updatedEntity.getKey()));
@@ -1179,7 +1107,7 @@ public void testPut() {
}
@Test
- public void testDelete() {
+ void testDelete() {
Iterator keys =
datastore.fetch(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()).iterator();
assertEquals(ENTITY1, keys.next());
@@ -1195,7 +1123,7 @@ public void testDelete() {
}
@Test
- public void testKeyFactory() {
+ void testKeyFactory() {
KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND1);
assertEquals(INCOMPLETE_KEY1, keyFactory.newKey());
assertEquals(
@@ -1206,7 +1134,7 @@ public void testKeyFactory() {
}
@Test
- public void testRetryableException() {
+ void testRetryableException() {
LookupRequest requestPb =
LookupRequest.newBuilder().setProjectId(PROJECT_ID).addKeys(KEY1.toPb()).build();
LookupResponse responsePb =
@@ -1214,6 +1142,7 @@ public void testRetryableException() {
.addFound(EntityResult.newBuilder().setEntity(ENTITY1.toPb()))
.build();
EasyMock.expect(rpcMock.lookup(requestPb))
+ .andReturn(LookupResponse.newBuilder().build())
.andThrow(new DatastoreException(14, "UNAVAILABLE", "UNAVAILABLE", null))
.andReturn(responsePb);
EasyMock.replay(rpcFactoryMock, rpcMock);
@@ -1224,7 +1153,7 @@ public void testRetryableException() {
}
@Test
- public void testRetryableExceptionForOperationWithTxn() {
+ void testRetryableExceptionForOperationWithTxn() {
ByteString txnBytes = ByteString.copyFromUtf8("txn1");
LookupRequest requestPb =
LookupRequest.newBuilder()
@@ -1250,7 +1179,7 @@ public void testRetryableExceptionForOperationWithTxn() {
}
@Test
- public void testNonRetryableExceptionForOperationWithTxn() {
+ void testNonRetryableExceptionForOperationWithTxn() {
ByteString txnBytes = ByteString.copyFromUtf8("txn1");
LookupRequest requestPb =
LookupRequest.newBuilder()
@@ -1264,19 +1193,19 @@ public void testNonRetryableExceptionForOperationWithTxn() {
.andThrow(new DatastoreException(10, "ABORTED", "ABORTED", null))
.times(1);
EasyMock.replay(rpcFactoryMock, rpcMock);
- try {
- Datastore datastore = rpcMockOptions.getService();
- Transaction transaction = datastore.newTransaction();
- transaction.get(KEY1);
- Assert.fail();
- EasyMock.verify(rpcFactoryMock, rpcMock);
- } catch (DatastoreException ex) {
- assertEquals("ABORTED", ex.getMessage());
- }
+ DatastoreException ex =
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ Datastore datastore = rpcMockOptions.getService();
+ Transaction transaction = datastore.newTransaction();
+ transaction.get(KEY1);
+ });
+ assertEquals("ABORTED", ex.getMessage());
}
@Test
- public void testNonRetryableException() {
+ void testNonRetryableException() {
LookupRequest requestPb =
LookupRequest.newBuilder().setProjectId(PROJECT_ID).addKeys(KEY1.toPb()).build();
EasyMock.expect(rpcMock.lookup(requestPb))
@@ -1284,35 +1213,35 @@ public void testNonRetryableException() {
new DatastoreException(DatastoreException.UNKNOWN_CODE, "denied", "PERMISSION_DENIED"))
.times(1);
EasyMock.replay(rpcFactoryMock, rpcMock);
- try {
- Datastore datastore = rpcMockOptions.getService();
- datastore.get(KEY1);
- Assert.fail();
- EasyMock.verify(rpcFactoryMock, rpcMock);
- } catch (DatastoreException ex) {
- assertEquals("denied", ex.getMessage());
- }
+ DatastoreException ex =
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ Datastore datastore = rpcMockOptions.getService();
+ datastore.get(KEY1);
+ });
+ assertEquals("denied", ex.getMessage());
}
@Test
- public void testRuntimeException() {
+ void testRuntimeException() {
LookupRequest requestPb =
LookupRequest.newBuilder().setProjectId(PROJECT_ID).addKeys(KEY1.toPb()).build();
String exceptionMessage = "Artificial runtime exception";
EasyMock.expect(rpcMock.lookup(requestPb)).andThrow(new RuntimeException(exceptionMessage));
EasyMock.replay(rpcFactoryMock, rpcMock);
- try {
- Datastore datastore = rpcMockOptions.getService();
- datastore.get(KEY1);
- Assert.fail();
- EasyMock.verify(rpcFactoryMock, rpcMock);
- } catch (DatastoreException ex) {
- assertEquals(exceptionMessage, ex.getCause().getMessage());
- }
+ DatastoreException ex =
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ Datastore datastore = rpcMockOptions.getService();
+ datastore.get(KEY1);
+ });
+ assertEquals(exceptionMessage, ex.getCause().getMessage());
}
@Test
- public void testGqlQueryWithNullBinding() {
+ void testGqlQueryWithNullBinding() {
Query query =
Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND1)
.setNullBinding("name")
@@ -1336,7 +1265,7 @@ public void testGqlQueryWithNullBinding() {
}
@Test
- public void testQueryWithStartCursor() {
+ void testQueryWithStartCursor() {
Entity entity1 =
Entity.newBuilder(Key.newBuilder(PROJECT_ID, KIND1, "name-01").build()).build();
Entity entity2 =
@@ -1357,7 +1286,7 @@ public void testQueryWithStartCursor() {
}
@Test
- public void testDatabaseIdKeyFactory() {
+ void testDatabaseIdKeyFactory() {
KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND1);
Key key1 = keyFactory.newKey("key1");
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AggregationQueryTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AggregationQueryTest.java
index fd037808c..7dfe951a0 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AggregationQueryTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AggregationQueryTest.java
@@ -22,16 +22,16 @@
import static com.google.cloud.datastore.aggregation.Aggregation.count;
import static com.google.cloud.datastore.aggregation.Aggregation.sum;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.cloud.datastore.aggregation.AvgAggregation;
import com.google.cloud.datastore.aggregation.CountAggregation;
import com.google.cloud.datastore.aggregation.SumAggregation;
import com.google.common.collect.ImmutableSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class AggregationQueryTest {
+class AggregationQueryTest {
private static final String KIND = "Task";
private static final String NAMESPACE = "ns";
@@ -44,7 +44,7 @@ public class AggregationQueryTest {
.build();
@Test
- public void testAggregations() {
+ void testAggregations() {
AggregationQuery aggregationQuery =
Query.newAggregationQueryBuilder()
.setNamespace(NAMESPACE)
@@ -60,7 +60,7 @@ public void testAggregations() {
}
@Test
- public void testAggregationBuilderWithMultipleAggregationsOneByOne() {
+ void testAggregationBuilderWithMultipleAggregationsOneByOne() {
AggregationQuery aggregationQuery =
Query.newAggregationQueryBuilder()
.setNamespace(NAMESPACE)
@@ -79,7 +79,7 @@ public void testAggregationBuilderWithMultipleAggregationsOneByOne() {
}
@Test
- public void testAggregationBuilderWithMultipleAggregationsTogether() {
+ void testAggregationBuilderWithMultipleAggregationsTogether() {
AggregationQuery aggregationQuery =
Query.newAggregationQueryBuilder()
.setNamespace(NAMESPACE)
@@ -97,7 +97,7 @@ public void testAggregationBuilderWithMultipleAggregationsTogether() {
}
@Test
- public void testAggregationBuilderWithMultipleAggregationsConfiguredThroughConstructor() {
+ void testAggregationBuilderWithMultipleAggregationsConfiguredThroughConstructor() {
AggregationQuery aggregationQuery =
Query.newAggregationQueryBuilder()
.setNamespace(NAMESPACE)
@@ -117,7 +117,7 @@ public void testAggregationBuilderWithMultipleAggregationsConfiguredThroughConst
}
@Test
- public void testAggregationBuilderWithDuplicateAggregations() {
+ void testAggregationBuilderWithDuplicateAggregations() {
AggregationQuery aggregationQueryWithDuplicateCounts =
Query.newAggregationQueryBuilder()
.setNamespace(NAMESPACE)
@@ -149,7 +149,7 @@ public void testAggregationBuilderWithDuplicateAggregations() {
}
@Test
- public void testAggregationQueryBuilderWithoutNamespace() {
+ void testAggregationQueryBuilderWithoutNamespace() {
AggregationQuery aggregationQuery =
Query.newAggregationQueryBuilder()
.addAggregation(count().as("total"))
@@ -164,31 +164,31 @@ public void testAggregationQueryBuilderWithoutNamespace() {
}
@Test
- public void testAggregationQueryBuilderWithoutNestedQuery() {
+ void testAggregationQueryBuilderWithoutNestedQuery() {
assertThrows(
- "Nested query is required for an aggregation query to run",
IllegalArgumentException.class,
() ->
Query.newAggregationQueryBuilder()
.setNamespace(NAMESPACE)
.addAggregation(count().as("total"))
- .build());
+ .build(),
+ "Nested query is required for an aggregation query to run");
}
@Test
- public void testAggregationQueryBuilderWithoutAggregation() {
+ void testAggregationQueryBuilderWithoutAggregation() {
assertThrows(
- "At least one aggregation is required for an aggregation query to run",
IllegalArgumentException.class,
() ->
Query.newAggregationQueryBuilder()
.setNamespace(NAMESPACE)
.over(COMPLETED_TASK_QUERY)
- .build());
+ .build(),
+ "At least one aggregation is required for an aggregation query to run");
}
@Test
- public void testAggregationQueryBuilderWithGqlQuery() {
+ void testAggregationQueryBuilderWithGqlQuery() {
GqlQuery> gqlQuery = Query.newGqlQueryBuilder("SELECT * FROM Task WHERE done = true").build();
AggregationQuery aggregationQuery =
@@ -199,10 +199,10 @@ public void testAggregationQueryBuilderWithGqlQuery() {
}
@Test
- public void testAggregationQueryBuilderWithoutProvidingAnyNestedQuery() {
+ void testAggregationQueryBuilderWithoutProvidingAnyNestedQuery() {
assertThrows(
- "Nested query is required for an aggregation query to run",
IllegalArgumentException.class,
- () -> Query.newAggregationQueryBuilder().setNamespace(NAMESPACE).build());
+ () -> Query.newAggregationQueryBuilder().setNamespace(NAMESPACE).build(),
+ "Nested query is required for an aggregation query to run");
}
}
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AggregationResultTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AggregationResultTest.java
index 84341f9d4..24f6e763c 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AggregationResultTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/AggregationResultTest.java
@@ -16,15 +16,15 @@
package com.google.cloud.datastore;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableMap;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class AggregationResultTest {
+class AggregationResultTest {
@Test
- public void shouldGetLongAggregatedResultValueByAlias() {
+ void shouldGetLongAggregatedResultValueByAlias() {
AggregationResult aggregationResult =
new AggregationResult(
ImmutableMap.of(
@@ -36,7 +36,7 @@ public void shouldGetLongAggregatedResultValueByAlias() {
}
@Test
- public void shouldGetDoubleAggregatedResultValueByAlias() {
+ void shouldGetDoubleAggregatedResultValueByAlias() {
AggregationResult aggregationResult =
new AggregationResult(
ImmutableMap.of(
@@ -48,7 +48,7 @@ public void shouldGetDoubleAggregatedResultValueByAlias() {
}
@Test
- public void shouldGetLongAggregatedResultValueAsDouble() {
+ void shouldGetLongAggregatedResultValueAsDouble() {
AggregationResult aggregationResult =
new AggregationResult(ImmutableMap.of("count", LongValue.of(45)));
@@ -56,7 +56,7 @@ public void shouldGetLongAggregatedResultValueAsDouble() {
}
@Test
- public void shouldGetDoubleAggregatedResultValueAsLong() {
+ void shouldGetDoubleAggregatedResultValueAsLong() {
AggregationResult aggregationResult =
new AggregationResult(ImmutableMap.of("qty_avg", DoubleValue.of(45.9322)));
@@ -64,7 +64,7 @@ public void shouldGetDoubleAggregatedResultValueAsLong() {
}
@Test
- public void shouldThrowRuntimeExceptionOnUnknownTypes() {
+ void shouldThrowRuntimeExceptionOnUnknownTypes() {
AggregationResult aggregationResult =
new AggregationResult(
ImmutableMap.of(
@@ -84,14 +84,14 @@ public void shouldThrowRuntimeExceptionOnUnknownTypes() {
}
@Test
- public void shouldGetDoubleAggregatedResultValueAsNumber() {
+ void shouldGetDoubleAggregatedResultValueAsNumber() {
AggregationResult aggregationResult =
new AggregationResult(ImmutableMap.of("qty_avg", DoubleValue.of(45.9322)));
assertThat(aggregationResult.getNumber("qty_avg")).isEqualTo(45.9322);
}
@Test
- public void shouldGetLongAggregatedResultValueAsNumber() {
+ void shouldGetLongAggregatedResultValueAsNumber() {
AggregationResult aggregationResult =
new AggregationResult(ImmutableMap.of("count", LongValue.of(50)));
assertThat(aggregationResult.getNumber("count")).isEqualTo(50);
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseDatastoreBatchWriterTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseDatastoreBatchWriterTest.java
index 6c8d7c057..54e001a0f 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseDatastoreBatchWriterTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseDatastoreBatchWriterTest.java
@@ -19,17 +19,18 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList;
import java.util.LinkedList;
import java.util.List;
import org.easymock.EasyMock;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class BaseDatastoreBatchWriterTest {
+class BaseDatastoreBatchWriterTest {
private static final Key KEY1 = Key.newBuilder("dataset1", "kind1", "name1").build();
private static final Key KEY2 = Key.newBuilder(KEY1, 1).build();
@@ -68,18 +69,18 @@ void finish() {
}
}
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
batchWriter = new DatastoreBatchWriter();
}
- @After
- public void tearDown() {
+ @AfterEach
+ void tearDown() {
batchWriter.finish();
}
@Test
- public void testAdd() {
+ void testAdd() {
Entity entity2 =
Entity.newBuilder(ENTITY2).setKey(Key.newBuilder(KEY1).setName("name2").build()).build();
List pbs = new LinkedList<>();
@@ -103,7 +104,7 @@ public void testAdd() {
}
@Test
- public void testAddAfterDelete() {
+ void testAddAfterDelete() {
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY1.toPb()).build());
batchWriter.delete(KEY1);
@@ -111,32 +112,48 @@ public void testAddAfterDelete() {
assertEquals(pbs, batchWriter.toMutationPbList());
}
- @Test(expected = DatastoreException.class)
- public void testAddDuplicate() {
- batchWriter.add(ENTITY1);
- batchWriter.add(ENTITY1);
+ @Test
+ void testAddDuplicate() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ batchWriter.add(ENTITY1);
+ batchWriter.add(ENTITY1);
+ });
}
- @Test(expected = DatastoreException.class)
- public void testAddAfterPut() {
- batchWriter.put(ENTITY1);
- batchWriter.add(ENTITY1);
+ @Test
+ void testAddAfterPut() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ batchWriter.put(ENTITY1);
+ batchWriter.add(ENTITY1);
+ });
}
- @Test(expected = DatastoreException.class)
- public void testAddAfterUpdate() {
- batchWriter.update(ENTITY1);
- batchWriter.add(ENTITY1);
+ @Test
+ void testAddAfterUpdate() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ batchWriter.update(ENTITY1);
+ batchWriter.add(ENTITY1);
+ });
}
- @Test(expected = DatastoreException.class)
- public void testAddWhenNotActive() {
- batchWriter.deactivate();
- batchWriter.add(ENTITY1);
+ @Test
+ void testAddWhenNotActive() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ batchWriter.deactivate();
+ batchWriter.add(ENTITY1);
+ });
}
@Test
- public void testAddWithDeferredAllocation() {
+ void testAddWithDeferredAllocation() {
List pbs = new LinkedList<>();
pbs.add(
com.google.datastore.v1.Mutation.newBuilder()
@@ -152,14 +169,18 @@ public void testAddWithDeferredAllocation() {
assertEquals(pbs, batchWriter.toMutationPbList());
}
- @Test(expected = DatastoreException.class)
- public void testAddWithDeferredAllocationWhenNotActive() {
- batchWriter.deactivate();
- batchWriter.addWithDeferredIdAllocation(INCOMPLETE_ENTITY_1);
+ @Test
+ void testAddWithDeferredAllocationWhenNotActive() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ batchWriter.deactivate();
+ batchWriter.addWithDeferredIdAllocation(INCOMPLETE_ENTITY_1);
+ });
}
@Test
- public void testUpdate() {
+ void testUpdate() {
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpdate(ENTITY1.toPb()).build());
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpdate(ENTITY2.toPb()).build());
@@ -170,7 +191,7 @@ public void testUpdate() {
}
@Test
- public void testUpdateAfterUpdate() {
+ void testUpdateAfterUpdate() {
Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpdate(entity.toPb()).build());
@@ -180,7 +201,7 @@ public void testUpdateAfterUpdate() {
}
@Test
- public void testUpdateAfterAdd() {
+ void testUpdateAfterAdd() {
Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
@@ -190,7 +211,7 @@ public void testUpdateAfterAdd() {
}
@Test
- public void testUpdateAfterPut() {
+ void testUpdateAfterPut() {
Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
@@ -199,20 +220,28 @@ public void testUpdateAfterPut() {
assertEquals(pbs, batchWriter.toMutationPbList());
}
- @Test(expected = DatastoreException.class)
- public void testUpdateAfterDelete() {
- batchWriter.delete(KEY1);
- batchWriter.update(ENTITY1, ENTITY2);
+ @Test
+ void testUpdateAfterDelete() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ batchWriter.delete(KEY1);
+ batchWriter.update(ENTITY1, ENTITY2);
+ });
}
- @Test(expected = DatastoreException.class)
- public void testUpdateWhenNotActive() {
- batchWriter.deactivate();
- batchWriter.update(ENTITY1);
+ @Test
+ void testUpdateWhenNotActive() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ batchWriter.deactivate();
+ batchWriter.update(ENTITY1);
+ });
}
@Test
- public void testPut() {
+ void testPut() {
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY1.toPb()).build());
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY2.toPb()).build());
@@ -226,7 +255,7 @@ public void testPut() {
}
@Test
- public void testPutIncompleteKey() {
+ void testPutIncompleteKey() {
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY1.toPb()).build());
pbs.add(
@@ -246,7 +275,7 @@ public void testPutIncompleteKey() {
}
@Test
- public void testPutWithDeferredAllocation() {
+ void testPutWithDeferredAllocation() {
List pbs = new LinkedList<>();
pbs.add(
com.google.datastore.v1.Mutation.newBuilder()
@@ -263,7 +292,7 @@ public void testPutWithDeferredAllocation() {
}
@Test
- public void testPutAfterPut() {
+ void testPutAfterPut() {
Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
@@ -275,7 +304,7 @@ public void testPutAfterPut() {
}
@Test
- public void testPutAfterAdd() {
+ void testPutAfterAdd() {
Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
@@ -285,7 +314,7 @@ public void testPutAfterAdd() {
}
@Test
- public void testPutAfterUpdate() {
+ void testPutAfterUpdate() {
Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
@@ -296,7 +325,7 @@ public void testPutAfterUpdate() {
}
@Test
- public void testPutAfterDelete() {
+ void testPutAfterDelete() {
Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
@@ -306,14 +335,18 @@ public void testPutAfterDelete() {
assertEquals(pbs, batchWriter.toMutationPbList());
}
- @Test(expected = DatastoreException.class)
- public void testPutWhenNotActive() {
- batchWriter.deactivate();
- batchWriter.put(ENTITY1);
+ @Test
+ void testPutWhenNotActive() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ batchWriter.deactivate();
+ batchWriter.put(ENTITY1);
+ });
}
@Test
- public void testDelete() {
+ void testDelete() {
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setDelete(KEY1.toPb()).build());
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setDelete(KEY2.toPb()).build());
@@ -324,7 +357,7 @@ public void testDelete() {
}
@Test
- public void testDeleteAfterAdd() {
+ void testDeleteAfterAdd() {
List pbs = new LinkedList<>();
pbs.add(
com.google.datastore.v1.Mutation.newBuilder()
@@ -338,7 +371,7 @@ public void testDeleteAfterAdd() {
}
@Test
- public void testDeleteAfterUpdate() {
+ void testDeleteAfterUpdate() {
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setDelete(KEY1.toPb()).build());
batchWriter.update(ENTITY1);
@@ -347,7 +380,7 @@ public void testDeleteAfterUpdate() {
}
@Test
- public void testDeleteAfterPut() {
+ void testDeleteAfterPut() {
List pbs = new LinkedList<>();
pbs.add(com.google.datastore.v1.Mutation.newBuilder().setDelete(KEY1.toPb()).build());
batchWriter.put(ENTITY1);
@@ -355,9 +388,13 @@ public void testDeleteAfterPut() {
assertEquals(pbs, batchWriter.toMutationPbList());
}
- @Test(expected = DatastoreException.class)
- public void testDeleteWhenNotActive() {
- batchWriter.deactivate();
- batchWriter.delete(KEY1);
+ @Test
+ void testDeleteWhenNotActive() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ batchWriter.deactivate();
+ batchWriter.delete(KEY1);
+ });
}
}
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseEntityTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseEntityTest.java
index 1b5380ab9..b4bd18c66 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseEntityTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseEntityTest.java
@@ -16,9 +16,10 @@
package com.google.cloud.datastore;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.cloud.Timestamp;
import com.google.common.collect.ImmutableList;
@@ -27,10 +28,10 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class BaseEntityTest {
+class BaseEntityTest {
private static final Blob BLOB = Blob.copyFrom(new byte[] {1, 2});
private static final Timestamp TIMESTAMP = Timestamp.now();
@@ -52,8 +53,8 @@ public BaseEntity build() {
}
}
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
builder = new Builder();
builder.set("blob", BLOB).set("boolean", true).set("timestamp", TIMESTAMP);
builder.set("double", 1.25).set("key", KEY).set("string", "hello world");
@@ -79,7 +80,7 @@ public void setUp() {
}
@Test
- public void testContains() {
+ void testContains() {
BaseEntity entity = builder.build();
assertTrue(entity.contains("list1"));
assertFalse(entity.contains("bla"));
@@ -88,19 +89,23 @@ public void testContains() {
}
@Test
- public void testGetValue() {
+ void testGetValue() {
BaseEntity entity = builder.build();
assertEquals(BlobValue.of(BLOB), entity.getValue("blob"));
}
- @Test(expected = DatastoreException.class)
- public void testGetValueNotFound() {
- BaseEntity entity = builder.clear().build();
- entity.getValue("blob");
+ @Test
+ void testGetValueNotFound() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ BaseEntity entity = builder.clear().build();
+ entity.getValue("blob");
+ });
}
@Test
- public void testIsNull() {
+ void testIsNull() {
BaseEntity entity = builder.build();
assertTrue(entity.isNull("null"));
assertFalse(entity.isNull("blob"));
@@ -108,14 +113,18 @@ public void testIsNull() {
assertTrue(entity.isNull("blob"));
}
- @Test(expected = DatastoreException.class)
- public void testIsNullNotFound() {
- BaseEntity entity = builder.clear().build();
- entity.isNull("null");
+ @Test
+ void testIsNullNotFound() {
+ assertThrows(
+ DatastoreException.class,
+ () -> {
+ BaseEntity entity = builder.clear().build();
+ entity.isNull("null");
+ });
}
@Test
- public void testGetString() {
+ void testGetString() {
BaseEntity entity = builder.build();
assertEquals("hello world", entity.getString("string"));
assertEquals("bla", entity.getString("stringValue"));
@@ -124,7 +133,7 @@ public void testGetString() {
}
@Test
- public void testGetLong() {
+ void testGetLong() {
BaseEntity entity = builder.build();
assertEquals(125, entity.getLong("long"));
entity = builder.set("long", LongValue.of(10)).build();
@@ -132,7 +141,7 @@ public void testGetLong() {
}
@Test
- public void testGetDouble() {
+ void testGetDouble() {
BaseEntity entity = builder.build();
assertEquals(1.25, entity.getDouble("double"), 0);
entity = builder.set("double", DoubleValue.of(10)).build();
@@ -140,7 +149,7 @@ public void testGetDouble() {
}
@Test
- public void testGetBoolean() throws Exception {
+ void testGetBoolean() throws Exception {
BaseEntity entity = builder.build();
assertTrue(entity.getBoolean("boolean"));
entity = builder.set("boolean", BooleanValue.of(false)).build();
@@ -148,7 +157,7 @@ public void testGetBoolean() throws Exception {
}
@Test
- public void testGetTimestamp() {
+ void testGetTimestamp() {
BaseEntity entity = builder.build();
assertEquals(TIMESTAMP, entity.getTimestamp("timestamp"));
Calendar cal = Calendar.getInstance();
@@ -159,13 +168,13 @@ public void testGetTimestamp() {
}
@Test
- public void testGetLatLng() {
+ void testGetLatLng() {
BaseEntity entity = builder.build();
assertEquals(LAT_LNG, entity.getLatLng("latLng"));
}
@Test
- public void testGetKey() {
+ void testGetKey() {
BaseEntity entity = builder.build();
assertEquals(KEY, entity.getKey("key"));
Key key = Key.newBuilder(KEY).setName("BLA").build();
@@ -174,7 +183,7 @@ public void testGetKey() {
}
@Test
- public void testGetEntity() {
+ void testGetEntity() {
BaseEntity entity = builder.build();
assertEquals(ENTITY, entity.getEntity("entity"));
assertEquals(PARTIAL_ENTITY, entity.getEntity("partialEntity"));
@@ -183,7 +192,7 @@ public void testGetEntity() {
}
@Test
- public void testGetList() {
+ void testGetList() {
BaseEntity entity = builder.build();
List extends Value>> list = entity.getList("list1");
assertEquals(3, list.size());
@@ -213,7 +222,7 @@ public void testGetList() {
}
@Test
- public void testGetBlob() {
+ void testGetBlob() {
BaseEntity entity = builder.build();
assertEquals(BLOB, entity.getBlob("blob"));
Blob blob = Blob.copyFrom(new byte[] {});
@@ -222,7 +231,7 @@ public void testGetBlob() {
}
@Test
- public void testNames() {
+ void testNames() {
Set names =
ImmutableSet.builder()
.add("string", "stringValue", "boolean", "double", "long", "list1", "list2", "list3")
@@ -236,7 +245,7 @@ public void testNames() {
}
@Test
- public void testKey() {
+ void testKey() {
builder.setKey(KEY);
BaseEntity entity = builder.build();
assertEquals(KEY, entity.getKey());
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseKeyTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseKeyTest.java
index 08b65bdc7..b68ce7b1a 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseKeyTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseKeyTest.java
@@ -16,15 +16,16 @@
package com.google.cloud.datastore;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class BaseKeyTest {
+class BaseKeyTest {
private class Builder extends BaseKey.Builder {
@@ -56,7 +57,7 @@ protected BaseKey getParent() {
}
@Test
- public void testProjectId() {
+ void testProjectId() {
Builder builder = new Builder("ds1", "k");
BaseKey key = builder.build();
assertEquals("ds1", key.getProjectId());
@@ -66,7 +67,7 @@ public void testProjectId() {
}
@Test
- public void testDatabaseId() {
+ void testDatabaseId() {
Builder builder = new Builder("ds1", "k").setDatabaseId("test-db");
BaseKey key = builder.build();
assertEquals("ds1", key.getProjectId());
@@ -75,19 +76,23 @@ public void testDatabaseId() {
assertEquals("test-db", key.getDatabaseId());
}
- @Test(expected = IllegalArgumentException.class)
- public void testBadDatasetInConstructor() {
- new Builder(" ", "k");
+ @Test
+ void testBadDatasetInConstructor() {
+ assertThrows(IllegalArgumentException.class, () -> new Builder(" ", "k"));
}
- @Test(expected = IllegalArgumentException.class)
- public void testBadDatasetInSetter() {
- Builder builder = new Builder("d", "k");
- builder.setProjectId(" ");
+ @Test
+ void testBadDatasetInSetter() {
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ Builder builder = new Builder("d", "k");
+ builder.setProjectId(" ");
+ });
}
@Test
- public void testNamespace() {
+ void testNamespace() {
Builder builder = new Builder("ds", "k");
BaseKey key = builder.build();
assertTrue(key.getNamespace() != null);
@@ -97,7 +102,7 @@ public void testNamespace() {
}
@Test
- public void testKind() {
+ void testKind() {
Builder builder = new Builder("ds", "k1");
BaseKey key = builder.build();
assertEquals("k1", key.getKind());
@@ -105,25 +110,33 @@ public void testKind() {
assertEquals("k2", key.getKind());
}
- @Test(expected = NullPointerException.class)
- public void testNoKind() throws Exception {
- Builder builder = new Builder("ds");
- builder.build();
+ @Test
+ void testNoKind() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> {
+ Builder builder = new Builder("ds");
+ builder.build();
+ });
}
- @Test(expected = IllegalArgumentException.class)
- public void testBadKindInConstructor() throws Exception {
- new Builder("ds", "");
+ @Test
+ void testBadKindInConstructor() throws Exception {
+ assertThrows(IllegalArgumentException.class, () -> new Builder("ds", ""));
}
- @Test(expected = IllegalArgumentException.class)
- public void testBadKindInSetter() throws Exception {
- Builder builder = new Builder("ds", "k1");
- builder.setKind("");
+ @Test
+ void testBadKindInSetter() throws Exception {
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ Builder builder = new Builder("ds", "k1");
+ builder.setKind("");
+ });
}
@Test
- public void testAncestors() throws Exception {
+ void testAncestors() throws Exception {
Builder builder = new Builder("ds", "k");
BaseKey key = builder.build();
assertTrue(key.getAncestors().isEmpty());
@@ -137,7 +150,7 @@ public void testAncestors() throws Exception {
}
@Test
- public void testCopyFrom() {
+ void testCopyFrom() {
Builder copyFrom = new Builder("test-project", "kind").setDatabaseId("test-db");
Builder builder = new Builder(copyFrom.build());
BaseKey baseKey = builder.build();
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobTest.java
index 391f6f765..071a4520d 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobTest.java
@@ -16,28 +16,28 @@
package com.google.cloud.datastore;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import com.google.common.testing.EqualsTester;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Random;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class BlobTest {
+class BlobTest {
private static final byte[] bytes1 = new byte[10];
private static final byte[] bytes2 = new byte[11];
private Blob blob1;
private Blob blob2;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
Random rnd = new Random();
rnd.nextBytes(bytes1);
rnd.nextBytes(bytes2);
@@ -46,7 +46,7 @@ public void setUp() {
}
@Test
- public void testEquals() {
+ void testEquals() {
EqualsTester equalsTester = new EqualsTester();
equalsTester.addEqualityGroup(blob1, blob1).testEquals();
assertEquals(blob1, Blob.copyFrom(bytes1));
@@ -54,19 +54,19 @@ public void testEquals() {
}
@Test
- public void testLength() {
+ void testLength() {
assertEquals(bytes1.length, blob1.getLength());
assertEquals(bytes2.length, blob2.getLength());
}
@Test
- public void testToByteArray() {
+ void testToByteArray() {
assertArrayEquals(bytes1, blob1.toByteArray());
assertArrayEquals(bytes2, blob2.toByteArray());
}
@Test
- public void testAsReadOnlyByteBuffer() {
+ void testAsReadOnlyByteBuffer() {
ByteBuffer buffer = blob1.asReadOnlyByteBuffer();
byte[] bytes = new byte[bytes1.length];
buffer.get(bytes);
@@ -75,7 +75,7 @@ public void testAsReadOnlyByteBuffer() {
}
@Test
- public void testAsInputStream() throws Exception {
+ void testAsInputStream() throws Exception {
byte[] bytes = new byte[bytes1.length];
InputStream in = blob1.asInputStream();
assertEquals(bytes1.length, in.read(bytes));
@@ -84,7 +84,7 @@ public void testAsInputStream() throws Exception {
}
@Test
- public void testCopyTo() {
+ void testCopyTo() {
byte[] bytes = new byte[bytes1.length];
blob1.copyTo(bytes);
assertArrayEquals(bytes1, bytes);
@@ -99,7 +99,7 @@ public void testCopyTo() {
}
@Test
- public void testCopyFrom() throws Exception {
+ void testCopyFrom() throws Exception {
Blob blob = Blob.copyFrom(ByteBuffer.wrap(bytes1));
assertEquals(blob1, blob);
assertArrayEquals(bytes1, blob.toByteArray());
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobValueTest.java
index 7bad94293..0c73b0381 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobValueTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobValueTest.java
@@ -16,24 +16,24 @@
package com.google.cloud.datastore;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class BlobValueTest {
+class BlobValueTest {
private static final Blob CONTENT = Blob.copyFrom(new byte[] {1, 2});
@Test
- public void testToBuilder() {
+ void testToBuilder() {
BlobValue value = BlobValue.of(CONTENT);
assertEquals(value, value.toBuilder().build());
}
@Test
- public void testOf() {
+ void testOf() {
BlobValue value = BlobValue.of(CONTENT);
assertEquals(CONTENT, value.get());
assertFalse(value.excludeFromIndexes());
@@ -41,7 +41,7 @@ public void testOf() {
@SuppressWarnings("deprecation")
@Test
- public void testBuilder() {
+ void testBuilder() {
BlobValue.Builder builder = BlobValue.newBuilder(CONTENT);
BlobValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build();
assertEquals(CONTENT, value.get());
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BooleanValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BooleanValueTest.java
index 579c17748..e7a265fc4 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BooleanValueTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BooleanValueTest.java
@@ -16,22 +16,22 @@
package com.google.cloud.datastore;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class BooleanValueTest {
+class BooleanValueTest {
@Test
- public void testToBuilder() {
+ void testToBuilder() {
BooleanValue value = BooleanValue.of(true);
assertEquals(value, value.toBuilder().build());
}
@Test
- public void testOf() {
+ void testOf() {
BooleanValue value = BooleanValue.of(false);
assertFalse(value.get());
assertFalse(value.excludeFromIndexes());
@@ -39,7 +39,7 @@ public void testOf() {
@SuppressWarnings("deprecation")
@Test
- public void testBuilder() {
+ void testBuilder() {
BooleanValue.Builder builder = BooleanValue.newBuilder(true);
BooleanValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build();
assertTrue(value.get());
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/CursorTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/CursorTest.java
index 4a3c3542d..8a9ebadab 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/CursorTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/CursorTest.java
@@ -16,34 +16,34 @@
package com.google.cloud.datastore;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import com.google.protobuf.ByteString;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class CursorTest {
+class CursorTest {
private static final byte[] bytes1 = {1, 2, 3, '%', '<', '+'};
private static final byte[] bytes2 = {10, 20, 30};
private Cursor cursor1;
private Cursor cursor2;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
cursor1 = new Cursor(ByteString.copyFrom(bytes1));
cursor2 = new Cursor(ByteString.copyFrom(bytes2));
}
@Test
- public void testToFromUrlSafe() {
+ void testToFromUrlSafe() {
String urlSafe = cursor1.toUrlSafe();
assertEquals(cursor1, Cursor.fromUrlSafe(urlSafe));
}
@Test
- public void testCopyFrom() {
+ void testCopyFrom() {
Cursor cursor = Cursor.copyFrom(bytes2);
assertEquals(cursor2, cursor);
assertNotEquals(cursor1, cursor);
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreExceptionTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreExceptionTest.java
index 8c52b5519..bf71518b9 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreExceptionTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreExceptionTest.java
@@ -20,23 +20,23 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.cloud.BaseServiceException;
import com.google.cloud.RetryHelper;
import java.io.IOException;
import java.net.SocketTimeoutException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class DatastoreExceptionTest {
+class DatastoreExceptionTest {
@Test
- public void testDatastoreException() {
+ void testDatastoreException() {
DatastoreException exception = new DatastoreException(10, "message", "ABORTED");
assertEquals(10, exception.getCode());
assertEquals("ABORTED", exception.getReason());
@@ -79,7 +79,7 @@ public void testDatastoreException() {
}
@Test
- public void testTranslateAndThrow() {
+ void testTranslateAndThrow() {
Exception cause = new DatastoreException(14, "message", "UNAVAILABLE");
RetryHelper.RetryHelperException exceptionMock =
createMock(RetryHelper.RetryHelperException.class);
@@ -112,13 +112,12 @@ public void testTranslateAndThrow() {
}
@Test
- public void testThrowInvalidRequest() {
- try {
- DatastoreException.throwInvalidRequest("message %s %d", "a", 1);
- fail("Exception expected");
- } catch (DatastoreException ex) {
- assertEquals("FAILED_PRECONDITION", ex.getReason());
- assertEquals("message a 1", ex.getMessage());
- }
+ void testThrowInvalidRequest() {
+ DatastoreException exception =
+ assertThrows(
+ DatastoreException.class,
+ () -> DatastoreException.throwInvalidRequest("message %s %d", "a", 1));
+ assertEquals("FAILED_PRECONDITION", exception.getReason());
+ assertEquals("message a 1", exception.getMessage());
}
}
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreHelperTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreHelperTest.java
index 010a892ae..b965cda90 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreHelperTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreHelperTest.java
@@ -21,19 +21,19 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;
import java.util.Collections;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class DatastoreHelperTest {
+class DatastoreHelperTest {
@Test
- public void testNewKeyFactory() {
+ void testNewKeyFactory() {
DatastoreOptions options = createMock(DatastoreOptions.class);
expect(options.getProjectId()).andReturn("ds1").once();
expect(options.getNamespace()).andReturn("ns1").once();
@@ -50,7 +50,7 @@ public void testNewKeyFactory() {
}
@Test
- public void testAllocateId() {
+ void testAllocateId() {
Datastore datastore = createStrictMock(Datastore.class);
IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build();
Key key1 = Key.newBuilder(pKey1, 1).build();
@@ -62,7 +62,7 @@ public void testAllocateId() {
}
@Test
- public void testGetWithDatastore() throws Exception {
+ void testGetWithDatastore() throws Exception {
Datastore datastore = createStrictMock(Datastore.class);
IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build();
Key key1 = Key.newBuilder(pKey1, 1).build();
@@ -83,7 +83,7 @@ public void testGetWithDatastore() throws Exception {
}
@Test
- public void testGetWithTransaction() throws Exception {
+ void testGetWithTransaction() throws Exception {
Transaction transaction = createStrictMock(Transaction.class);
IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build();
Key key1 = Key.newBuilder(pKey1, 1).build();
@@ -99,7 +99,7 @@ public void testGetWithTransaction() throws Exception {
}
@Test
- public void testAdd() throws Exception {
+ void testAdd() throws Exception {
Datastore datastore = createStrictMock(Datastore.class);
IncompleteKey pKey = IncompleteKey.newBuilder("ds", "k").build();
Key key = Key.newBuilder(pKey, 1).build();
@@ -111,7 +111,7 @@ public void testAdd() throws Exception {
}
@Test
- public void testFetchWithDatastore() throws Exception {
+ void testFetchWithDatastore() throws Exception {
Datastore datastore = createStrictMock(Datastore.class);
IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build();
Key key1 = Key.newBuilder(pKey1, 1).build();
@@ -138,7 +138,7 @@ public void testFetchWithDatastore() throws Exception {
}
@Test
- public void testFetchWithTransaction() throws Exception {
+ void testFetchWithTransaction() throws Exception {
Transaction transaction = createStrictMock(Transaction.class);
IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build();
Key key1 = Key.newBuilder(pKey1, 1).build();
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java
index 0c25c3b6c..4dcd3bd6d 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java
@@ -17,10 +17,10 @@
package com.google.cloud.datastore;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.api.gax.grpc.ChannelPoolSettings;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
@@ -32,11 +32,10 @@
import com.google.cloud.http.HttpTransportOptions;
import com.google.datastore.v1.client.DatastoreFactory;
import org.easymock.EasyMock;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class DatastoreOptionsTest {
+class DatastoreOptionsTest {
private static final String PROJECT_ID = "project-id";
private static final String DATABASE_ID = "database-id";
@@ -46,8 +45,8 @@ public class DatastoreOptionsTest {
private DatastoreRpc datastoreRpc;
private DatastoreOptions.Builder options;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
datastoreRpcFactory = EasyMock.createMock(DatastoreRpcFactory.class);
datastoreRpc = EasyMock.createMock(DatastoreRpc.class);
options =
@@ -65,47 +64,47 @@ public void setUp() {
}
@Test
- public void testProjectId() {
+ void testProjectId() {
assertEquals(PROJECT_ID, options.build().getProjectId());
}
@Test
- public void testDatabaseId() {
+ void testDatabaseId() {
assertEquals(DATABASE_ID, options.build().getDatabaseId());
}
@Test
- public void testHost() {
+ void testHost() {
assertEquals("http://localhost:" + PORT, options.build().getHost());
}
@Test
- public void testOpenTelemetryOptionsEnabled() {
+ void testOpenTelemetryOptionsEnabled() {
options.setOpenTelemetryOptions(
DatastoreOpenTelemetryOptions.newBuilder().setTracingEnabled(true).build());
assertTrue(options.build().getOpenTelemetryOptions().isEnabled());
}
@Test
- public void testOpenTelemetryOptionsDisabled() {
+ void testOpenTelemetryOptionsDisabled() {
options.setOpenTelemetryOptions(
DatastoreOpenTelemetryOptions.newBuilder().setTracingEnabled(false).build());
assertTrue(!options.build().getOpenTelemetryOptions().isEnabled());
}
@Test
- public void testNamespace() {
+ void testNamespace() {
assertTrue(options.build().getNamespace().isEmpty());
assertEquals("ns1", options.setNamespace("ns1").build().getNamespace());
}
@Test
- public void testDatastore() {
+ void testDatastore() {
assertSame(datastoreRpc, options.build().getRpc());
}
@Test
- public void testGrpcDefaultChannelConfigurations() {
+ void testGrpcDefaultChannelConfigurations() {
DatastoreOptions datastoreOptions =
DatastoreOptions.newBuilder()
.setServiceRpcFactory(datastoreRpcFactory)
@@ -124,7 +123,7 @@ public void testGrpcDefaultChannelConfigurations() {
}
@Test
- public void testCustomChannelAndCredentials() {
+ void testCustomChannelAndCredentials() {
InstantiatingGrpcChannelProvider channelProvider =
DatastoreSettings.defaultGrpcTransportProviderBuilder()
.setChannelPoolSettings(
@@ -147,7 +146,7 @@ public void testCustomChannelAndCredentials() {
}
@Test
- public void testInvalidConfigForHttp() {
+ void testInvalidConfigForHttp() {
DatastoreOptions.Builder options =
DatastoreOptions.newBuilder()
.setServiceRpcFactory(datastoreRpcFactory)
@@ -164,11 +163,11 @@ public void testInvalidConfigForHttp() {
.build())
.setCredentials(NoCredentials.getInstance())
.setHost("http://localhost:" + PORT);
- Assert.assertThrows(IllegalArgumentException.class, options::build);
+ org.junit.jupiter.api.Assertions.assertThrows(IllegalArgumentException.class, options::build);
}
@Test
- public void testTransport() {
+ void testTransport() {
// default http transport
assertThat(options.build().getTransportOptions()).isInstanceOf(HttpTransportOptions.class);
@@ -185,7 +184,7 @@ public void testTransport() {
}
@Test
- public void testHostWithGrpcAndHttp() {
+ void testHostWithGrpcAndHttp() {
DatastoreOptions grpcTransportOptions =
DatastoreOptions.newBuilder()
.setTransportOptions(GrpcTransportOptions.newBuilder().build())
@@ -222,7 +221,7 @@ public void testHostWithGrpcAndHttp() {
}
@Test
- public void testToBuilder() {
+ void testToBuilder() {
DatastoreOptions original = options.setNamespace("ns1").build();
DatastoreOptions copy = original.toBuilder().build();
assertEquals(original.getProjectId(), copy.getProjectId());
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTestGrpc.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTestGrpc.java
index cb242f2af..1dc5cb891 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTestGrpc.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTestGrpc.java
@@ -21,14 +21,10 @@
import com.google.common.truth.Truth;
import java.io.IOException;
import java.time.Duration;
-import java.util.Arrays;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
-@RunWith(Parameterized.class)
-public class DatastoreTestGrpc extends AbstractDatastoreTest {
+class DatastoreTestGrpc extends AbstractDatastoreTest {
private static final LocalDatastoreHelper helper = LocalDatastoreHelper.create(1.0, 9090);
@@ -36,24 +32,15 @@ public class DatastoreTestGrpc extends AbstractDatastoreTest {
helper.getGrpcTransportOptions(GrpcTransportOptions.newBuilder().build());
private static Datastore datastore = options.getService();
- public DatastoreTestGrpc(DatastoreOptions options, Datastore datastore) {
- super(options, datastore);
- }
-
- @Parameterized.Parameters(name = "data options: {0}")
- public static Iterable
+
-
- junit
- junit
- 4.13.2
- test
-
org.easymock
easymock
@@ -219,6 +214,14 @@
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ plain
+ false
+
+
org.apache.maven.plugins
maven-dependency-plugin
@@ -227,11 +230,41 @@
com.google.http-client:google-http-client-jackson2
com.google.oauth-client:google-oauth-client
javax.annotation:javax.annotation-api
+
+ org.junit.jupiter:junit-jupiter-engine
+
+ org.junit.vintage:junit-vintage-engine
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
+
+
+
+ package
+ false
+
+
+
+
+ attach-javadocs
+
+ jar
+
+
+
+ protected
+
+
+
+
+