Skip to content

Commit

Permalink
NA: Straighten out a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
bucky-boy committed Sep 23, 2024
1 parent 8b913d3 commit f57d819
Showing 1 changed file with 37 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
import static com.yoti.api.client.spi.remote.call.YotiConstants.DEFAULT_CHARSET;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

import java.io.IOException;
import java.time.ZonedDateTime;
Expand All @@ -19,10 +26,10 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.hamcrest.Matchers;
import org.junit.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.*;
import org.mockito.junit.*;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class SessionSpecTest {
Expand Down Expand Up @@ -53,51 +60,40 @@ public class SessionSpecTest {

@Test
public void shouldBuildWithMinimalConfiguration() {
SessionSpec result = SessionSpec.builder().build();

assertThat(result.getClientSessionTokenTtl(), is(nullValue()));
assertThat(result.getSessionDeadline(), is(nullValue()));
assertThat(result.getResourcesTtl(), is(nullValue()));
assertThat(result.getImportToken(), is(nullValue()));
assertThat(result.getUserTrackingId(), is(nullValue()));
assertThat(result.getNotifications(), is(nullValue()));
assertThat(result.getRequestedChecks(), hasSize(0));
assertThat(result.getRequestedTasks(), hasSize(0));
assertThat(result.getSdkConfig(), is(nullValue()));
assertThat(result.getRequiredDocuments(), hasSize(0));
assertThat(result.getBlockBiometricConsent(), is(nullValue()));
assertThat(result.getIbvOptions(), is(nullValue()));
assertThat(result.getIdentityProfile(), is(nullValue()));
assertThat(result.getAdvancedIdentityProfileRequirements(), is(nullValue()));
assertThat(result.getSubject(), is(nullValue()));
assertThat(result.getResources(), is(nullValue()));
assertThat(result.getCreateIdentityProfilePreview(), is(nullValue()));
}

@Test
public void shouldBuildWithSimpleValues() {
SessionSpec result = SessionSpec.builder()
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
.withResourcesTtl(SOME_RESOURCES_TTL)
.withUserTrackingId(SOME_USER_TRACKING_ID)
.withBlockBiometricConsent(true)
.build();

assertThat(result, is(instanceOf(SessionSpec.class)));
assertThat(result.getClientSessionTokenTtl(), is(SOME_CLIENT_SESSION_TOKEN_TTL));
assertThat(result.getResourcesTtl(), is(SOME_RESOURCES_TTL));
assertThat(result.getUserTrackingId(), is(SOME_USER_TRACKING_ID));
assertThat(result.getBlockBiometricConsent(), is(true));
assertThat(result.getRequiredDocuments(), hasSize(0));
}

@Test
public void shouldRaiseForMissingClientSessionTokenTtl() {
try {
SessionSpec.builder().build();
} catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), containsString("clientSessionTokenTtl"));
}
}

@Test
public void shouldRaiseForMissingResourcesTtl() {
try {
SessionSpec.builder()
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
.build();
} catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), containsString("resourcesTtl"));
}
}

@Test
public void shouldRaiseForMissingUserTrackingId() {
try {
SessionSpec.builder()
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
.withResourcesTtl(SOME_RESOURCES_TTL)
.build();
} catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), containsString("userTrackingId"));
}
}

@Test
Expand All @@ -124,18 +120,14 @@ public void shouldBuildWithValidNotifications() {

@Test
public void shouldBuildWithValidRequestedChecks() {
RequestedDocumentAuthenticityCheck authenticityCheck = RequestedDocumentAuthenticityCheck.builder()
.build();
RequestedDocumentAuthenticityCheck authenticityCheck = RequestedDocumentAuthenticityCheck.builder().build();

RequestedLivenessCheck livenessCheck = RequestedLivenessCheck.builder()
.forZoomLiveness()
.withMaxRetries(3)
.build();

SessionSpec result = SessionSpec.builder()
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
.withResourcesTtl(SOME_RESOURCES_TTL)
.withUserTrackingId(SOME_USER_TRACKING_ID)
.withRequestedCheck(authenticityCheck)
.withRequestedCheck(livenessCheck)
.build();
Expand All @@ -152,9 +144,6 @@ public void shouldBuildWithValidRequestedTasks() {
.build();

SessionSpec result = SessionSpec.builder()
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
.withResourcesTtl(SOME_RESOURCES_TTL)
.withUserTrackingId(SOME_USER_TRACKING_ID)
.withRequestedTask(textExtractionTask)
.build();

Expand All @@ -176,13 +165,9 @@ public void shouldBuildWithValidSdkConfig() {
.build();

SessionSpec result = SessionSpec.builder()
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
.withResourcesTtl(SOME_RESOURCES_TTL)
.withUserTrackingId(SOME_USER_TRACKING_ID)
.withSdkConfig(sdkConfig)
.build();

assertThat(result.getSdkConfig(), is(notNullValue()));
assertThat(result.getSdkConfig().getAllowedCaptureMethods(), is("CAMERA_AND_UPLOAD"));
assertThat(result.getSdkConfig().getPrimaryColour(), is(SOME_SDK_CONFIG_PRIMARY_COLOUR));
assertThat(result.getSdkConfig().getSecondaryColour(), is(SOME_SDK_CONFIG_SECONDARY_COLOUR));
Expand Down Expand Up @@ -230,7 +215,7 @@ public void withSessionDeadline_shouldSetTheSessionDeadline() {
}

@Test
public void buildWithIdentityProfile() throws IOException {
public void shouldBuildWithIdentityProfileRequirements() throws IOException {
Map<String, Object> scheme = new HashMap<>();
scheme.put(IdentityProperty.TYPE, "A_TYPE");
scheme.put(IdentityProperty.OBJECTIVE, "AN_OBJECTIVE");
Expand Down Expand Up @@ -260,7 +245,7 @@ private static JsonNode toSessionSpecJson(Map<String, Object> obj) throws IOExce
}

@Test
public void buildWithSubject() throws IOException {
public void shouldBuildWithSubject() throws IOException {
Map<String, Object> subject = new HashMap<>();
subject.put(SubjectProperty.SUBJECT_ID, "A_SUBJECT_ID");

Expand Down Expand Up @@ -295,14 +280,6 @@ public void shouldBuildWithCreateIdentityProfilePreview() {
assertThat(sessionSpec.getCreateIdentityProfilePreview(), is(true));
}

@Test
public void shouldSetNullForCreateIdentityProfilePreviewWhenNotProvidedExplicitly() {
SessionSpec sessionSpec = SessionSpec.builder()
.build();

assertThat(sessionSpec.getCreateIdentityProfilePreview(), nullValue());
}

@Test
public void shouldBuildWithImportToken() {
SessionSpec sessionSpec = SessionSpec.builder()
Expand Down

0 comments on commit f57d819

Please sign in to comment.