1111import com .mindee .parsing .common .Document ;
1212import com .mindee .parsing .common .Job ;
1313import com .mindee .parsing .common .PredictResponse ;
14- import com .mindee .product . ProductTestHelper ;
14+ import static com .mindee .TestingUtilities . assertStringEqualsFile ;
1515import com .mindee .product .custom .CustomV1 ;
1616import com .mindee .product .generated .GeneratedV1 ;
1717import com .mindee .product .invoice .InvoiceV4 ;
3333import org .mockito .Mockito ;
3434import org .mockito .junit .jupiter .MockitoExtension ;
3535
36+ import static com .mindee .TestingUtilities .getResourcePath ;
37+ import static com .mindee .TestingUtilities .getV1ResourcePathString ;
38+
3639@ ExtendWith (MockitoExtension .class )
3740class MindeeClientTest {
3841
@@ -51,8 +54,6 @@ public void setUp() {
5154 void givenAClientForCustom_withFile_parse_thenShouldCallMindeeApi ()
5255 throws IOException {
5356
54- File file = new File ("src/test/resources/file_types/pdf/blank_1.pdf" );
55-
5657 PredictResponse predictResponse = new PredictResponse ();
5758 predictResponse .setDocument (new Document <>());
5859 predictResponse .setApiRequest (null );
@@ -64,7 +65,7 @@ void givenAClientForCustom_withFile_parse_thenShouldCallMindeeApi()
6465 .thenReturn (predictResponse );
6566
6667 PredictResponse <CustomV1 > document = client .parse (
67- new LocalInputSource (file ),
68+ new LocalInputSource (getResourcePath ( "file_types/pdf/blank_1.pdf" ) ),
6869 new Endpoint ("" , "" , "" ));
6970
7071 Assertions .assertNotNull (document );
@@ -76,7 +77,6 @@ void givenAClientForCustom_withFile_parse_thenShouldCallMindeeApi()
7677 void givenAClientForCustomAndPageOptions_parse_thenShouldOperateCutOnPagesAndCallTheHttpClientCorrectly ()
7778 throws IOException {
7879
79- File file = new File ("src/test/resources/file_types/pdf/multipage.pdf" );
8080 List <Integer > pageNumberToKeep = new ArrayList <>();
8181 pageNumberToKeep .add (1 );
8282
@@ -93,7 +93,7 @@ void givenAClientForCustomAndPageOptions_parse_thenShouldOperateCutOnPagesAndCal
9393 .thenReturn (new SplitPdf (new byte [0 ], 0 ));
9494
9595 PredictResponse <CustomV1 > document = client .parse (
96- new LocalInputSource (file ),
96+ new LocalInputSource (getResourcePath ( "file_types/pdf/multipage.pdf" ) ),
9797 new Endpoint ("" , "" , "" ),
9898 new PageOptions (
9999 pageNumberToKeep , PageOptionsOperation .KEEP_ONLY , 0 ));
@@ -109,7 +109,6 @@ void givenAClientForCustomAndPageOptions_parse_thenShouldOperateCutOnPagesAndCal
109109 void givenAClientForInvoice_withFile_parse_thenShouldCallMindeeApi ()
110110 throws IOException {
111111
112- File file = new File ("src/test/resources/file_types/pdf/blank_1.pdf" );
113112 PredictResponse predictResponse = new PredictResponse ();
114113 predictResponse .setDocument (new Document <>());
115114 predictResponse .setApiRequest (null );
@@ -123,7 +122,7 @@ void givenAClientForInvoice_withFile_parse_thenShouldCallMindeeApi()
123122
124123 PredictResponse <InvoiceV4 > document = client .parse (
125124 InvoiceV4 .class ,
126- new LocalInputSource (file ));
125+ new LocalInputSource (getResourcePath ( "file_types/pdf/blank_1.pdf" ) ));
127126
128127 Assertions .assertNotNull (document );
129128 Mockito .verify (mindeeApi , Mockito .times (1 ))
@@ -134,8 +133,6 @@ void givenAClientForInvoice_withFile_parse_thenShouldCallMindeeApi()
134133 void givenAClientForInvoice_withInputStream_parse_thenShouldCallMindeeApi ()
135134 throws IOException {
136135
137- File file = new File ("src/test/resources/file_types/pdf/blank_1.pdf" );
138-
139136 PredictResponse predictResponse = new PredictResponse ();
140137 predictResponse .setDocument (new Document <>());
141138 predictResponse .setApiRequest (null );
@@ -149,7 +146,7 @@ void givenAClientForInvoice_withInputStream_parse_thenShouldCallMindeeApi()
149146 PredictResponse <InvoiceV4 > document = client .parse (
150147 InvoiceV4 .class ,
151148 new LocalInputSource (
152- Files .newInputStream (file . toPath ( )),
149+ Files .newInputStream (getResourcePath ( "file_types/pdf/blank_1.pdf" )),
153150 "" ));
154151
155152 Assertions .assertNotNull (document );
@@ -161,7 +158,6 @@ void givenAClientForInvoice_withInputStream_parse_thenShouldCallMindeeApi()
161158 void givenAClientForInvoice_withByteArray_parse_thenShouldCallMindeeApi ()
162159 throws IOException {
163160
164- File file = new File ("src/test/resources/file_types/pdf/blank_1.pdf" );
165161 PredictResponse predictResponse = new PredictResponse ();
166162 predictResponse .setDocument (new Document <>());
167163 predictResponse .setApiRequest (null );
@@ -175,7 +171,7 @@ void givenAClientForInvoice_withByteArray_parse_thenShouldCallMindeeApi()
175171 PredictResponse <InvoiceV4 > document = client .parse (
176172 InvoiceV4 .class ,
177173 new LocalInputSource (
178- Files .readAllBytes (file . toPath ( )),
174+ Files .readAllBytes (getResourcePath ( "file_types/pdf/blank_1.pdf" )),
179175 "" ));
180176
181177 Assertions .assertNotNull (document );
@@ -187,7 +183,6 @@ void givenAClientForInvoice_withByteArray_parse_thenShouldCallMindeeApi()
187183 void givenAClientForInvoiceAndPageOptions_parse_thenShouldOperateCutOnPagesAndCallTheHttpClientCorrectly ()
188184 throws IOException {
189185
190- File file = new File ("src/test/resources/file_types/pdf/multipage.pdf" );
191186 List <Integer > pageNumberToKeep = new ArrayList <>();
192187 pageNumberToKeep .add (1 );
193188 PredictResponse predictResponse = new PredictResponse ();
@@ -206,7 +201,7 @@ void givenAClientForInvoiceAndPageOptions_parse_thenShouldOperateCutOnPagesAndCa
206201
207202 PredictResponse <InvoiceV4 > document = client .parse (
208203 InvoiceV4 .class ,
209- new LocalInputSource (file ),
204+ new LocalInputSource (getResourcePath ( "file_types/pdf/multipage.pdf" ) ),
210205 new PageOptions (
211206 pageNumberToKeep , PageOptionsOperation .KEEP_ONLY , 0 ));
212207
@@ -286,8 +281,9 @@ void givenACustomDocumentUrl_whenParsed_shouldCallApiWithCorrectParams() throws
286281 @ Test
287282 void givenAnAsyncDoc_whenEnqueued_shouldInvokeApiCorrectly () throws IOException {
288283
289- File file = new File ("src/test/resources/file_types/pdf/blank_1.pdf" );
290- LocalInputSource localInputSource = new LocalInputSource (file );
284+ LocalInputSource localInputSource = new LocalInputSource (
285+ getResourcePath ("file_types/pdf/blank_1.pdf" )
286+ );
291287
292288 Job job = new Job (LocalDateTime .now (), "someid" , LocalDateTime .now (), "Completed" , null );
293289 AsyncPredictResponse predictResponse = new AsyncPredictResponse ();
@@ -326,8 +322,9 @@ void givenAnAsyncDoc_whenEnqueued_shouldInvokeApiCorrectly() throws IOException
326322 @ Test
327323 void givenAnAsyncDoc_whenEnqueuedNoParams_shouldInvokeApiCorrectly () throws IOException {
328324
329- File file = new File ("src/test/resources/file_types/pdf/blank_1.pdf" );
330- LocalInputSource localInputSource = new LocalInputSource (file );
325+ LocalInputSource localInputSource = new LocalInputSource (
326+ getResourcePath ("file_types/pdf/blank_1.pdf" )
327+ );
331328
332329 Job job = new Job (LocalDateTime .now (), "someid" , LocalDateTime .now (), "Completed" , null );
333330 AsyncPredictResponse predictResponse = new AsyncPredictResponse ();
@@ -399,9 +396,9 @@ void givenAnAsyncUrl_whenEnqueued_shouldInvokeApiCorrectly() throws IOException
399396 @ Test
400397 void givenAnAsyncGeneratedDoc_whenEnqueuedNoParams_shouldInvokeApiCorrectly () throws IOException , InterruptedException {
401398
402- File file = new File ( "src/test/resources/file_types/pdf/blank_1.pdf" );
403- LocalInputSource localInputSource = new LocalInputSource ( file );
404-
399+ LocalInputSource localInputSource = new LocalInputSource (
400+ getResourcePath ( "file_types/pdf/blank_1.pdf" )
401+ );
405402 Job job = new Job (LocalDateTime .now (), "someid" , LocalDateTime .now (), "Completed" , null );
406403 Endpoint endpoint = new Endpoint ("dsddw" , "dcsdcd" , "dsfdd" );
407404 AsyncPredictResponse predictResponse = new AsyncPredictResponse ();
@@ -438,26 +435,26 @@ void givenAnAsyncGeneratedDoc_whenEnqueuedNoParams_shouldInvokeApiCorrectly() th
438435
439436 @ Test
440437 void givenJsonInput_whenSync_shouldDeserializeCorrectly () throws IOException {
441- File file = new File ("src/test/resources/ products/invoices/response_v4/complete.json" );
438+ File file = new File (getV1ResourcePathString ( " products/invoices/response_v4/complete.json") );
442439 LocalResponse localResponse = new LocalResponse (file );
443440 AsyncPredictResponse <InvoiceV4 > predictResponse = client .loadPrediction (InvoiceV4 .class , localResponse );
444- ProductTestHelper . assertStringEqualsFile (
441+ assertStringEqualsFile (
445442 predictResponse .getDocumentObj ().toString (),
446- "src/test/resources/ products/invoices/response_v4/summary_full.rst"
443+ getV1ResourcePathString ( "/ products/invoices/response_v4/summary_full.rst")
447444 );
448445 }
449446
450447 @ Test
451448 void givenJsonInput_whenAsync_shouldDeserializeCorrectly () throws IOException {
452- File file = new File ("src/test/resources/ products/international_id/response_v2/complete.json" );
449+ File file = new File (getV1ResourcePathString ( " products/international_id/response_v2/complete.json") );
453450 LocalResponse localResponse = new LocalResponse (file );
454451 AsyncPredictResponse <InternationalIdV2 > predictResponse = client .loadPrediction (
455452 InternationalIdV2 .class ,
456453 localResponse
457454 );
458- ProductTestHelper . assertStringEqualsFile (
455+ assertStringEqualsFile (
459456 predictResponse .getDocumentObj ().toString (),
460- "src/test/resources/ products/international_id/response_v2/summary_full.rst"
457+ getV1ResourcePathString ( " products/international_id/response_v2/summary_full.rst")
461458 );
462459 }
463460}
0 commit comments