executorFactory = new DefaultExecutorFactory();
ScheduledExecutorService executorService = executorFactory.get();
assertSame(executorService, executorFactory.get());
diff --git a/java-core/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/SharedResourceHolderTest.java b/java-core/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/SharedResourceHolderTest.java
index ba70a0de55..3e1ceee9ef 100644
--- a/java-core/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/SharedResourceHolderTest.java
+++ b/java-core/google-cloud-core-grpc/src/test/java/com/google/cloud/grpc/SharedResourceHolderTest.java
@@ -16,8 +16,19 @@
package com.google.cloud.grpc;
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.LinkedList;
import java.util.concurrent.Delayed;
@@ -26,20 +37,17 @@
import java.util.concurrent.TimeUnit;
import org.easymock.EasyMock;
import org.easymock.IAnswer;
-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;
/**
* This class was copied from grpc-core to prevent dependence on an unstable API that may be subject
- * to changes
- * (https://github.com/grpc/grpc-java/blob/d07ecbe037d2705a1c9f4b6345581f860e505b56/core/src/test/java/io/grpc/internal/SharedResourceHolderTest.java)
+ * to changes (SharedResourceHolderTest)
*
* Unit tests for {@link SharedResourceHolder}.
*/
-@RunWith(JUnit4.class)
-public class SharedResourceHolderTest {
+class SharedResourceHolderTest {
private final LinkedList> scheduledDestroyTasks = new LinkedList<>();
@@ -67,13 +75,13 @@ public void close(ResourceInstance instance) {
private static final SharedResourceHolder.Resource SHARED_BAR =
new ResourceFactory();
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
holder = new SharedResourceHolder(new MockExecutorFactory());
}
@Test
- public void destroyResourceWhenRefCountReachesZero() {
+ void destroyResourceWhenRefCountReachesZero() {
ResourceInstance foo1 = holder.getInternal(SHARED_FOO);
ResourceInstance sharedFoo = foo1;
ResourceInstance foo2 = holder.getInternal(SHARED_FOO);
@@ -121,7 +129,7 @@ public void destroyResourceWhenRefCountReachesZero() {
}
@Test
- public void cancelDestroyTask() {
+ void cancelDestroyTask() {
ResourceInstance foo1 = holder.getInternal(SHARED_FOO);
ResourceInstance sharedFoo = foo1;
holder.releaseInternal(SHARED_FOO, foo1);
@@ -148,7 +156,7 @@ public void cancelDestroyTask() {
}
@Test
- public void releaseWrongInstance() {
+ void releaseWrongInstance() {
ResourceInstance uncached = new ResourceInstance();
try {
holder.releaseInternal(SHARED_FOO, uncached);
@@ -167,7 +175,7 @@ public void releaseWrongInstance() {
}
@Test
- public void overreleaseInstance() {
+ void overreleaseInstance() {
ResourceInstance foo1 = holder.getInternal(SHARED_FOO);
holder.releaseInternal(SHARED_FOO, foo1);
try {
@@ -179,7 +187,7 @@ public void overreleaseInstance() {
}
@Test
- public void handleInstanceCloseError() {
+ void handleInstanceCloseError() {
class ExceptionOnCloseResource implements SharedResourceHolder.Resource {
@Override
public ResourceInstance create() {
diff --git a/java-core/google-cloud-core-http/pom.xml b/java-core/google-cloud-core-http/pom.xml
index 4aae033b7c..2dfb7936a7 100644
--- a/java-core/google-cloud-core-http/pom.xml
+++ b/java-core/google-cloud-core-http/pom.xml
@@ -77,8 +77,18 @@
- junit
- junit
+ org.junit.platform
+ junit-platform-launcher
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+ org.junit.vintage
+ junit-vintage-engine
test
diff --git a/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java b/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java
index e88a32a9af..885cb7511d 100644
--- a/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java
+++ b/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/BaseHttpServiceExceptionTest.java
@@ -21,10 +21,10 @@
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.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 com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.cloud.BaseServiceException;
@@ -35,9 +35,9 @@
import java.net.SocketTimeoutException;
import java.util.Collections;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class BaseHttpServiceExceptionTest {
+class BaseHttpServiceExceptionTest {
private static final int CODE = 1;
private static final int CODE_NO_REASON = 2;
@@ -53,7 +53,7 @@ private static class CustomServiceException extends BaseHttpServiceException {
private static final long serialVersionUID = -195251309124875103L;
- public CustomServiceException(int code, String message, String reason, boolean idempotent) {
+ CustomServiceException(int code, String message, String reason, boolean idempotent) {
super(code, message, reason, idempotent, RETRYABLE_ERRORS);
}
@@ -63,7 +63,7 @@ public CustomServiceException(int code, String message, String reason, boolean i
}
@Test
- public void testBaseServiceException() {
+ void testBaseServiceException() {
BaseServiceException serviceException =
new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS);
assertEquals(CODE, serviceException.getCode());
@@ -145,7 +145,7 @@ public void testBaseServiceException() {
}
@Test
- public void testTranslateAndThrow() throws Exception {
+ void testTranslateAndThrow() throws Exception {
BaseServiceException cause =
new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS);
RetryHelper.RetryHelperException exceptionMock =
diff --git a/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java b/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java
index c04d0647fb..0ac860c820 100644
--- a/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java
+++ b/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/CensusHttpModuleTest.java
@@ -21,6 +21,7 @@
import static org.easymock.EasyMock.createMockBuilder;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpExecuteInterceptor;
@@ -41,25 +42,18 @@
import java.io.IOException;
import java.util.EnumSet;
import java.util.Random;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/** Tests for {@link CensusHttpModule}. */
-@RunWith(JUnit4.class)
-public class CensusHttpModuleTest {
-
- @Rule public final ExpectedException thrown = ExpectedException.none();
+class CensusHttpModuleTest {
private final Tracer tracer = Tracing.getTracer();
private final CensusHttpModule censusHttpModule = new CensusHttpModule(tracer, false);
private HttpRequest httpRequest;
- @Before
- public void setUp() throws IOException {
+ @BeforeEach
+ void setUp() throws IOException {
httpRequest =
new NetHttpTransport()
.createRequestFactory()
@@ -67,23 +61,23 @@ public void setUp() throws IOException {
}
@Test
- public void tracerShouldNotBeNull() {
+ void tracerShouldNotBeNull() {
assertThat(censusHttpModule.getTracer()).isNotNull();
}
@Test
- public void isRecordEventsShouldBeSet() {
+ void isRecordEventsShouldBeSet() {
assertThat(censusHttpModule.isRecordEvents()).isEqualTo(false);
}
@Test
- public void getHttpRequestInitializerShouldReturnCorrectClass() {
+ void getHttpRequestInitializerShouldReturnCorrectClass() {
HttpRequestInitializer initializer = censusHttpModule.getHttpRequestInitializer(null);
assertThat(initializer).isInstanceOf(CensusHttpModule.CensusHttpRequestInitializer.class);
}
@Test
- public void implementationOfDefaultTextFormatSetter() {
+ void implementationOfDefaultTextFormatSetter() {
String testKey = "testKey";
String testValue = "testValue";
TextFormat.Setter setter =
@@ -93,14 +87,13 @@ public void implementationOfDefaultTextFormatSetter() {
}
@Test
- public void censusHttpExecuteInterceptorDisallowNullRequest() throws IOException {
+ void censusHttpExecuteInterceptorDisallowNullRequest() {
HttpExecuteInterceptor interceptor = censusHttpModule.new CensusHttpExecuteInterceptor(null);
- thrown.expect(NullPointerException.class);
- interceptor.intercept(null);
+ assertThrows(NullPointerException.class, () -> interceptor.intercept(null));
}
@Test
- public void censusHttpExecuteInterceptorShouldExecuteOriginal() throws IOException {
+ void censusHttpExecuteInterceptorShouldExecuteOriginal() throws IOException {
HttpExecuteInterceptor mockInterceptor = createMock(HttpExecuteInterceptor.class);
HttpExecuteInterceptor censusInterceptor =
censusHttpModule.new CensusHttpExecuteInterceptor(mockInterceptor);
@@ -111,7 +104,7 @@ public void censusHttpExecuteInterceptorShouldExecuteOriginal() throws IOExcepti
}
@Test
- public void censusHttpExecuteInterceptorShouldInjectHeader() throws IOException {
+ void censusHttpExecuteInterceptorShouldInjectHeader() throws IOException {
Random random = new Random();
SpanContext spanContext =
SpanContext.create(
@@ -135,14 +128,13 @@ public void censusHttpExecuteInterceptorShouldInjectHeader() throws IOException
}
@Test
- public void censusHttpRequestInitializerDisallowNullRequest() throws IOException {
+ void censusHttpRequestInitializerDisallowNullRequest() {
HttpRequestInitializer initializer = censusHttpModule.getHttpRequestInitializer(null);
- thrown.expect(NullPointerException.class);
- initializer.initialize(null);
+ assertThrows(NullPointerException.class, () -> initializer.initialize(null));
}
@Test
- public void censusHttpRequestInitializerShouldExecuteOriginal() throws IOException {
+ void censusHttpRequestInitializerShouldExecuteOriginal() throws IOException {
HttpRequestInitializer mockOriginalInitializer = createMock(HttpRequestInitializer.class);
HttpRequestInitializer censusInitializer =
censusHttpModule.getHttpRequestInitializer(mockOriginalInitializer);
@@ -153,7 +145,7 @@ public void censusHttpRequestInitializerShouldExecuteOriginal() throws IOExcepti
}
@Test
- public void censusHttpRequestInitializerShouldSetInterceptor() throws IOException {
+ void censusHttpRequestInitializerShouldSetInterceptor() throws IOException {
censusHttpModule.getHttpRequestInitializer(null).initialize(httpRequest);
assertThat(httpRequest.getInterceptor())
.isInstanceOf(CensusHttpModule.CensusHttpExecuteInterceptor.class);
diff --git a/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java b/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java
index 75ffc2bf17..1697a0c43f 100644
--- a/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java
+++ b/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java
@@ -16,11 +16,11 @@
package com.google.cloud.http;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
@@ -50,10 +50,10 @@
import java.util.Set;
import java.util.regex.Pattern;
import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class HttpTransportOptionsTest {
+class HttpTransportOptionsTest {
private static final HttpTransport MOCK_HTTP_TRANSPORT =
new MockHttpTransport() {
@Override
@@ -88,8 +88,8 @@ public LowLevelHttpResponse execute() {
private Credentials customCredentials;
private HttpRequest defaultHttpRequest;
- @Before
- public void setup() throws IOException {
+ @BeforeEach
+ void setup() throws IOException {
defaultHeaderProvider = EasyMock.createMock(HeaderProvider.class);
EasyMock.expect(defaultHeaderProvider.getHeaders()).andReturn(new HashMap<>());
@@ -109,7 +109,7 @@ public void setup() throws IOException {
}
@Test
- public void testBuilder() {
+ void testBuilder() {
assertEquals(1234, OPTIONS.getConnectTimeout());
assertSame(MOCK_HTTP_TRANSPORT_FACTORY, OPTIONS.getHttpTransportFactory());
assertEquals(5678, OPTIONS.getReadTimeout());
@@ -119,19 +119,19 @@ public void testBuilder() {
}
@Test
- public void testBaseEquals() {
+ void testBaseEquals() {
assertEquals(OPTIONS, OPTIONS_COPY);
assertNotEquals(DEFAULT_OPTIONS, OPTIONS);
}
@Test
- public void testBaseHashCode() {
+ void testBaseHashCode() {
assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode());
assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode());
}
@Test
- public void testHeader() {
+ void testHeader() {
String expectedHeaderPattern = "^gl-java/.+ gccl/.* gax/.+";
ServiceOptions, ?> serviceOptions = EasyMock.createMock(ServiceOptions.class);
HeaderProvider headerProvider =
@@ -145,7 +145,7 @@ public void testHeader() {
}
@Test
- public void testHttpRequestInitializer_defaultUniverseDomainSettings_defaultCredentials()
+ void testHttpRequestInitializer_defaultUniverseDomainSettings_defaultCredentials()
throws IOException {
TestServiceOptions testServiceOptions =
generateTestServiceOptions(Credentials.GOOGLE_DEFAULT_UNIVERSE, defaultCredentials);
@@ -156,7 +156,7 @@ public void testHttpRequestInitializer_defaultUniverseDomainSettings_defaultCred
}
@Test
- public void testHttpRequestInitializer_defaultUniverseDomainSettings_customCredentials() {
+ void testHttpRequestInitializer_defaultUniverseDomainSettings_customCredentials() {
TestServiceOptions testServiceOptions =
generateTestServiceOptions(Credentials.GOOGLE_DEFAULT_UNIVERSE, customCredentials);
HttpRequestInitializer httpRequestInitializer =
@@ -171,7 +171,7 @@ public void testHttpRequestInitializer_defaultUniverseDomainSettings_customCrede
}
@Test
- public void testHttpRequestInitializer_customUniverseDomainSettings_defaultCredentials() {
+ void testHttpRequestInitializer_customUniverseDomainSettings_defaultCredentials() {
TestServiceOptions testServiceOptions =
generateTestServiceOptions(CUSTOM_UNIVERSE_DOMAIN, defaultCredentials);
HttpRequestInitializer httpRequestInitializer =
@@ -186,7 +186,7 @@ public void testHttpRequestInitializer_customUniverseDomainSettings_defaultCrede
}
@Test
- public void testHttpRequestInitializer_customUniverseDomainSettings_customCredentials()
+ void testHttpRequestInitializer_customUniverseDomainSettings_customCredentials()
throws IOException {
TestServiceOptions testServiceOptions =
generateTestServiceOptions(CUSTOM_UNIVERSE_DOMAIN, customCredentials);
@@ -197,8 +197,7 @@ public void testHttpRequestInitializer_customUniverseDomainSettings_customCreden
}
@Test
- public void testHttpRequestInitializer_defaultUniverseDomainSettings_noCredentials()
- throws IOException {
+ void testHttpRequestInitializer_defaultUniverseDomainSettings_noCredentials() throws IOException {
NoCredentials noCredentials = NoCredentials.getInstance();
TestServiceOptions testServiceOptions =
generateTestServiceOptions(Credentials.GOOGLE_DEFAULT_UNIVERSE, noCredentials);
@@ -209,7 +208,7 @@ public void testHttpRequestInitializer_defaultUniverseDomainSettings_noCredentia
}
@Test
- public void testHttpRequestInitializer_customUniverseDomainSettings_noCredentials() {
+ void testHttpRequestInitializer_customUniverseDomainSettings_noCredentials() {
NoCredentials noCredentials = NoCredentials.getInstance();
TestServiceOptions testServiceOptions =
generateTestServiceOptions(CUSTOM_UNIVERSE_DOMAIN, noCredentials);
diff --git a/java-core/google-cloud-core/pom.xml b/java-core/google-cloud-core/pom.xml
index 90659cc850..d3584d8c8a 100644
--- a/java-core/google-cloud-core/pom.xml
+++ b/java-core/google-cloud-core/pom.xml
@@ -76,8 +76,18 @@
- junit
- junit
+ org.junit.platform
+ junit-platform-launcher
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+ org.junit.vintage
+ junit-vintage-engine
test
diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java
index 241793b3be..92327a0b1c 100644
--- a/java-core/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java
+++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/AsyncPageImplTest.java
@@ -16,16 +16,16 @@
package com.google.cloud;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.gax.paging.AsyncPage;
import com.google.common.collect.ImmutableList;
import java.util.concurrent.ExecutionException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class AsyncPageImplTest {
+class AsyncPageImplTest {
private static final ImmutableList VALUES1 = ImmutableList.of("1", "2");
private static final ImmutableList VALUES2 = ImmutableList.of("3", "4");
@@ -51,7 +51,7 @@ public ApiFuture> getNextPage() {
}
@Test
- public void testPage() {
+ void testPage() {
final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2);
AsyncPageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult);
AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1);
@@ -61,7 +61,7 @@ public void testPage() {
}
@Test
- public void testPageAsync() throws ExecutionException, InterruptedException {
+ void testPageAsync() throws ExecutionException, InterruptedException {
final AsyncPageImpl nextResult = new AsyncPageImpl<>(null, "c", VALUES2);
AsyncPageImpl.NextPageFetcher fetcher = new TestPageFetcher(nextResult);
AsyncPageImpl result = new AsyncPageImpl<>(fetcher, "c", VALUES1);
@@ -71,7 +71,7 @@ public void testPageAsync() throws ExecutionException, InterruptedException {
}
@Test
- public void testIterateAll() {
+ void testIterateAll() {
final AsyncPageImpl nextResult2 = new AsyncPageImpl<>(null, "c3", VALUES3);
AsyncPageImpl.NextPageFetcher fetcher2 = new TestPageFetcher(nextResult2);
final AsyncPageImpl nextResult1 = new AsyncPageImpl<>(fetcher2, "c2", VALUES2);
@@ -81,7 +81,7 @@ public void testIterateAll() {
}
@Test
- public void testAsyncPageAndIterateAll() throws ExecutionException, InterruptedException {
+ void testAsyncPageAndIterateAll() throws ExecutionException, InterruptedException {
final AsyncPageImpl nextResult2 = new AsyncPageImpl<>(null, "c3", VALUES3);
AsyncPageImpl.NextPageFetcher fetcher2 = new TestPageFetcher(nextResult2);
final AsyncPageImpl nextResult1 = new AsyncPageImpl<>(fetcher2, "c2", VALUES2);
diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java
index 5dcd1726bb..bbc13770ae 100644
--- a/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java
+++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseSerializationTest.java
@@ -34,6 +34,10 @@
* {@code restorableObjects()} method to return all restorable objects whose state must be tested
* for proper serialization. Both methods can return {@code null} if no such object needs to be
* tested.
+ *
+ * This class has not migrated to Junit 5 because downstream libraries, e.g., java-logging, are
+ * extending this class and these libraries still use Junit 4. Migrating this class to Junit 5 will
+ * cause test failures in downstream libraries.
*/
public abstract class BaseSerializationTest {
diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java
index 4bc5993f7f..cfa06a6586 100644
--- a/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java
+++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java
@@ -22,18 +22,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.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 com.google.cloud.BaseServiceException.ExceptionData;
import com.google.common.collect.ImmutableSet;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/** Tests for {@link BaseServiceException}. */
-public class BaseServiceExceptionTest {
+class BaseServiceExceptionTest {
private static final int CODE = 1;
private static final int CODE_NO_REASON = 2;
@@ -64,7 +64,7 @@ public CustomServiceException(int code, String message, String reason, boolean i
}
@Test
- public void testBaseServiceException() {
+ void testBaseServiceException() {
BaseServiceException serviceException =
new BaseServiceException(ExceptionData.from(CODE, MESSAGE, REASON, NOT_RETRYABLE));
assertEquals(CODE, serviceException.getCode());
@@ -121,7 +121,7 @@ public void testBaseServiceException() {
}
@Test
- public void testTranslateAndThrow() throws Exception {
+ void testTranslateAndThrow() throws Exception {
BaseServiceException cause =
new BaseServiceException(ExceptionData.from(CODE, MESSAGE, REASON, NOT_RETRYABLE));
RetryHelper.RetryHelperException exceptionMock =
@@ -141,7 +141,7 @@ public void testTranslateAndThrow() throws Exception {
@Test
@SuppressWarnings("TruthSelfEquals")
- public void testError_Equal() {
+ void testError_Equal() {
BaseServiceException.Error error = new BaseServiceException.Error(0, "reason", true);
assertThat(error).isEqualTo(error);
assertThat(error.hashCode()).isEqualTo(error.hashCode());
diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java
index 65743a347a..847531f715 100644
--- a/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java
+++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java
@@ -17,11 +17,12 @@
package com.google.cloud;
import static com.google.common.truth.Truth.assertThat;
-import static junit.framework.TestCase.assertFalse;
-import static junit.framework.TestCase.assertTrue;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.cloud.spi.ServiceRpcFactory;
import java.io.IOException;
@@ -30,10 +31,10 @@
import java.nio.channels.ClosedChannelException;
import java.util.Arrays;
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 BaseWriteChannelTest {
+class BaseWriteChannelTest {
private abstract static class CustomService implements Service {}
@@ -58,8 +59,8 @@ protected CustomServiceOptions(
private static final Random RANDOM = new Random();
private static BaseWriteChannel channel;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
channel =
new BaseWriteChannel(null, ENTITY, UPLOAD_ID) {
@Override
@@ -78,8 +79,8 @@ protected BaseState.Builder stateBuilder() {
}
@Test
- public void testConstructor() {
- assertEquals(null, channel.getOptions());
+ void testConstructor() {
+ assertNull(channel.getOptions());
assertEquals(ENTITY, channel.getEntity());
assertEquals(0, channel.getPosition());
assertEquals(UPLOAD_ID, channel.getUploadId());
@@ -90,20 +91,20 @@ public void testConstructor() {
}
@Test
- public void testClose() throws IOException {
+ void testClose() throws IOException {
channel.close();
assertFalse(channel.isOpen());
assertNull(channel.getBuffer());
}
- @Test(expected = ClosedChannelException.class)
+ @Test
public void testValidateOpen() throws IOException {
channel.close();
- channel.write(ByteBuffer.allocate(42));
+ assertThrows(ClosedChannelException.class, () -> channel.write(ByteBuffer.allocate(42)));
}
@Test
- public void testChunkSize() {
+ void testChunkSize() {
channel.setChunkSize(42);
assertThat(channel.getChunkSize() >= MIN_CHUNK_SIZE).isTrue();
assertThat(channel.getChunkSize() % MIN_CHUNK_SIZE).isEqualTo(0);
@@ -118,7 +119,7 @@ public void testChunkSize() {
}
@Test
- public void testWrite() throws IOException {
+ void testWrite() throws IOException {
channel.write(ByteBuffer.wrap(CONTENT));
assertEquals(CONTENT.length, channel.getLimit());
assertEquals(DEFAULT_CHUNK_SIZE, channel.getBuffer().length);
@@ -126,7 +127,7 @@ public void testWrite() throws IOException {
}
@Test
- public void testWriteAndFlush() throws IOException {
+ void testWriteAndFlush() throws IOException {
ByteBuffer content = randomBuffer(DEFAULT_CHUNK_SIZE + 1);
channel.write(content);
assertEquals(DEFAULT_CHUNK_SIZE, channel.getPosition());
diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java
index 001bba9834..e8f6ae2da5 100644
--- a/java-core/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java
+++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/BatchResultTest.java
@@ -16,27 +16,27 @@
package com.google.cloud;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import com.google.cloud.BaseServiceException.ExceptionData;
import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class BatchResultTest {
+class BatchResultTest {
private BatchResult result;
- @Before
+ @BeforeEach
public void setUp() {
result = new BatchResult() {};
}
@Test
- public void testSuccess() {
+ void testSuccess() {
assertFalse(result.completed());
try {
result.get();
@@ -51,7 +51,7 @@ public void testSuccess() {
}
@Test
- public void testError() {
+ void testError() {
assertFalse(result.completed());
try {
result.get();
@@ -77,7 +77,7 @@ public void testError() {
}
@Test
- public void testNotifyError() {
+ void testNotifyError() {
final BaseServiceException ex =
new BaseServiceException(ExceptionData.from(0, "message", "reason", false));
assertFalse(result.completed());
@@ -97,7 +97,7 @@ public void testNotifyError() {
}
@Test
- public void testNotifySuccess() {
+ void testNotifySuccess() {
assertFalse(result.completed());
BatchResult.Callback callback =
EasyMock.createStrictMock(BatchResult.Callback.class);
diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java
index 42873f8643..67237b5371 100644
--- a/java-core/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java
+++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/ByteArrayTest.java
@@ -16,8 +16,8 @@
package com.google.cloud;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.common.io.ByteStreams;
import com.google.protobuf.ByteString;
@@ -26,10 +26,10 @@
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
-public class ByteArrayTest {
+class ByteArrayTest {
private static final String STRING_CONTENT = "Hello, ByteArray!";
private static final byte[] BYTES_CONTENT = STRING_CONTENT.getBytes(StandardCharsets.UTF_8);
@@ -42,14 +42,14 @@ public class ByteArrayTest {
private static ByteArray streamArray;
- @BeforeClass
- public static void beforeClass() throws IOException {
+ @BeforeAll
+ static void beforeClass() throws IOException {
streamArray = ByteArray.copyFrom(STREAM_CONTENT);
BYTE_BUFFER_CONTENT.flip();
}
@Test
- public void testCopyFromString() throws IOException {
+ void testCopyFromString() throws IOException {
assertEquals(STRING_CONTENT, STRING_ARRAY.toStringUtf8());
assertArrayEquals(BYTES_CONTENT, STRING_ARRAY.toByteArray());
assertEquals(BYTE_BUFFER_CONTENT.asReadOnlyBuffer(), STRING_ARRAY.asReadOnlyByteBuffer());
@@ -57,7 +57,7 @@ public void testCopyFromString() throws IOException {
}
@Test
- public void testCopyFromByteArray() throws IOException {
+ void testCopyFromByteArray() throws IOException {
assertEquals(STRING_CONTENT, BYTES_ARRAY.toStringUtf8());
assertArrayEquals(BYTES_CONTENT, BYTES_ARRAY.toByteArray());
assertEquals(BYTE_BUFFER_CONTENT.asReadOnlyBuffer(), BYTES_ARRAY.asReadOnlyByteBuffer());
@@ -65,7 +65,7 @@ public void testCopyFromByteArray() throws IOException {
}
@Test
- public void testCopyFromByteBuffer() throws IOException {
+ void testCopyFromByteBuffer() throws IOException {
assertEquals(STRING_CONTENT, BYTE_BUFFER_ARRAY.toStringUtf8());
assertArrayEquals(BYTES_CONTENT, BYTE_BUFFER_ARRAY.toByteArray());
assertEquals(BYTE_BUFFER_CONTENT.asReadOnlyBuffer(), BYTE_BUFFER_ARRAY.asReadOnlyByteBuffer());
@@ -73,7 +73,7 @@ public void testCopyFromByteBuffer() throws IOException {
}
@Test
- public void testCopyFromStream() throws IOException {
+ void testCopyFromStream() throws IOException {
assertEquals(STRING_CONTENT, streamArray.toStringUtf8());
assertArrayEquals(BYTES_CONTENT, streamArray.toByteArray());
assertEquals(BYTE_BUFFER_CONTENT.asReadOnlyBuffer(), streamArray.asReadOnlyByteBuffer());
@@ -81,32 +81,32 @@ public void testCopyFromStream() throws IOException {
}
@Test
- public void testLength() {
+ void testLength() {
assertEquals(BYTES_CONTENT.length, ARRAY.length());
}
@Test
- public void testToStringUtf8() {
+ void testToStringUtf8() {
assertEquals(STRING_CONTENT, ARRAY.toStringUtf8());
}
@Test
- public void testToByteArray() {
+ void testToByteArray() {
assertArrayEquals(BYTES_CONTENT, ARRAY.toByteArray());
}
@Test
- public void testAsReadOnlyByteBuffer() {
+ void testAsReadOnlyByteBuffer() {
assertEquals(BYTE_BUFFER_CONTENT.asReadOnlyBuffer(), ARRAY.asReadOnlyByteBuffer());
}
@Test
- public void testAsInputStream() throws IOException {
+ void testAsInputStream() throws IOException {
assertArrayEquals(BYTES_CONTENT, ByteStreams.toByteArray(ARRAY.asInputStream()));
}
@Test
- public void testHashCode() {
+ void testHashCode() {
assertEquals(STRING_ARRAY.hashCode(), BYTES_ARRAY.hashCode());
assertEquals(BYTES_ARRAY.hashCode(), BYTE_BUFFER_ARRAY.hashCode());
assertEquals(BYTE_BUFFER_ARRAY.hashCode(), streamArray.hashCode());
diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/ConditionTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/ConditionTest.java
index 67e0e6c2b5..19abe3eba3 100644
--- a/java-core/google-cloud-core/src/test/java/com/google/cloud/ConditionTest.java
+++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/ConditionTest.java
@@ -18,12 +18,12 @@
import static com.google.common.truth.Truth.assertThat;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public final class ConditionTest {
+final class ConditionTest {
@Test
- public void title_nullable() {
+ void title_nullable() {
Condition condition =
Condition.newBuilder().setTitle(null).setDescription("desc").setExpression("expr").build();
@@ -31,7 +31,7 @@ public void title_nullable() {
}
@Test
- public void description_nullable() {
+ void description_nullable() {
Condition condition =
Condition.newBuilder().setTitle("title").setDescription(null).setExpression("expr").build();
diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/DateTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/DateTest.java
index d95efaf094..6b2a6e4df5 100644
--- a/java-core/google-cloud-core/src/test/java/com/google/cloud/DateTest.java
+++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/DateTest.java
@@ -18,23 +18,20 @@
import static com.google.common.testing.SerializableTester.reserializeAndAssert;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
import com.google.common.testing.EqualsTester;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Unit tests for {@link Date}. */
-@RunWith(JUnit4.class)
-public class DateTest {
+class DateTest {
private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
@Test
- public void parseDate() {
+ void parseDate() {
verifyDate("2016-09-18", 2016, 9, 18);
verifyDate("2000-01-01", 2000, 1, 1);
verifyDate("9999-12-31", 9999, 12, 31);
@@ -53,7 +50,7 @@ private void verifyDate(String input, int year, int month, int day) {
}
@Test
- public void parseInvalidDates() {
+ void parseInvalidDates() {
parseInvalidDate("2016/09/18");
parseInvalidDate("2016 09 18");
parseInvalidDate("2016-9-18");
@@ -112,7 +109,7 @@ private void parseInvalidDay(String input) {
}
@Test
- public void testToString() {
+ void testToString() {
Date date = Date.fromYearMonthDay(10, 9, 5);
assertThat(date.toString()).isEqualTo("0010-09-05");
date = Date.fromYearMonthDay(2016, 12, 31);
@@ -122,7 +119,7 @@ public void testToString() {
}
@Test
- public void equalAndHashCode() {
+ void equalAndHashCode() {
Date d1 = Date.fromYearMonthDay(2016, 9, 18);
Date d2 = Date.fromYearMonthDay(2016, 9, 18);
Date d3 = Date.fromYearMonthDay(2016, 9, 19);
@@ -130,7 +127,7 @@ public void equalAndHashCode() {
}
@Test
- public void validOrdering() {
+ void validOrdering() {
Date d1 = Date.fromYearMonthDay(2016, 9, 18);
Date d2 = Date.fromYearMonthDay(2016, 9, 19);
Date d3 = Date.fromYearMonthDay(2016, 9, 20);
@@ -140,12 +137,12 @@ public void validOrdering() {
}
@Test
- public void serialization() {
+ void serialization() {
reserializeAndAssert(Date.fromYearMonthDay(2017, 4, 20));
}
@Test
- public void testToJavaUtilDate() throws ParseException {
+ void testToJavaUtilDate() throws ParseException {
Date gcDate = Date.parseDate("2016-09-18");
java.util.Date juDate1 = SIMPLE_DATE_FORMAT.parse("2016-09-18");
java.util.Date juDate2 = Date.toJavaUtilDate(gcDate);
@@ -153,7 +150,7 @@ public void testToJavaUtilDate() throws ParseException {
}
@Test
- public void testFromJavaUtilDate() throws ParseException {
+ void testFromJavaUtilDate() throws ParseException {
java.util.Date juDate = SIMPLE_DATE_FORMAT.parse("2016-09-18");
Date gcDate = Date.fromJavaUtilDate(juDate);
assertThat(gcDate.getYear()).isEqualTo(2016);
diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java
index 50e0583c89..f5efcdd3d1 100644
--- a/java-core/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java
+++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java
@@ -16,9 +16,10 @@
package com.google.cloud;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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 static org.junit.jupiter.api.Assertions.fail;
import com.google.cloud.ExceptionHandler.Interceptor;
import com.google.cloud.ExceptionHandler.Interceptor.RetryResult;
@@ -27,13 +28,13 @@
import java.nio.channels.ClosedByInterruptException;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/** Tests for {@link ExceptionHandler}. */
-public class ExceptionHandlerTest {
+class ExceptionHandlerTest {
@Test
- public void testVerifyCaller() {
+ void testVerifyCaller() {
class A implements Callable
-
- junit
- junit
- 4.13.2
- test
-
com.google.truth
truth
diff --git a/java-shared-dependencies/third-party-dependencies/pom.xml b/java-shared-dependencies/third-party-dependencies/pom.xml
index 6d798069f8..f46adf6328 100644
--- a/java-shared-dependencies/third-party-dependencies/pom.xml
+++ b/java-shared-dependencies/third-party-dependencies/pom.xml
@@ -198,6 +198,13 @@
detector-resources-support
${google.cloud.opentelemetry.version}
+
+ org.junit
+ junit-bom
+ ${junit.version}
+ pom
+ import
+