@@ -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 ();
@@ -266,8 +269,7 @@ void standardFieldTypes_mustExposeSimpleListFieldValues() throws IOException {
266269 assertInstanceOf (String .class , firstDynamicItem .getValue ());
267270 for (DynamicField item : dynamicItems ) {
268271 SimpleField itemField = item .getSimpleField ();
269- assertInstanceOf (String .class , itemField .getValue ());
270- assertEquals (itemField .getValue (), itemField .getStringValue ());
272+ testSimpleFieldString (itemField );
271273 assertEquals (1 , itemField .getLocations ().size ());
272274 }
273275
@@ -277,14 +279,18 @@ void standardFieldTypes_mustExposeSimpleListFieldValues() throws IOException {
277279 SimpleField firstSimpleItem = simpleItems .get (0 );
278280 assertEquals (FieldConfidence .Medium , firstSimpleItem .getConfidence ());
279281 for (SimpleField itemField : simpleItems ) {
280- assertInstanceOf (String .class , itemField .getValue ());
281- assertEquals (itemField .getValue (), itemField .getStringValue ());
282+ testSimpleFieldString (itemField );
282283 assertEquals (1 , itemField .getLocations ().size ());
283284 }
284285
285286 assertThrows (IllegalStateException .class , listField ::getObjectItems );
286287 }
287288
289+ private void testObjectSubFieldSimpleString (String fieldName , SimpleField subField ) {
290+ assertTrue (fieldName .startsWith ("subfield_" ));
291+ testSimpleFieldString (subField );
292+ }
293+
288294 @ Test
289295 @ DisplayName ("object list fields must be recognised" )
290296 void standardFieldTypes_mustExposeObjectListFieldValues () throws IOException {
@@ -326,8 +332,9 @@ void standardFieldTypes_mustExposeObjectListFieldValues() throws IOException {
326332 SimpleField itemSubfield1 = itemSubFields .getSimpleField ("subfield_1" );
327333 assertInstanceOf (String .class , itemSubfield1 .getValue ());
328334 for (Map .Entry <String , SimpleField > entry : itemFields .entrySet ()) {
335+ String fieldName = entry .getKey ();
329336 SimpleField subfield = entry .getValue ();
330- assertEquals ( subfield . getValue () , subfield . getStringValue () );
337+ testObjectSubFieldSimpleString ( fieldName , subfield );
331338 }
332339 }
333340
@@ -354,6 +361,7 @@ void standardFieldTypes_mustExposeObjectFieldValues() throws IOException {
354361 for (Map .Entry <String , DynamicField > entry : subFieldsDynamic .entrySet ()) {
355362 String fieldName = entry .getKey ();
356363 SimpleField subField = entry .getValue ().getSimpleField ();
364+ testObjectSubFieldSimpleString (fieldName , subField );
357365 }
358366
359367 LinkedHashMap <String , SimpleField > subFieldsSimple = fieldObject .getSimpleFields ();
@@ -363,6 +371,7 @@ void standardFieldTypes_mustExposeObjectFieldValues() throws IOException {
363371 for (Map .Entry <String , SimpleField > entry : subFieldsSimple .entrySet ()) {
364372 String fieldName = entry .getKey ();
365373 SimpleField subField = entry .getValue ();
374+ testObjectSubFieldSimpleString (fieldName , subField );
366375 }
367376 }
368377 }
0 commit comments