Skip to content

Commit

Permalink
chore: use Monitor mock in tests instead of ConsoleMonitor (#46) (#21)
Browse files Browse the repository at this point in the history
* Use mock of Monitor in tests for consistency.

* Removed consolemonitor.
  • Loading branch information
ouphi authored Aug 8, 2022
1 parent 8602590 commit b9c70e4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.nimbusds.jwt.SignedJWT;
import org.eclipse.dataspaceconnector.iam.did.spi.resolution.DidPublicKeyResolver;
import org.eclipse.dataspaceconnector.identityhub.junit.testfixtures.VerifiableCredentialTestUtil;
import org.eclipse.dataspaceconnector.spi.monitor.ConsoleMonitor;
import org.eclipse.dataspaceconnector.spi.monitor.Monitor;
import org.eclipse.dataspaceconnector.spi.result.Result;
import org.junit.jupiter.api.Test;
Expand All @@ -41,15 +40,14 @@
public class DidJwtCredentialsVerifierTest {

private static final Faker FAKER = new Faker();
private static final Monitor MONITOR = new ConsoleMonitor();
private static final ECKey JWK = generateEcKey();
private static final ECKey ANOTHER_JWK = generateEcKey();
private static final String ISSUER = FAKER.internet().url();
private static final String SUBJECT = FAKER.internet().url();
private static final String OTHER_SUBJECT = FAKER.internet().url() + "other";
private static final SignedJWT JWT = buildSignedJwt(generateVerifiableCredential(), ISSUER, SUBJECT, JWK);
private DidPublicKeyResolver didPublicKeyResolver = mock(DidPublicKeyResolver.class);
private DidJwtCredentialsVerifier didJwtCredentialsVerifier = new DidJwtCredentialsVerifier(didPublicKeyResolver, MONITOR);
private DidJwtCredentialsVerifier didJwtCredentialsVerifier = new DidJwtCredentialsVerifier(didPublicKeyResolver, mock(Monitor.class));

@Test
public void isSignedByIssuer_jwtSignedByIssuer() {
Expand Down
2 changes: 2 additions & 0 deletions identity-hub-core/identity-hub-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ val jupiterVersion: String by project
val faker: String by project
val assertj: String by project
val nimbusVersion: String by project
val mockitoVersion: String by project

dependencies {
api(project(":spi:identity-hub-spi"))
Expand All @@ -44,6 +45,7 @@ dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${jupiterVersion}")
testImplementation("org.assertj:assertj-core:${assertj}")
testImplementation("com.github.javafaker:javafaker:${faker}")
testImplementation("org.mockito:mockito-core:${mockitoVersion}")
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.dataspaceconnector.identityhub.credentials.model.VerifiableCredential;
import org.eclipse.dataspaceconnector.junit.extensions.EdcExtension;
import org.eclipse.dataspaceconnector.junit.testfixtures.TestUtils;
import org.eclipse.dataspaceconnector.spi.monitor.ConsoleMonitor;
import org.eclipse.dataspaceconnector.spi.monitor.Monitor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -30,6 +30,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.dataspaceconnector.identityhub.junit.testfixtures.VerifiableCredentialTestUtil.buildSignedJwt;
import static org.eclipse.dataspaceconnector.identityhub.junit.testfixtures.VerifiableCredentialTestUtil.generateEcKey;
import static org.mockito.Mockito.mock;

@ExtendWith(EdcExtension.class)
public class IdentityHubClientImplIntegrationTest {
Expand All @@ -43,7 +44,7 @@ public class IdentityHubClientImplIntegrationTest {
@BeforeEach
void setUp() {
var okHttpClient = TestUtils.testOkHttpClient();
client = new IdentityHubClientImpl(okHttpClient, OBJECT_MAPPER, new ConsoleMonitor());
client = new IdentityHubClientImpl(okHttpClient, OBJECT_MAPPER, mock(Monitor.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.eclipse.dataspaceconnector.identityhub.model.MessageStatus;
import org.eclipse.dataspaceconnector.identityhub.model.RequestStatus;
import org.eclipse.dataspaceconnector.identityhub.model.ResponseObject;
import org.eclipse.dataspaceconnector.spi.monitor.ConsoleMonitor;
import org.eclipse.dataspaceconnector.spi.monitor.Monitor;
import org.eclipse.dataspaceconnector.spi.response.ResponseStatus;
import org.eclipse.dataspaceconnector.spi.response.StatusResult;
import org.junit.jupiter.api.Test;
Expand All @@ -40,6 +40,7 @@
import static org.eclipse.dataspaceconnector.identityhub.junit.testfixtures.VerifiableCredentialTestUtil.buildSignedJwt;
import static org.eclipse.dataspaceconnector.identityhub.junit.testfixtures.VerifiableCredentialTestUtil.generateEcKey;
import static org.eclipse.dataspaceconnector.identityhub.model.MessageResponseObject.MESSAGE_ID_VALUE;
import static org.mockito.Mockito.mock;

public class IdentityHubClientImplTest {
private static final Faker FAKER = new Faker();
Expand Down Expand Up @@ -171,6 +172,6 @@ private IdentityHubClientImpl createClient(Interceptor interceptor) {
.addInterceptor(interceptor)
.build();

return new IdentityHubClientImpl(okHttpClient, OBJECT_MAPPER, new ConsoleMonitor());
return new IdentityHubClientImpl(okHttpClient, OBJECT_MAPPER, mock(Monitor.class));
}
}

0 comments on commit b9c70e4

Please sign in to comment.