-
Notifications
You must be signed in to change notification settings - Fork 54
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
test: Migrate gax unit tests to Junit 5 #2724
Conversation
import org.threeten.bp.Duration; | ||
|
||
@RunWith(JUnit4.class) | ||
public class TimeoutTest { | ||
@ExtendWith(MockitoExtension.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because there is a @Rule
for Mockito being removed below.
gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/ApiExceptionsTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/ApiExceptionsTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/ApiExceptionsTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchedRequestIssuerTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchedRequestIssuerTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchedRequestIssuerTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchedRequestIssuerTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java
Outdated
Show resolved
Hide resolved
...a/gax/src/test/java/com/google/api/gax/rpc/internal/QuotaProjectIdHidingCredentialsTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/mtls/AbstractMtlsTransportChannelTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/mtls/MtlsProviderTest.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/mtls/MtlsProviderTest.java
Outdated
Show resolved
Hide resolved
gax-java/pom.xml
Outdated
<version>4.13.2</version> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>4.11.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using mockito bom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not aware of a mockito bom, sounds like a good idea. Also, I think adding the bom to this pom should fine, because gax-parent is not included in the gapic-generator-java-bom, only gax-bom is. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so.
You can verify this by running mvn -pl gapic-generator-java-bom help:effective-pom
at repo root.
gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java
Show resolved
Hide resolved
gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java
Show resolved
Hide resolved
gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java
Outdated
Show resolved
Hide resolved
Quality Gate passed for 'gapic-generator-java-root'Issues Measures |
Quality Gate passed for 'java_showcase_integration_tests'Issues Measures |
This PR migrate all unit tests in Gax to Junit 5. Other than standard direct replacements, some tests need to be rewritten due to the following scenarios: - `@Rule` does not exist anymore and there is no direct replacement. We mostly use it to initialize a Mockito stub, replaced with `@ExtendWith(MockitoExtension.class)`. - Some tests were relying on try-catch to assert exceptions, replaced with `assertThrows`. e.g. [OperationsClientTest](https://github.com/googleapis/sdk-platform-java/pull/2724/files#diff-4530df761eff0854357165d951e1667d3810a5448ec2aa4b853a6331516cbde0) - Parameterized tests in [AbstractRetryingExecutorTest](https://github.com/googleapis/sdk-platform-java/pull/2724/files#diff-9c5f5c1d2fcef6c4164fc0171d01e7020aa7ebb7aa49615cf3743dc89c9b3d1d) There are a few environment variable tests can be re-written with Junit 5, so we don't need to configure a [profile](https://github.com/googleapis/sdk-platform-java/blob/main/gax-java/gax/pom.xml#L115-L128) for it anymore, but they are not in the scope of this PR. fixes: #1611.
This PR migrate all unit tests in Gax to Junit 5.
Other than standard direct replacements, some tests need to be rewritten due to the following scenarios:
@Rule
does not exist anymore and there is no direct replacement. We mostly use it to initialize a Mockito stub, replaced with@ExtendWith(MockitoExtension.class)
.assertThrows
. e.g. OperationsClientTestThere are a few environment variable tests can be re-written with Junit 5, so we don't need to configure a profile for it anymore, but they are not in the scope of this PR.
fixes: #1611.