1616import com .mindee .parsing .v2 .field .ObjectField ;
1717import com .mindee .parsing .v2 .field .SimpleField ;
1818import java .io .IOException ;
19+ import java .math .BigDecimal ;
1920import java .util .HashMap ;
2021import java .util .LinkedHashMap ;
2122import java .util .List ;
@@ -93,51 +94,52 @@ class CompletePredictionTest {
9394 void asyncPredict_whenComplete_mustExposeAllProperties () throws IOException {
9495 InferenceResponse response = loadInference ("products/financial_document/complete.json" );
9596 Inference inference = response .getInference ();
96- assertNotNull (inference , "Inference must not be null" );
97- assertEquals (
98- "12345678-1234-1234-1234-123456789abc" ,
99- inference .getId (),
100- "Inference ID mismatch"
101- );
97+ assertNotNull (inference );
98+ assertEquals ("12345678-1234-1234-1234-123456789abc" , inference .getId ());
10299
103100 InferenceModel model = inference .getModel ();
104101 assertNotNull (model , "Model must not be null" );
105- assertEquals ("12345678-1234-1234-1234-123456789abc" , model .getId (), "Model ID mismatch" );
102+ assertEquals ("12345678-1234-1234-1234-123456789abc" , model .getId ());
106103
107104 InferenceFile file = inference .getFile ();
108- assertNotNull (file , "File must not be null" );
109- assertEquals ("complete.jpg" , file .getName (), "File name mismatch" );
110- assertEquals (1 , file .getPageCount (), "Page count mismatch" );
111- assertEquals ("image/jpeg" , file .getMimeType (), "MIME type mismatch" );
112- assertNull (file .getAlias (), "File alias must be null for this payload" );
105+ assertNotNull (file );
106+ assertEquals ("complete.jpg" , file .getName ());
107+ assertEquals (1 , file .getPageCount ());
108+ assertEquals ("image/jpeg" , file .getMimeType ());
109+ assertNull (file .getAlias ());
113110
114111 InferenceFields fields = inference .getResult ().getFields ();
115- assertEquals (21 , fields .size (), "Expected 21 fields in the payload" );
112+ assertEquals (21 , fields .size ());
116113
117114 SimpleField date = fields .get ("date" ).getSimpleField ();
118- assertEquals ("2019-11-02" , date .getValue (), "'date' value mismatch" );
115+ assertEquals ("2019-11-02" , date .getValue ());
119116
117+ // list of objects
120118 DynamicField taxes = fields .get ("taxes" );
121- assertNotNull (taxes , "'taxes' field must exist" );
119+ assertNotNull (taxes );
122120 ListField taxesList = taxes .getListField ();
123- assertNotNull (taxesList , "'taxes' must be a ListField" );
124- assertEquals (1 , taxesList .getItems ().size (), "'taxes' list must contain exactly one item" );
121+ assertNotNull (taxesList );
122+ assertEquals (1 , taxesList .getItems ().size ());
125123 ObjectField taxItemObj = taxesList .getItems ().get (0 ).getObjectField ();
126- assertNotNull (taxItemObj , "First item of 'taxes' must be an ObjectField" );
127- assertEquals (3 , taxItemObj .getFields ().size (), "Tax ObjectField must contain 3 sub-fields" );
124+ assertNotNull (taxItemObj );
125+ assertEquals (3 , taxItemObj .getFields ().size ());
128126 SimpleField baseTax = taxItemObj .getFields ().get ("base" ).getSimpleField ();
129- assertEquals (31.5 , baseTax .getValue (), "'taxes.base' value mismatch" );
130- assertNotNull (taxes .toString (), "'taxes'.toString() must not be null" );
127+ assertEquals (31.5 , baseTax .getValue ());
128+ assertEquals (31.5 , baseTax .getDoubleValue ());
129+ assertEquals (BigDecimal .valueOf (31.5 ), baseTax .getBigDecimalValue ());
130+ assertNotNull (taxes .toString ());
131131
132+ // single object
132133 DynamicField supplierAddress = fields .get ("supplier_address" );
133- assertNotNull (supplierAddress , "'supplier_address' field must exist" );
134+ assertNotNull (supplierAddress );
134135 ObjectField supplierObj = supplierAddress .getObjectField ();
135- assertNotNull (supplierObj , "'supplier_address' must be an ObjectField" );
136+ assertEquals (9 , supplierObj .getFields ().size ());
137+ assertNotNull (supplierObj );
136138 DynamicField country = supplierObj .getFields ().get ("country" );
137- assertNotNull (country , "'supplier_address.country' must exist" );
138- assertEquals ("USA" , country .getSimpleField ().getValue (), "Country mismatch" );
139- assertEquals ("USA" , country .toString (), "'country'.toString() mismatch" );
140- assertNotNull (supplierAddress .toString (), "'supplier_address'.toString() must not be null" );
139+ assertNotNull (country );
140+ assertEquals ("USA" , country .getSimpleField ().getValue ());
141+ assertEquals ("USA" , country .toString ());
142+ assertNotNull (supplierAddress .toString ());
141143
142144 ObjectField customerAddr = fields .get ("customer_address" ).getObjectField ();
143145 SimpleField city = customerAddr .getFields ().get ("city" ).getSimpleField ();
@@ -214,7 +216,7 @@ void standardFieldTypes_mustExposeSimpleFieldValues() throws IOException {
214216
215217 assertNotNull (fields .get ("field_simple_string" ).getSimpleField ());
216218
217- SimpleField fieldSimpleString = fields .get ("field_simple_string" ). getSimpleField ( );
219+ SimpleField fieldSimpleString = fields .getSimpleField ("field_simple_string" );
218220 testSimpleFieldString (fieldSimpleString );
219221 assertEquals (FieldConfidence .Certain , fieldSimpleString .getConfidence ());
220222 assertEquals (1 , fieldSimpleString .getLocations ().size ());
@@ -232,25 +234,32 @@ void standardFieldTypes_mustExposeSimpleFieldValues() throws IOException {
232234 assertInstanceOf (Double .class , fieldSimpleInt .getValue ());
233235 assertEquals (fieldSimpleInt .getValue (), fieldSimpleInt .getDoubleValue ());
234236 assertEquals (FieldConfidence .Medium , fieldSimpleInt .getConfidence ());
237+ assertThrows (ClassCastException .class , fieldSimpleInt ::getStringValue );
235238
236239 SimpleField fieldSimpleZero = fields .get ("field_simple_zero" ).getSimpleField ();
237240 assertNotNull (fieldSimpleZero );
238241 assertEquals (FieldConfidence .Low , fieldSimpleZero .getConfidence ());
239242 assertInstanceOf (Double .class , fieldSimpleZero .getValue ());
243+ assertEquals (0.0 , fieldSimpleZero .getDoubleValue ());
244+ assertEquals (BigDecimal .valueOf (0.0 ), fieldSimpleZero .getBigDecimalValue ());
245+ assertThrows (ClassCastException .class , fieldSimpleZero ::getStringValue );
246+ assertThrows (ClassCastException .class , fieldSimpleZero ::getBooleanValue );
240247
241248 SimpleField fieldSimpleBool = fields .get ("field_simple_bool" ).getSimpleField ();
242249 assertNotNull (fieldSimpleBool );
243250 assertInstanceOf (Boolean .class , fieldSimpleBool .getValue ());
244251 assertEquals (fieldSimpleBool .getValue (), fieldSimpleBool .getBooleanValue ());
245252 assertThrows (ClassCastException .class , fieldSimpleBool ::getStringValue );
246253 assertThrows (ClassCastException .class , fieldSimpleBool ::getDoubleValue );
254+ assertThrows (ClassCastException .class , fieldSimpleBool ::getBigDecimalValue );
247255
248256 SimpleField fieldSimpleNull = fields .get ("field_simple_null" ).getSimpleField ();
249257 assertNotNull (fieldSimpleNull );
250258 assertNull (fieldSimpleNull .getValue ());
251259 assertNull (fieldSimpleNull .getStringValue ());
252260 assertNull (fieldSimpleNull .getBooleanValue ());
253261 assertNull (fieldSimpleNull .getDoubleValue ());
262+ assertNull (fieldSimpleNull .getBigDecimalValue ());
254263 }
255264
256265 @ Test
0 commit comments