@Test
    public void testSetGetAggregateTypes() throws Exception {
        StructDataType type = new StructDataType("teststr");
        type.addField(new Field("intarray", DataType.getArray(DataType.INT)));
        type.addField(new Field("strws", DataType.getWeightedSet(DataType.STRING)));

        Struct struct = new Struct(type);

        {
            //TEST USING OUR IMPLEMENTATION OF LIST
            Array integerArray = new Array(type.getField("intarray").getDataType());
            integerArray.add(new IntegerFieldValue(5));
            integerArray.add(new IntegerFieldValue(10));
            assertEquals(2, integerArray.size());
            struct.setFieldValue("intarray", integerArray);
            assertEquals(2, integerArray.size());
            List outList = (List) struct.getFieldValue("intarray");
            integerArray.add(new IntegerFieldValue(322));
            integerArray.add(new IntegerFieldValue(453));
            assertEquals(integerArray, outList);
            assertSame(integerArray, outList);
            assertEquals(4, integerArray.size());
            Array anotherArray = new Array(type.getField("intarray").getDataType());
            anotherArray.add(new IntegerFieldValue(5324));
            Object o = struct.setFieldValue("intarray", anotherArray);
            assertEquals(integerArray, o);
            assertSame(integerArray, o);
            outList = (List) struct.getFieldValue("intarray");
            assertFalse(integerArray.equals(outList));
            assertEquals(anotherArray, outList);
            assertSame(anotherArray, outList);
        }
        {
            WeightedSet<StringFieldValue> strWs = new WeightedSet<>(type.getField("strws").getDataType());
            strWs.put(new StringFieldValue("banana"), 10);
            strWs.add(new StringFieldValue("apple"));
            assertEquals(2, strWs.size());
            Object o = struct.setFieldValue("strws", strWs);
            assertNull(o);
            assertEquals(2, strWs.size());
            WeightedSet<StringFieldValue> outWs = (WeightedSet<StringFieldValue>) struct.getFieldValue("strws");
            strWs.add(new StringFieldValue("poison"));
            strWs.put(new StringFieldValue("pie"), 599);
            assertEquals(strWs, outWs);
            assertSame(strWs, outWs);
            assertEquals(4, strWs.size());
            WeightedSet anotherWs = new WeightedSet(type.getField("strws").getDataType());
            anotherWs.add(new StringFieldValue("be bop"));
            o = struct.setFieldValue("strws", anotherWs);
            assertEquals(strWs, o);
            assertSame(strWs, o);
            outWs = (WeightedSet<StringFieldValue>) struct.getFieldValue("strws");

            System.out.println("OutWS " + outWs);
            System.out.println("StrWS " + strWs);

            assertFalse(strWs.equals(outWs));
            assertEquals(anotherWs, outWs);
            assertSame(anotherWs, outWs);
        }
    }
@author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
document/src/test/java/com/yahoo/document/datatypes/StructTestCase.java