Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: use Junit5 in java core #2754

Merged
merged 48 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6104515
chore: change test dependency
JoeWang1127 May 8, 2024
ba073a2
change tests
JoeWang1127 May 8, 2024
fc4bcb3
change tests
JoeWang1127 May 8, 2024
e7dd139
change tests
JoeWang1127 May 8, 2024
d97231d
change tests
JoeWang1127 May 8, 2024
f4f37b6
change tests
JoeWang1127 May 8, 2024
db78162
change tests
JoeWang1127 May 8, 2024
d84ffa1
change tests
JoeWang1127 May 8, 2024
849ea75
change tests
JoeWang1127 May 8, 2024
9827052
change tests
JoeWang1127 May 8, 2024
421d1ea
change tests
JoeWang1127 May 8, 2024
c04aa05
change tests
JoeWang1127 May 8, 2024
5a52991
change tests
JoeWang1127 May 8, 2024
7bb27e3
change tests
JoeWang1127 May 8, 2024
cadee13
change tests
JoeWang1127 May 8, 2024
5e6e1f8
change tests
JoeWang1127 May 8, 2024
93f6239
change tests
JoeWang1127 May 8, 2024
d2f28b5
change tests
JoeWang1127 May 8, 2024
c5ede6f
change tests
JoeWang1127 May 8, 2024
48f681d
change tests
JoeWang1127 May 8, 2024
9f0d7bf
change tests
JoeWang1127 May 8, 2024
9f21f35
change tests
JoeWang1127 May 8, 2024
0733888
change tests
JoeWang1127 May 8, 2024
322de93
change tests
JoeWang1127 May 8, 2024
5a05545
change tests
JoeWang1127 May 8, 2024
d21cd32
change tests
JoeWang1127 May 8, 2024
5a58299
change tests
JoeWang1127 May 8, 2024
282ea92
change tests
JoeWang1127 May 8, 2024
046a43a
change tests
JoeWang1127 May 8, 2024
de50f00
change tests
JoeWang1127 May 8, 2024
f22d1ca
change tests
JoeWang1127 May 8, 2024
f7ea1bc
change tests
JoeWang1127 May 8, 2024
1c7634d
change tests
JoeWang1127 May 8, 2024
8ab4f9d
remove junit4 rules and tests
JoeWang1127 May 8, 2024
7b7c47c
Merge branch 'main' into chore/junit5-java-core
JoeWang1127 May 8, 2024
aa21286
lint
JoeWang1127 May 8, 2024
6b64111
change to public
JoeWang1127 May 8, 2024
bd6e6b4
Revert "remove junit4 rules and tests"
JoeWang1127 May 8, 2024
faae274
Merge branch 'main' into chore/junit5-java-core
JoeWang1127 May 8, 2024
99c7b7f
Merge branch 'main' into chore/junit5-java-core
JoeWang1127 May 10, 2024
905d3c4
Revert "change tests"
JoeWang1127 May 10, 2024
c02f7a2
add comment to BaseSerializationTest
JoeWang1127 May 10, 2024
67cb1c6
lint
JoeWang1127 May 10, 2024
d3d6af2
add junit version in pom parent
JoeWang1127 May 13, 2024
74f94f2
add junit to third party dependency
JoeWang1127 May 14, 2024
155b09b
Merge branch 'main' into chore/junit5-java-core
JoeWang1127 May 14, 2024
1bc09d9
code refactor according to code review
JoeWang1127 May 16, 2024
787bf6f
Merge branch 'main' into chore/junit5-java-core
JoeWang1127 May 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gapic-generator-java-pom-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<errorprone.version>2.27.1</errorprone.version>
<j2objc-annotations.version>3.0.0</j2objc-annotations.version>
<threetenbp.version>1.6.9</threetenbp.version>
<junit.version>5.10.2</junit.version>
</properties>

