66import static org .junit .jupiter .api .Assertions .assertNotNull ;
77
88import com .mindee .input .LocalResponse ;
9+ import com .mindee .parsing .v2 .InferenceResponse ;
910import com .mindee .v2 .product .crop .CropItem ;
1011import com .mindee .v2 .product .crop .CropResponse ;
1112import java .io .IOException ;
@@ -25,18 +26,18 @@ private CropResponse loadResponse(String filePath) throws IOException {
2526 @ DisplayName ("Result with single value" )
2627 class SinglePredictionTest {
2728 @ Test
28- @ DisplayName ("all properties must be valid" )
29+ @ DisplayName ("crop properties must be valid" )
2930 void mustHaveValidProperties () throws IOException {
3031 CropResponse response = loadResponse ("products/crop/crop_single.json" );
3132 assertNotNull (response .getInference ());
3233
3334 ArrayList <CropItem > crops = response .getInference ().getResult ().getCrops ();
3435 assertEquals (1 , crops .size ());
3536
36- CropItem crop1 = crops .get (0 );
37- assertEquals ("invoice" , crop1 .getObjectType ());
38- assertNotNull (crop1 .getLocation ().getPolygon ());
39- assertEquals (0 , crop1 .getLocation ().getPage ());
37+ CropItem crop0 = crops .get (0 );
38+ assertEquals ("invoice" , crop0 .getObjectType ());
39+ assertNotNull (crop0 .getLocation ().getPolygon ());
40+ assertEquals (0 , crop0 .getLocation ().getPage ());
4041 }
4142
4243 @ Test
@@ -54,23 +55,23 @@ void mustHaveValidDisplay() throws IOException {
5455 @ DisplayName ("Result with multiple values" )
5556 class MultiPredictionTest {
5657 @ Test
57- @ DisplayName ("all properties must be valid" )
58+ @ DisplayName ("crop properties must be valid" )
5859 void mustHaveValidProperties () throws IOException {
5960 CropResponse response = loadResponse ("products/crop/crop_multiple.json" );
6061 assertNotNull (response .getInference ());
6162
6263 ArrayList <CropItem > crops = response .getInference ().getResult ().getCrops ();
6364 assertEquals (2 , crops .size ());
6465
65- CropItem crop1 = crops .get (0 );
66- assertEquals ("invoice" , crop1 .getObjectType ());
66+ CropItem crop0 = crops .get (0 );
67+ assertEquals ("invoice" , crop0 .getObjectType ());
68+ assertNotNull (crop0 .getLocation ().getPolygon ());
69+ assertEquals (0 , crop0 .getLocation ().getPage ());
70+
71+ CropItem crop1 = crops .get (1 );
72+ assertEquals ("receipt" , crop1 .getObjectType ());
6773 assertNotNull (crop1 .getLocation ().getPolygon ());
6874 assertEquals (0 , crop1 .getLocation ().getPage ());
69-
70- CropItem crop2 = crops .get (1 );
71- assertEquals ("receipt" , crop2 .getObjectType ());
72- assertNotNull (crop2 .getLocation ().getPolygon ());
73- assertEquals (0 , crop2 .getLocation ().getPage ());
7475 }
7576
7677 @ Test
@@ -82,5 +83,47 @@ void mustHaveValidDisplay() throws IOException {
8283 getV2ResourcePath ("products/crop/crop_multiple.rst" )
8384 );
8485 }
86+
87+ @ Test
88+ @ DisplayName ("extraction properties must be valid" )
89+ void extractionMustHaveValidProperties () throws IOException {
90+ CropResponse response = loadResponse ("products/crop/default_sample_extraction.json" );
91+ assertNotNull (response .getInference ());
92+
93+ ArrayList <CropItem > crops = response .getInference ().getResult ().getCrops ();
94+ assertEquals (2 , crops .size ());
95+
96+ CropItem crop0 = crops .get (0 );
97+ assertEquals ("receipt" , crop0 .getObjectType ());
98+ assertNotNull (crop0 .getLocation ().getPolygon ());
99+ assertEquals (0 , crop0 .getLocation ().getPage ());
100+ InferenceResponse extractionResponse0 = crop0 .getExtractionResponse ();
101+ assertNotNull (extractionResponse0 );
102+ assertEquals (
103+ "CHEZ ALAIN MIAM MIAM" ,
104+ extractionResponse0
105+ .getInference ()
106+ .getResult ()
107+ .getFields ()
108+ .getSimpleField ("supplier_name" )
109+ .getValue ()
110+ );
111+
112+ CropItem crop1 = crops .get (1 );
113+ assertEquals ("receipt" , crop1 .getObjectType ());
114+ assertNotNull (crop1 .getLocation ().getPolygon ());
115+ assertEquals (0 , crop1 .getLocation ().getPage ());
116+ InferenceResponse extractionResponse1 = crop1 .getExtractionResponse ();
117+ assertNotNull (extractionResponse1 );
118+ assertEquals (
119+ "La cerise sur la pizza" ,
120+ extractionResponse1
121+ .getInference ()
122+ .getResult ()
123+ .getFields ()
124+ .getSimpleField ("supplier_name" )
125+ .getValue ()
126+ );
127+ }
85128 }
86129}
0 commit comments