Skip to content

Commit 29163cf

Browse files
committed
add a basic test for subfields
1 parent 91bb20a commit 29163cf

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/test/java/com/mindee/parsing/v2/InferenceTest.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ void deepNestedFields_mustExposeCorrectTypes() throws IOException {
190190
@DisplayName("standard_field_types.json")
191191
class StandardFieldTypes {
192192

193+
private void testSimpleFieldString(SimpleField field) {
194+
assertNotNull(field);
195+
assertEquals(field.getValue(), field.getStringValue());
196+
assertThrows(ClassCastException.class, field::getDoubleValue);
197+
assertThrows(ClassCastException.class, field::getBooleanValue);
198+
assertInstanceOf(List.class, field.getLocations());
199+
}
200+
193201
@Test
194202
@DisplayName("simple fields must be recognised")
195203
void standardFieldTypes_mustExposeSimpleFieldValues() throws IOException {
@@ -202,13 +210,8 @@ void standardFieldTypes_mustExposeSimpleFieldValues() throws IOException {
202210
assertNotNull(fields.get("field_simple_string").getSimpleField());
203211

204212
SimpleField fieldSimpleString = fields.get("field_simple_string").getSimpleField();
205-
assertNotNull(fieldSimpleString);
206-
assertInstanceOf(String.class, fieldSimpleString.getValue());
207-
assertEquals(fieldSimpleString.getValue(), fieldSimpleString.getStringValue());
208-
assertThrows(ClassCastException.class, fieldSimpleString::getDoubleValue);
209-
assertThrows(ClassCastException.class, fieldSimpleString::getBooleanValue);
213+
testSimpleFieldString(fieldSimpleString);
210214
assertEquals(FieldConfidence.Certain, fieldSimpleString.getConfidence());
211-
assertInstanceOf(List.class, fieldSimpleString.getLocations());
212215
assertEquals(1, fieldSimpleString.getLocations().size());
213216

214217
SimpleField fieldSimpleFloat = fields.get("field_simple_float").getSimpleField();
@@ -285,6 +288,11 @@ void standardFieldTypes_mustExposeSimpleListFieldValues() throws IOException {
285288
assertThrows(IllegalStateException.class, listField::getObjectItems);
286289
}
287290

291+
private void testObjectSubFieldSimpleString(String fieldName, SimpleField subField) {
292+
assertTrue(fieldName.startsWith("subfield_"));
293+
testSimpleFieldString(subField);
294+
}
295+
288296
@Test
289297
@DisplayName("object list fields must be recognised")
290298
void standardFieldTypes_mustExposeObjectListFieldValues() throws IOException {
@@ -326,8 +334,9 @@ void standardFieldTypes_mustExposeObjectListFieldValues() throws IOException {
326334
SimpleField itemSubfield1 = itemSubFields.getSimpleField("subfield_1");
327335
assertInstanceOf(String.class, itemSubfield1.getValue());
328336
for (Map.Entry<String, SimpleField> entry : itemFields.entrySet()) {
337+
String fieldName = entry.getKey();
329338
SimpleField subfield = entry.getValue();
330-
assertEquals(subfield.getValue(), subfield.getStringValue());
339+
testObjectSubFieldSimpleString(fieldName, subfield);
331340
}
332341
}
333342

@@ -354,6 +363,7 @@ void standardFieldTypes_mustExposeObjectFieldValues() throws IOException {
354363
for (Map.Entry<String, DynamicField> entry : subFieldsDynamic.entrySet()) {
355364
String fieldName = entry.getKey();
356365
SimpleField subField = entry.getValue().getSimpleField();
366+
testObjectSubFieldSimpleString(fieldName, subField);
357367
}
358368

359369
LinkedHashMap<String, SimpleField> subFieldsSimple = fieldObject.getSimpleFields();
@@ -363,6 +373,7 @@ void standardFieldTypes_mustExposeObjectFieldValues() throws IOException {
363373
for (Map.Entry<String, SimpleField> entry : subFieldsSimple.entrySet()) {
364374
String fieldName = entry.getKey();
365375
SimpleField subField = entry.getValue();
376+
testObjectSubFieldSimpleString(fieldName, subField);
366377
}
367378
}
368379
}

0 commit comments

Comments
 (0)