### Question:
UnionStructObjectInspector extends StructObjectInspector { protected UnionStructObjectInspector( List<StructObjectInspector> unionObjectInspectors) { init(unionObjectInspectors); } protected  UnionStructObjectInspector(
      List<StructObjectInspector> unionObjectInspectors); @Override final Category getCategory(); @Override String getTypeName(); @Override StructField getStructFieldRef(String fieldName); @Override List<? extends StructField> getAllStructFieldRefs(); @Override @SuppressWarnings("unchecked") Object getStructFieldData(Object data, StructField fieldRef); @Override @SuppressWarnings("unchecked") List<Object> getStructFieldsDataAsList(Object data);  }### Answer:
@Test public void testUnionStructObjectInspector() throws Throwable { try { ArrayList<String> fieldNames1 = new ArrayList<>(); fieldNames1.add("firstInteger"); fieldNames1.add("secondString"); fieldNames1.add("thirdBoolean"); ArrayList<ObjectInspector> fieldObjectInspectors1 = new ArrayList<>(); fieldObjectInspectors1 .add(PrimitiveObjectInspectorFactory.javaIntObjectInspector); fieldObjectInspectors1 .add(PrimitiveObjectInspectorFactory.javaStringObjectInspector); fieldObjectInspectors1 .add(PrimitiveObjectInspectorFactory.javaBooleanObjectInspector); StandardStructObjectInspector soi1 = ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames1, fieldObjectInspectors1); ArrayList<String> fieldNames2 = new ArrayList<>(); fieldNames2.add("fourthDouble"); fieldNames2.add("fifthLong"); ArrayList<ObjectInspector> fieldObjectInspectors2 = new ArrayList<>(); fieldObjectInspectors2 .add(PrimitiveObjectInspectorFactory.javaDoubleObjectInspector); fieldObjectInspectors2 .add(PrimitiveObjectInspectorFactory.javaLongObjectInspector); StandardStructObjectInspector soi2 = ObjectInspectorFactory .getStandardStructObjectInspector(fieldNames2, fieldObjectInspectors2); UnionStructObjectInspector usoi1 = ObjectInspectorFactory.getUnionStructObjectInspector( Arrays.asList(new StructObjectInspector[] {soi1, soi2})); UnionStructObjectInspector usoi2 = ObjectInspectorFactory.getUnionStructObjectInspector( Arrays.asList(new StructObjectInspector[] {soi1, soi2})); Assert.assertEquals(usoi1, usoi2); Assert.assertEquals(Category.STRUCT, usoi1.getCategory()); List<? extends StructField> fields = usoi1.getAllStructFieldRefs(); Assert.assertEquals(5, fields.size()); for (int i = 0; i < 5; i++) { if (i <= 2) { Assert.assertEquals(fieldNames1.get(i).toLowerCase(), fields.get(i) .getFieldName()); Assert.assertEquals(fieldObjectInspectors1.get(i), fields.get(i) .getFieldObjectInspector()); } else { Assert.assertEquals(fieldNames2.get(i - 3).toLowerCase(), fields.get(i) .getFieldName()); Assert.assertEquals(fieldObjectInspectors2.get(i - 3), fields.get(i) .getFieldObjectInspector()); } } Assert.assertEquals(fields.get(1), usoi1.getStructFieldRef("secondString")); Assert.assertEquals(fields.get(4), usoi1.getStructFieldRef("fifthLong")); for (int i = 0; i < 5; i++) { Assert.assertNull(usoi1.getStructFieldData(null, fields.get(i))); } ArrayList<Object> struct1 = new ArrayList<>(3); struct1.add(1); struct1.add("two"); struct1.add(true); ArrayList<Object> struct2 = new ArrayList<>(2); struct2.add(1.0); struct2.add(111); ArrayList<Object> struct = new ArrayList<>(2); struct.add(struct1); struct.add(struct2); ArrayList<Object> all = new ArrayList<>(5); all.addAll(struct1); all.addAll(struct2); for (int i = 0; i < 5; i++) { Assert.assertEquals(all.get(i), usoi1 .getStructFieldData(struct, fields.get(i))); } } catch (Throwable e) { e.printStackTrace(); throw e; } }