TargetPropertyWriterFactory { public TargetPropertyWriter getOrCreateWriter(String property) { return getOrCreateWriter(property, property, () -> NULL_WRITER); } TargetPropertyWriterFactory(Class<T> type, ObjEntity entity); TargetPropertyWriter getOrCreateWriter(String property); TargetPropertyWriter getOrCreateWriter(
            String propertyName,
            String dbName,
            Supplier<TargetPropertyWriter> defaultWriterSupplier);  }
@Test public void testGetOrCreateWriter_Null() { TargetPropertyWriterFactory<C1> factory = new TargetPropertyWriterFactory<>(C1.class, mock(ObjEntity.class)); assertThrows(NullPointerException.class, () -> factory.getOrCreateWriter("dummy", "dbDummy", () -> null)); }
@Test public void testGetOrCreateWriter_Default() { TargetPropertyWriter expected = (t, v) -> {}; TargetPropertyWriterFactory<C1> factory = new TargetPropertyWriterFactory<>(C1.class, mock(ObjEntity.class)); assertSame(expected, factory.getOrCreateWriter("dummy", "dbDummy", () -> expected)); assertSame(expected, factory.getOrCreateWriter("dummy", "dbDummy", () -> expected)); }
@Test public void testGetOrCreateWriter_Setter() { TargetPropertyWriter defaultWriter = (t, v) -> {}; TargetPropertyWriterFactory<C1> factory = new TargetPropertyWriterFactory<>(C1.class, mock(ObjEntity.class)); TargetPropertyWriter setter = factory.getOrCreateWriter("me", "dbDummy", () -> defaultWriter); assertNotSame(defaultWriter, setter); assertSame(setter, factory.getOrCreateWriter("me", "dbDummy", () -> defaultWriter)); }