@Test
    public void testBasicStuff() throws Exception {
        StructDataType type = new StructDataType("teststr");
        type.addField(new Field("int", 0, DataType.INT));
        type.addField(new Field("flt", 1, DataType.FLOAT));
        type.addField(new Field("str", 2, DataType.STRING));
        type.addField(new Field("raw", 3, DataType.RAW));
        type.addField(new Field("lng", 4, DataType.LONG));
        type.addField(new Field("dbl", 5, DataType.DOUBLE));
        type.addField(new Field("uri", 6, DataType.URI));
        type.addField(new Field("byt", 8, DataType.BYTE));

        Struct struct = new Struct(type);
        {
            //add and remove again:
            assertEquals(0, struct.getFields().size());
            IntegerFieldValue ifv = new IntegerFieldValue(5);
            struct.setFieldValue("int", ifv);
            assertEquals(1, struct.getFields().size());
            struct.removeFieldValue("int");
            assertEquals(0, struct.getFields().size());
        }

        {
            //add three elements and remove one of them, and replace the last one:
            assertEquals(0, struct.getFields().size());

            IntegerFieldValue ifv = new IntegerFieldValue(5);
            struct.setFieldValue("int", ifv);
            assertEquals(1, struct.getFields().size());

            FloatFieldValue ffv = new FloatFieldValue(5.0f);
            struct.setFieldValue("flt", ffv);
            assertEquals(2, struct.getFields().size());

            DoubleFieldValue dfv = new DoubleFieldValue(6.0d);
            struct.setFieldValue("dbl", dfv);
            assertEquals(3, struct.getFields().size());

            Iterator<Map.Entry<Field, FieldValue>> it = struct.iterator();
            assertSame(ifv, it.next().getValue());
            assertSame(ffv, it.next().getValue());
            assertSame(dfv, it.next().getValue());
            assertFalse(it.hasNext());

            struct.removeFieldValue("flt");
            assertEquals(2, struct.getFields().size());

            it = struct.iterator();
            assertSame(ifv, it.next().getValue());
            assertSame(dfv, it.next().getValue());
            assertFalse(it.hasNext());

            DoubleFieldValue dfv2 = new DoubleFieldValue(9.0d);
            struct.setFieldValue("dbl", dfv2);
            assertEquals(2, struct.getFields().size());

            it = struct.iterator();
            assertSame(ifv, it.next().getValue());
            assertSame(dfv2, it.next().getValue());
            assertFalse(it.hasNext());
        }
    }
@author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
document/src/test/java/com/yahoo/document/datatypes/StructTestCase.java