@Test
    public void testSetterValidation() {
        Book book = new Book(new DocumentId("id:book:book::0"));

        book.setAuthor("Herman Melville");
        assertEquals("The string field value contains illegal code point 0x16",
                     assertThrows(IllegalArgumentException.class,
                                  () -> book.setAuthor("He\u0016rman Malville")).getMessage());

        book.setRef(new DocumentId("id:ns:parent::foo"));
        assertEquals("Can't assign document ID 'id:ns:common::bar' (of type 'common') to reference of document type 'parent'",
                     assertThrows(IllegalArgumentException.class,
                                  () -> book.setRef(new DocumentId("id:ns:common::bar"))).getMessage());

        book.setStringmap(Map.of("foo", "bar"));
        assertEquals("The string field value contains illegal code point 0x16",
                     assertThrows(IllegalArgumentException.class,
                                  () -> book.setStringmap(Map.of("foo", "bar\u0016"))).getMessage());
        assertEquals("The string field value contains illegal code point 0x16",
                     assertThrows(IllegalArgumentException.class,
                                  () -> book.setStringmap(Map.of("bar\u0016", "foo"))).getMessage());
    }
Tests vespa-documentgen-plugin

@author vegardh
documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java