Skip to content

Commit e5a6e86

Browse files
committed
NA: Straighten out a unit test
1 parent 8b913d3 commit e5a6e86

File tree

1 file changed

+37
-60
lines changed

1 file changed

+37
-60
lines changed

yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SessionSpecTest.java

Lines changed: 37 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
import static com.yoti.api.client.spi.remote.call.YotiConstants.DEFAULT_CHARSET;
44

55
import static org.hamcrest.MatcherAssert.assertThat;
6-
import static org.hamcrest.Matchers.*;
6+
import static org.hamcrest.Matchers.contains;
7+
import static org.hamcrest.Matchers.equalTo;
8+
import static org.hamcrest.Matchers.hasItems;
9+
import static org.hamcrest.Matchers.hasSize;
10+
import static org.hamcrest.Matchers.instanceOf;
11+
import static org.hamcrest.Matchers.is;
12+
import static org.hamcrest.Matchers.notNullValue;
13+
import static org.hamcrest.Matchers.nullValue;
714

815
import java.io.IOException;
916
import java.time.ZonedDateTime;
@@ -19,10 +26,10 @@
1926
import com.fasterxml.jackson.databind.JsonNode;
2027
import com.fasterxml.jackson.databind.ObjectMapper;
2128
import org.hamcrest.Matchers;
22-
import org.junit.*;
29+
import org.junit.Test;
2330
import org.junit.runner.RunWith;
24-
import org.mockito.*;
25-
import org.mockito.junit.*;
31+
import org.mockito.Mock;
32+
import org.mockito.junit.MockitoJUnitRunner;
2633

