Skip to content

Commit

Permalink
Update Mockito to v5 for Java tests (hyperledger#723)
Browse files Browse the repository at this point in the history
v4 is no longer supported. v5 does require a minimum of Java 11 but Java
8 is still targeted as the release version.

Also revert commit f026b2c since the
synchronization added there did not resolve intermittent test failures
in the automated build.

Signed-off-by: Mark S. Lewis <[email protected]>
  • Loading branch information
bestbeforetoday authored Jun 25, 2024
1 parent 4e86f9a commit d2cf912
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 95 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ jobs:
fail-fast: false
matrix:
java-version:
- 8
- 11
- 17
- 21
Expand All @@ -172,7 +171,7 @@ jobs:
fail-fast: false
matrix:
java-version:
- 8
- 11
- 21
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ build these components, the following need to be installed and available in the

- [Go 1.21+](https://go.dev/)
- [Node 18+](https://nodejs.org/)
- [Java 8+](https://adoptium.net/)
- [Java 11+](https://adoptium.net/)
- [Docker](https://www.docker.com/)
- [Make](https://www.gnu.org/software/make/)
- [Maven](https://maven.apache.org/)
Expand Down
14 changes: 7 additions & 7 deletions docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Each minor release version of Fabric Gateway client API targets the current supp

The following table shows versions of Fabric, programming language runtimes, and other dependencies that are explicitly tested and that are supported for use with the latest version of the Fabric Gateway client API.

| | Tested | Supported |
| ------------ | ------------- | ------------- |
| **Fabric** | 2.5 | 2.4.4+ |
| **Go** | 1.21, 1.22 | 1.21, 1.22 |
| **Node** | 18, 20 | 18, 20 |
| **Java** | 8, 11, 17, 21 | 8, 11, 17, 21 |
| **Platform** | Ubuntu 22.04 | |
| | Tested | Supported |
| ------------ | ------------ | ------------- |
| **Fabric** | 2.5 | 2.4.4+ |
| **Go** | 1.21, 1.22 | 1.21, 1.22 |
| **Node** | 18, 20 | 18, 20 |
| **Java** | 11, 17, 21 | 8, 11, 17, 21 |
| **Platform** | Ubuntu 22.04 | |
30 changes: 15 additions & 15 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>7.16.1</version>
<version>7.18.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -82,13 +82,13 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.25.3</version>
<version>3.26.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -153,7 +153,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce-version</id>
Expand All @@ -163,7 +163,7 @@
<configuration>
<rules>
<requireJavaVersion>
<version>${javaVersion}</version>
<version>11</version>
</requireJavaVersion>
<requireMavenVersion>
<version>3.6.3</version>
Expand All @@ -176,7 +176,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<executions>
<execution>
<id>show-profiles</id>
Expand All @@ -189,7 +189,7 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<version>3.12.1</version>
<configuration>
<source>${javaVersion}</source>
<target>${javaVersion}</target>
Expand All @@ -204,7 +204,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<version>3.3.0</version>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
Expand Down Expand Up @@ -264,7 +264,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.3</version>
<version>3.7.0</version>
<configuration>
<show>public</show>
<doctitle>Hyperledger Fabric Gateway client API for Java</doctitle>
Expand Down Expand Up @@ -295,7 +295,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand Down Expand Up @@ -411,7 +411,7 @@
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>9.1.0</version>
<version>9.2.0</version>
<configuration>
<skipProvidedScope>true</skipProvidedScope>
<skipTestScope>true</skipTestScope>
Expand Down Expand Up @@ -440,7 +440,7 @@
<plugin>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId>
<version>2.8.0</version>
<version>2.7.11</version>
<configuration>
<includeCompileScope>true</includeCompileScope>
<includeProvidedScope>false</includeProvidedScope>
Expand All @@ -466,7 +466,7 @@
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<version>3.6.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
Expand All @@ -484,7 +484,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.2</version>
<version>3.2.4</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down Expand Up @@ -528,7 +528,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ void throws_on_connection_error() {
StatusRuntimeException expected = new StatusRuntimeException(Status.UNAVAILABLE);
doThrow(expected).when(stub).chaincodeEvents(any());

GatewayRuntimeException e = catchThrowableOfType(
() -> {
try (CloseableIterator<ChaincodeEvent> events = network.getChaincodeEvents("CHAINCODE_NAME")) {
events.forEachRemaining(event -> {});
}
},
GatewayRuntimeException.class);
GatewayRuntimeException e = catchThrowableOfType(GatewayRuntimeException.class, () -> {
try (CloseableIterator<ChaincodeEvent> events = network.getChaincodeEvents("CHAINCODE_NAME")) {
events.forEachRemaining(event -> {});
}
});
assertThat(e.getStatus()).isEqualTo(expected.getStatus());
assertThat(e).hasCauseInstanceOf(StatusRuntimeException.class);
}
Expand Down Expand Up @@ -322,7 +320,7 @@ void close_stops_receiving_events() {
}

GatewayRuntimeException e =
catchThrowableOfType(() -> eventIter.forEachRemaining(event -> {}), GatewayRuntimeException.class);
catchThrowableOfType(GatewayRuntimeException.class, () -> eventIter.forEachRemaining(event -> {}));
assertThat(e).hasCauseInstanceOf(StatusRuntimeException.class);
assertThat(e.getStatus().getCode()).isEqualTo(Status.Code.CANCELLED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,11 @@ void throws_on_connection_error() {
StatusRuntimeException expected = new StatusRuntimeException(Status.UNAVAILABLE);
stubDoThrow(expected);

GatewayRuntimeException e = catchThrowableOfType(
() -> {
try (CloseableIterator<?> iter = getEvents()) {
iter.forEachRemaining(event -> {});
}
},
GatewayRuntimeException.class);
GatewayRuntimeException e = catchThrowableOfType(GatewayRuntimeException.class, () -> {
try (CloseableIterator<?> iter = getEvents()) {
iter.forEachRemaining(event -> {});
}
});

assertThat(e.getStatus()).isEqualTo(expected.getStatus());
assertThat(e).hasCauseInstanceOf(StatusRuntimeException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,58 +119,42 @@ public Gateway.Builder getGatewayBuilder() {
}

public EndorseRequest captureEndorse() {
synchronized (gatewaySpy) {
Mockito.verify(gatewaySpy).endorse(endorseRequestCaptor.capture());
}
Mockito.verify(gatewaySpy).endorse(endorseRequestCaptor.capture());
return endorseRequestCaptor.getValue();
}

public EvaluateRequest captureEvaluate() {
synchronized (gatewaySpy) {
Mockito.verify(gatewaySpy).evaluate(evaluateRequestCaptor.capture());
}
Mockito.verify(gatewaySpy).evaluate(evaluateRequestCaptor.capture());
return evaluateRequestCaptor.getValue();
}

public SubmitRequest captureSubmit() {
synchronized (gatewaySpy) {
Mockito.verify(gatewaySpy).submit(submitRequestCaptor.capture());
}
Mockito.verify(gatewaySpy).submit(submitRequestCaptor.capture());
return submitRequestCaptor.getValue();
}

public SignedCommitStatusRequest captureCommitStatus() {
synchronized (gatewaySpy) {
Mockito.verify(gatewaySpy).commitStatus(commitStatusRequestCaptor.capture());
}
Mockito.verify(gatewaySpy).commitStatus(commitStatusRequestCaptor.capture());
return commitStatusRequestCaptor.getValue();
}

public SignedChaincodeEventsRequest captureChaincodeEvents() {
synchronized (gatewaySpy) {
Mockito.verify(gatewaySpy).chaincodeEvents(chaincodeEventsRequestCaptor.capture());
}
Mockito.verify(gatewaySpy).chaincodeEvents(chaincodeEventsRequestCaptor.capture());
return chaincodeEventsRequestCaptor.getValue();
}

public Stream<Envelope> captureBlockEvents() {
synchronized (deliverSpy) {
Mockito.verify(deliverSpy).blockEvents(deliverRequestCaptor.capture());
}
Mockito.verify(deliverSpy).blockEvents(deliverRequestCaptor.capture());
return deliverRequestCaptor.getValue();
}

public Stream<Envelope> captureFilteredBlockEvents() {
synchronized (deliverSpy) {
Mockito.verify(deliverSpy).filteredBlockEvents(deliverFilteredRequestCaptor.capture());
}
Mockito.verify(deliverSpy).filteredBlockEvents(deliverFilteredRequestCaptor.capture());
return deliverFilteredRequestCaptor.getValue();
}

public Stream<Envelope> captureBlockAndPrivateDataEvents() {
synchronized (deliverSpy) {
Mockito.verify(deliverSpy).blockAndPrivateDataEvents(deliverWithPrivateDataRequestCaptor.capture());
}
Mockito.verify(deliverSpy).blockAndPrivateDataEvents(deliverWithPrivateDataRequestCaptor.capture());
return deliverWithPrivateDataRequestCaptor.getValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,19 @@ public MockDeliverService(final DeliverServiceStub stub) {

@Override
public StreamObserver<Envelope> deliver(final StreamObserver<DeliverResponse> responseObserver) {
synchronized (stub) {
return testUtils.invokeStubDuplexCall(
stub::blockEvents, (ServerCallStreamObserver<DeliverResponse>) responseObserver, 1);
}
return testUtils.invokeStubDuplexCall(
stub::blockEvents, (ServerCallStreamObserver<DeliverResponse>) responseObserver, 1);
}

@Override
public StreamObserver<Envelope> deliverFiltered(final StreamObserver<DeliverResponse> responseObserver) {
synchronized (stub) {
return testUtils.invokeStubDuplexCall(
stub::filteredBlockEvents, (ServerCallStreamObserver<DeliverResponse>) responseObserver, 1);
}
return testUtils.invokeStubDuplexCall(
stub::filteredBlockEvents, (ServerCallStreamObserver<DeliverResponse>) responseObserver, 1);
}

@Override
public StreamObserver<Envelope> deliverWithPrivateData(final StreamObserver<DeliverResponse> responseObserver) {
synchronized (stub) {
return testUtils.invokeStubDuplexCall(
stub::blockAndPrivateDataEvents, (ServerCallStreamObserver<DeliverResponse>) responseObserver, 1);
}
return testUtils.invokeStubDuplexCall(
stub::blockAndPrivateDataEvents, (ServerCallStreamObserver<DeliverResponse>) responseObserver, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,29 @@ public MockGatewayService(final GatewayServiceStub stub) {

@Override
public void endorse(final EndorseRequest request, final StreamObserver<EndorseResponse> responseObserver) {
synchronized (stub) {
testUtils.invokeStubUnaryCall(stub::endorse, request, responseObserver);
}
testUtils.invokeStubUnaryCall(stub::endorse, request, responseObserver);
}

@Override
public void submit(final SubmitRequest request, final StreamObserver<SubmitResponse> responseObserver) {
synchronized (stub) {
testUtils.invokeStubUnaryCall(stub::submit, request, responseObserver);
}
testUtils.invokeStubUnaryCall(stub::submit, request, responseObserver);
}

@Override
public void evaluate(final EvaluateRequest request, final StreamObserver<EvaluateResponse> responseObserver) {
synchronized (stub) {
testUtils.invokeStubUnaryCall(stub::evaluate, request, responseObserver);
}
testUtils.invokeStubUnaryCall(stub::evaluate, request, responseObserver);
}

@Override
public void commitStatus(
final SignedCommitStatusRequest request, final StreamObserver<CommitStatusResponse> responseObserver) {
synchronized (stub) {
testUtils.invokeStubUnaryCall(stub::commitStatus, request, responseObserver);
}
testUtils.invokeStubUnaryCall(stub::commitStatus, request, responseObserver);
}

@Override
public void chaincodeEvents(
final SignedChaincodeEventsRequest request,
final StreamObserver<ChaincodeEventsResponse> responseObserver) {
synchronized (stub) {
testUtils.invokeStubServerStreamingCall(stub::chaincodeEvents, request, responseObserver);
}
testUtils.invokeStubServerStreamingCall(stub::chaincodeEvents, request, responseObserver);
}
}
Loading

0 comments on commit d2cf912

Please sign in to comment.