|
5 | 5 | import static org.hamcrest.Matchers.instanceOf;
|
6 | 6 | import static org.hamcrest.Matchers.is;
|
7 | 7 | import static org.junit.Assert.assertThrows;
|
8 |
| -import static org.junit.Assert.fail; |
9 | 8 | import static org.mockito.ArgumentMatchers.any;
|
10 | 9 | import static org.mockito.ArgumentMatchers.eq;
|
11 | 10 | import static org.mockito.Mockito.doThrow;
|
@@ -49,194 +48,142 @@ public void setUp() {
|
49 | 48 | public void constructor_shouldFailWhenStreamExceptionLoadingKeys() {
|
50 | 49 | KeyPairSource badKeyPairSource = new StaticKeyPairSource(true);
|
51 | 50 |
|
52 |
| - try { |
53 |
| - new DocScanClient(APP_ID, badKeyPairSource, docScanServiceMock); |
54 |
| - } catch (InitialisationException e) { |
55 |
| - assertThat(e.getCause(), is(instanceOf(IOException.class))); |
56 |
| - assertThat(e.getCause().getMessage(), containsString("Test stream exception")); |
57 |
| - return; |
58 |
| - } |
59 |
| - fail("Expected an Exception"); |
| 51 | + InitialisationException ex = assertThrows(InitialisationException.class, () -> new DocScanClient(APP_ID, badKeyPairSource, docScanServiceMock)); |
| 52 | + |
| 53 | + assertThat(ex.getCause(), is(instanceOf(IOException.class))); |
| 54 | + assertThat(ex.getCause().getMessage(), containsString("Test stream exception")); |
60 | 55 | }
|
61 | 56 |
|
62 | 57 | @Test
|
63 | 58 | public void createDocScanSession_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
64 | 59 | DocScanException original = new DocScanException("Test exception");
|
65 |
| - |
66 | 60 | when(docScanServiceMock.createSession(eq(APP_ID), any(KeyPair.class), eq(sessionSpecMock))).thenThrow(original);
|
| 61 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
| 62 | + |
| 63 | + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.createSession(sessionSpecMock)); |
67 | 64 |
|
68 |
| - try { |
69 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
70 |
| - testObj.createSession(sessionSpecMock); |
71 |
| - } catch (DocScanException thrown) { |
72 |
| - assertThat(thrown, is(original)); |
73 |
| - return; |
74 |
| - } |
75 |
| - fail("Expected an exception"); |
| 65 | + assertThat(thrown, is(original)); |
76 | 66 | }
|
77 | 67 |
|
78 | 68 | @Test
|
79 | 69 | public void getDocScanSession_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
80 | 70 | DocScanException original = new DocScanException("Test exception");
|
81 |
| - |
82 | 71 | when(docScanServiceMock.retrieveSession(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID))).thenThrow(original);
|
| 72 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
| 73 | + |
| 74 | + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.getSession(SOME_SESSION_ID)); |
83 | 75 |
|
84 |
| - try { |
85 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
86 |
| - testObj.getSession(SOME_SESSION_ID); |
87 |
| - } catch (DocScanException thrown) { |
88 |
| - assertThat(thrown, is(original)); |
89 |
| - return; |
90 |
| - } |
91 |
| - fail("Expected an exception"); |
| 76 | + assertThat(thrown, is(original)); |
92 | 77 | }
|
93 | 78 |
|
94 | 79 | @Test
|
95 | 80 | public void getDocScanMedia_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
96 | 81 | DocScanException original = new DocScanException("Test exception");
|
97 |
| - |
98 | 82 | when(docScanServiceMock.getMediaContent(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID), eq(SOME_MEDIA_ID))).thenThrow(original);
|
| 83 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
| 84 | + |
| 85 | + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.getMediaContent(SOME_SESSION_ID, SOME_MEDIA_ID)); |
99 | 86 |
|
100 |
| - try { |
101 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
102 |
| - testObj.getMediaContent(SOME_SESSION_ID, SOME_MEDIA_ID); |
103 |
| - } catch (DocScanException thrown) { |
104 |
| - assertThat(thrown, is(original)); |
105 |
| - return; |
106 |
| - } |
107 |
| - fail("Expected an exception"); |
| 87 | + assertThat(thrown, is(original)); |
108 | 88 | }
|
109 | 89 |
|
110 | 90 | @Test
|
111 | 91 | public void deleteDocScanMedia_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
112 | 92 | DocScanException original = new DocScanException("Test exception");
|
113 |
| - |
114 | 93 | doThrow(original).when(docScanServiceMock).deleteMediaContent(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID), eq(SOME_MEDIA_ID));
|
| 94 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
115 | 95 |
|
116 |
| - try { |
117 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
118 |
| - testObj.deleteMediaContent(SOME_SESSION_ID, SOME_MEDIA_ID); |
119 |
| - } catch (DocScanException thrown) { |
120 |
| - assertThat(thrown, is(original)); |
121 |
| - return; |
122 |
| - } |
123 |
| - fail("Expected an exception"); |
| 96 | + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.deleteMediaContent(SOME_SESSION_ID, SOME_MEDIA_ID)); |
| 97 | + |
| 98 | + assertThat(thrown, is(original)); |
124 | 99 | }
|
125 | 100 |
|
126 | 101 | @Test
|
127 | 102 | public void deleteDocScanSession_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
128 | 103 | DocScanException original = new DocScanException("Test exception");
|
129 |
| - |
130 | 104 | doThrow(original).when(docScanServiceMock).deleteSession(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID));
|
| 105 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
131 | 106 |
|
132 |
| - try { |
133 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
134 |
| - testObj.deleteSession(SOME_SESSION_ID); |
135 |
| - } catch (DocScanException thrown) { |
136 |
| - assertThat(thrown, is(original)); |
137 |
| - return; |
138 |
| - } |
139 |
| - fail("Expected an exception"); |
| 107 | + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.deleteSession(SOME_SESSION_ID)); |
| 108 | + |
| 109 | + assertThat(thrown, is(original)); |
140 | 110 | }
|
141 | 111 |
|
142 | 112 | @Test
|
143 | 113 | public void putIbvInstructions_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
144 | 114 | DocScanException original = new DocScanException("Test exception");
|
145 |
| - |
146 | 115 | doThrow(original).when(docScanServiceMock).putIbvInstructions(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID), eq(instructionsMock));
|
| 116 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
147 | 117 |
|
148 |
| - DocScanException exception = assertThrows(DocScanException.class, () -> { |
149 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
150 |
| - testObj.putIbvInstructions(SOME_SESSION_ID, instructionsMock); |
151 |
| - }); |
| 118 | + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.putIbvInstructions(SOME_SESSION_ID, instructionsMock)); |
152 | 119 |
|
153 | 120 | assertThat(exception, is(original));
|
154 | 121 | }
|
155 | 122 |
|
156 | 123 | @Test
|
157 | 124 | public void getIbvInstructions_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
158 | 125 | DocScanException original = new DocScanException("Test exception");
|
159 |
| - |
160 | 126 | doThrow(original).when(docScanServiceMock).getIbvInstructions(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID));
|
| 127 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
161 | 128 |
|
162 |
| - DocScanException exception = assertThrows(DocScanException.class, () -> { |
163 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
164 |
| - testObj.getIbvInstructions(SOME_SESSION_ID); |
165 |
| - }); |
| 129 | + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.getIbvInstructions(SOME_SESSION_ID)); |
166 | 130 |
|
167 | 131 | assertThat(exception, is(original));
|
168 | 132 | }
|
169 | 133 |
|
170 | 134 | @Test
|
171 | 135 | public void getIbvInstructionsPdf_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
172 | 136 | DocScanException original = new DocScanException("Test exception");
|
173 |
| - |
174 | 137 | doThrow(original).when(docScanServiceMock).getIbvInstructionsPdf(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID));
|
| 138 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
175 | 139 |
|
176 |
| - DocScanException exception = assertThrows(DocScanException.class, () -> { |
177 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
178 |
| - testObj.getIbvInstructionsPdf(SOME_SESSION_ID); |
179 |
| - }); |
| 140 | + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.getIbvInstructionsPdf(SOME_SESSION_ID)); |
180 | 141 |
|
181 | 142 | assertThat(exception, is(original));
|
182 | 143 | }
|
183 | 144 |
|
184 | 145 | @Test
|
185 | 146 | public void fetchInstructionsContactProfile_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
186 | 147 | DocScanException original = new DocScanException("Test exception");
|
187 |
| - |
188 | 148 | doThrow(original).when(docScanServiceMock).fetchInstructionsContactProfile(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID));
|
| 149 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
189 | 150 |
|
190 |
| - DocScanException exception = assertThrows(DocScanException.class, () -> { |
191 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
192 |
| - testObj.fetchInstructionsContactProfile(SOME_SESSION_ID); |
193 |
| - }); |
| 151 | + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.fetchInstructionsContactProfile(SOME_SESSION_ID)); |
194 | 152 |
|
195 | 153 | assertThat(exception, is(original));
|
196 | 154 | }
|
197 | 155 |
|
198 | 156 | @Test
|
199 | 157 | public void triggerIbvEmailNotification_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
200 | 158 | DocScanException original = new DocScanException("Test exception");
|
201 |
| - |
202 | 159 | doThrow(original).when(docScanServiceMock).triggerIbvEmailNotification(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID));
|
| 160 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
203 | 161 |
|
204 |
| - DocScanException exception = assertThrows(DocScanException.class, () -> { |
205 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
206 |
| - testObj.triggerIbvEmailNotification(SOME_SESSION_ID); |
207 |
| - }); |
| 162 | + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.triggerIbvEmailNotification(SOME_SESSION_ID)); |
208 | 163 |
|
209 | 164 | assertThat(exception, is(original));
|
210 | 165 | }
|
211 |
| - |
| 166 | + |
212 | 167 | @Test
|
213 | 168 | public void getSessionConfiguration_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
214 | 169 | DocScanException original = new DocScanException("Test exception");
|
215 |
| - |
216 | 170 | doThrow(original).when(docScanServiceMock).fetchSessionConfiguration(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID));
|
| 171 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
217 | 172 |
|
218 |
| - DocScanException exception = assertThrows(DocScanException.class, () -> { |
219 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
220 |
| - testObj.getSessionConfiguration(SOME_SESSION_ID); |
221 |
| - }); |
| 173 | + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.getSessionConfiguration(SOME_SESSION_ID)); |
222 | 174 |
|
223 | 175 | assertThat(exception, is(original));
|
224 | 176 | }
|
225 | 177 |
|
226 | 178 | @Test
|
227 | 179 | public void getSupportedDocuments_shouldFailWithExceptionFromYotiDocsService() throws Exception {
|
228 | 180 | DocScanException original = new DocScanException("Test exception");
|
229 |
| - |
230 | 181 | doThrow(original).when(docScanServiceMock).getSupportedDocuments(any(KeyPair.class), any(Boolean.class));
|
| 182 | + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
| 183 | + |
| 184 | + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.getSupportedDocuments()); |
231 | 185 |
|
232 |
| - try { |
233 |
| - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); |
234 |
| - testObj.getSupportedDocuments(); |
235 |
| - } catch (DocScanException thrown) { |
236 |
| - assertThat(thrown, is(original)); |
237 |
| - return; |
238 |
| - } |
239 |
| - fail("Expected an exception"); |
| 186 | + assertThat(thrown, is(original)); |
240 | 187 | }
|
241 | 188 |
|
242 | 189 | }
|
0 commit comments