<developers>
Expand Down
14 changes: 12 additions & 2 deletions java-core/google-cloud-core-grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,18 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,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.gax.grpc.GrpcStatusCode;
import com.google.api.gax.rpc.InternalException;
Expand All @@ -33,16 +33,16 @@
import java.io.IOException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class BaseGrpcServiceExceptionTest {
class BaseGrpcServiceExceptionTest {

private static final String MESSAGE = "some message";
private static final boolean NOT_RETRYABLE = false;
private static final boolean IDEMPOTENT = true;

@Test
public void testBaseServiceException() {
void testBaseServiceException() {
BaseGrpcServiceException serviceException = null;

IOException exception = new SocketTimeoutException();
Expand Down Expand Up @@ -86,7 +86,7 @@ public void testBaseServiceException() {
}

@Test
public void testTranslateAndThrow() throws Exception {
void testTranslateAndThrow() throws Exception {
IOException exception = new SocketTimeoutException();
BaseGrpcServiceException cause = new BaseGrpcServiceException(exception, IDEMPOTENT);
RetryHelper.RetryHelperException exceptionMock =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

package com.google.cloud.grpc;

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.cloud.grpc.GrpcTransportOptions.DefaultExecutorFactory;
import com.google.cloud.grpc.GrpcTransportOptions.ExecutorFactory;
import java.util.concurrent.ScheduledExecutorService;
import org.easymock.EasyMock;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class GrpcTransportOptionsTest {
class GrpcTransportOptionsTest {

private static final ExecutorFactory MOCK_EXECUTOR_FACTORY =
EasyMock.createMock(ExecutorFactory.class);
Expand All @@ -38,13 +38,13 @@ public class GrpcTransportOptionsTest {
private static final GrpcTransportOptions OPTIONS_COPY = OPTIONS.toBuilder().build();

@Test
public void testBuilder() {
void testBuilder() {
assertSame(MOCK_EXECUTOR_FACTORY, OPTIONS.getExecutorFactory());
assertTrue(DEFAULT_OPTIONS.getExecutorFactory() instanceof DefaultExecutorFactory);
}

@Test
public void testBaseEquals() {
void testBaseEquals() {
assertEquals(OPTIONS, OPTIONS_COPY);
assertNotEquals(DEFAULT_OPTIONS, OPTIONS);
GrpcTransportOptions options =
Expand All @@ -53,7 +53,7 @@ public void testBaseEquals() {
}

@Test
public void testBaseHashCode() {
void testBaseHashCode() {
assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode());
assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode());
GrpcTransportOptions options =
Expand All @@ -62,7 +62,7 @@ public void testBaseHashCode() {
}

@Test
public void testDefaultExecutorFactory() {
void testDefaultExecutorFactory() {
ExecutorFactory<ScheduledExecutorService> executorFactory = new DefaultExecutorFactory();
ScheduledExecutorService executorService = executorFactory.get();
assertSame(executorService, executorFactory.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 (<a
* href="https://github.com/grpc/grpc-java/blob/d07ecbe037d2705a1c9f4b6345581f860e505b56/core/src/test/java/io/grpc/internal/SharedResourceHolderTest.java">SharedResourceHolderTest</a>)
*
* <p>Unit tests for {@link SharedResourceHolder}.
*/
@RunWith(JUnit4.class)
public class SharedResourceHolderTest {
class SharedResourceHolderTest {

private final LinkedList<MockScheduledFuture<?>> scheduledDestroyTasks = new LinkedList<>();

Expand Down Expand Up @@ -67,13 +75,13 @@ public void close(ResourceInstance instance) {
private static final SharedResourceHolder.Resource<ResourceInstance> 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);
Expand Down Expand Up @@ -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);
Expand All @@ -148,7 +156,7 @@ public void cancelDestroyTask() {
}

@Test
public void releaseWrongInstance() {
void releaseWrongInstance() {
ResourceInstance uncached = new ResourceInstance();
try {
holder.releaseInternal(SHARED_FOO, uncached);
Expand All @@ -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 {
Expand All @@ -179,7 +187,7 @@ public void overreleaseInstance() {
}

@Test
public void handleInstanceCloseError() {
void handleInstanceCloseError() {
class ExceptionOnCloseResource implements SharedResourceHolder.Resource<ResourceInstance> {
@Override
public ResourceInstance create() {
Expand Down
14 changes: 12 additions & 2 deletions java-core/google-cloud-core-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,18 @@

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -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());
Expand Down Expand Up @@ -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 =
Expand Down
Loading
Loading