2734
@RunWith(MockitoJUnitRunner.class)
2835
public class SessionSpecTest {
@@ -53,51 +60,40 @@ public class SessionSpecTest {
5360

5461
@Test
5562
public void shouldBuildWithMinimalConfiguration() {
63+
SessionSpec result = SessionSpec.builder().build();
64+
65+
assertThat(result.getClientSessionTokenTtl(), is(nullValue()));
66+
assertThat(result.getSessionDeadline(), is(nullValue()));
67+
assertThat(result.getResourcesTtl(), is(nullValue()));
68+
assertThat(result.getImportToken(), is(nullValue()));
69+
assertThat(result.getUserTrackingId(), is(nullValue()));
70+
assertThat(result.getNotifications(), is(nullValue()));
71+
assertThat(result.getRequestedChecks(), hasSize(0));
72+
assertThat(result.getRequestedTasks(), hasSize(0));
73+
assertThat(result.getSdkConfig(), is(nullValue()));
74+
assertThat(result.getRequiredDocuments(), hasSize(0));
75+
assertThat(result.getBlockBiometricConsent(), is(nullValue()));
76+
assertThat(result.getIbvOptions(), is(nullValue()));
77+
assertThat(result.getIdentityProfile(), is(nullValue()));
78+
assertThat(result.getAdvancedIdentityProfileRequirements(), is(nullValue()));
79+
assertThat(result.getSubject(), is(nullValue()));
80+
assertThat(result.getResources(), is(nullValue()));
81+
assertThat(result.getCreateIdentityProfilePreview(), is(nullValue()));
82+
}
83+
84+
@Test
85+
public void shouldBuildWithSimpleValues() {
5686
SessionSpec result = SessionSpec.builder()
5787
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
5888
.withResourcesTtl(SOME_RESOURCES_TTL)
5989
.withUserTrackingId(SOME_USER_TRACKING_ID)
6090
.withBlockBiometricConsent(true)
6191
.build();
6292

63-
assertThat(result, is(instanceOf(SessionSpec.class)));
6493
assertThat(result.getClientSessionTokenTtl(), is(SOME_CLIENT_SESSION_TOKEN_TTL));
6594
assertThat(result.getResourcesTtl(), is(SOME_RESOURCES_TTL));
6695
assertThat(result.getUserTrackingId(), is(SOME_USER_TRACKING_ID));
6796
assertThat(result.getBlockBiometricConsent(), is(true));
68-
assertThat(result.getRequiredDocuments(), hasSize(0));
69-
}
70-
71-
@Test
72-
public void shouldRaiseForMissingClientSessionTokenTtl() {
73-
try {
74-
SessionSpec.builder().build();
75-
} catch (IllegalArgumentException ex) {
76-
assertThat(ex.getMessage(), containsString("clientSessionTokenTtl"));
77-
}
78-
}
79-
80-
@Test
81-
public void shouldRaiseForMissingResourcesTtl() {
82-
try {
83-
SessionSpec.builder()
84-
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
85-
.build();
86-
} catch (IllegalArgumentException ex) {
87-
assertThat(ex.getMessage(), containsString("resourcesTtl"));
88-
}
89-
}
90-
91-
@Test
92-
public void shouldRaiseForMissingUserTrackingId() {
93-
try {
94-
SessionSpec.builder()
95-
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
96-
.withResourcesTtl(SOME_RESOURCES_TTL)
97-
.build();
98-
} catch (IllegalArgumentException ex) {
99-
assertThat(ex.getMessage(), containsString("userTrackingId"));
100-
}
10197
}
10298

10399
@Test
@@ -124,18 +120,14 @@ public void shouldBuildWithValidNotifications() {
124120

125121
@Test
126122
public void shouldBuildWithValidRequestedChecks() {
127-
RequestedDocumentAuthenticityCheck authenticityCheck = RequestedDocumentAuthenticityCheck.builder()
128-
.build();
123+
RequestedDocumentAuthenticityCheck authenticityCheck = RequestedDocumentAuthenticityCheck.builder().build();
129124

130125
RequestedLivenessCheck livenessCheck = RequestedLivenessCheck.builder()
131126
.forZoomLiveness()
132127
.withMaxRetries(3)
133128
.build();
134129

135130
SessionSpec result = SessionSpec.builder()
136-
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
137-
.withResourcesTtl(SOME_RESOURCES_TTL)
138-
.withUserTrackingId(SOME_USER_TRACKING_ID)
139131
.withRequestedCheck(authenticityCheck)
140132
.withRequestedCheck(livenessCheck)
141133
.build();
@@ -152,9 +144,6 @@ public void shouldBuildWithValidRequestedTasks() {
152144
.build();
153145

154146
SessionSpec result = SessionSpec.builder()
155-
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
156-
.withResourcesTtl(SOME_RESOURCES_TTL)
157-
.withUserTrackingId(SOME_USER_TRACKING_ID)
158147
.withRequestedTask(textExtractionTask)
159148
.build();
160149

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

178167
SessionSpec result = SessionSpec.builder()
179-
.withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL)
180-
.withResourcesTtl(SOME_RESOURCES_TTL)
181-
.withUserTrackingId(SOME_USER_TRACKING_ID)
182168
.withSdkConfig(sdkConfig)
183169
.build();
184170

185-
assertThat(result.getSdkConfig(), is(notNullValue()));
186171
assertThat(result.getSdkConfig().getAllowedCaptureMethods(), is("CAMERA_AND_UPLOAD"));
187172
assertThat(result.getSdkConfig().getPrimaryColour(), is(SOME_SDK_CONFIG_PRIMARY_COLOUR));
188173
assertThat(result.getSdkConfig().getSecondaryColour(), is(SOME_SDK_CONFIG_SECONDARY_COLOUR));
@@ -230,7 +215,7 @@ public void withSessionDeadline_shouldSetTheSessionDeadline() {
230215
}
231216

232217
@Test
233-
public void buildWithIdentityProfile() throws IOException {
218+
public void shouldBuildWithIdentityProfileRequirements() throws IOException {
234219
Map<String, Object> scheme = new HashMap<>();
235220
scheme.put(IdentityProperty.TYPE, "A_TYPE");
236221
scheme.put(IdentityProperty.OBJECTIVE, "AN_OBJECTIVE");
@@ -260,7 +245,7 @@ private static JsonNode toSessionSpecJson(Map<String, Object> obj) throws IOExce
260245
}
261246

262247
@Test
263-
public void buildWithSubject() throws IOException {
248+
public void shouldBuildWithSubject() throws IOException {
264249
Map<String, Object> subject = new HashMap<>();
265250
subject.put(SubjectProperty.SUBJECT_ID, "A_SUBJECT_ID");
266251

@@ -295,14 +280,6 @@ public void shouldBuildWithCreateIdentityProfilePreview() {
295280
assertThat(sessionSpec.getCreateIdentityProfilePreview(), is(true));
296281
}
297282

298-
@Test
299-
public void shouldSetNullForCreateIdentityProfilePreviewWhenNotProvidedExplicitly() {
300-
SessionSpec sessionSpec = SessionSpec.builder()
301-
.build();
302-
303-
assertThat(sessionSpec.getCreateIdentityProfilePreview(), nullValue());
304-
}
305-
306283
@Test
307284
public void shouldBuildWithImportToken() {
308285
SessionSpec sessionSpec = SessionSpec.builder()

0 commit comments

Comments
 (0)