OnlyAttribute implements FactoryStyleValidation { @Override public Optional<String> validateFactory() { if (!Attribute.class.isAssignableFrom(attributeField.getType())) { return Optional.of("Factories should only contain attributes and no state: "+ factoryClass.getName()+"#"+attributeField.getName()); } return Optional.empty(); } OnlyAttribute(Class<? extends FactoryBase<?, ?>> factoryClass, Field attributeField); @Override Optional<String> validateFactory();  }
@Test public void test() throws NoSuchFieldException { Optional<String> result = new OnlyAttribute(OnlyAttributeFactory.class, OnlyAttributeFactory.class.getField("blub")).validateFactory(); Assertions.assertTrue(result.isPresent()); }
@Test public void test_negative() throws NoSuchFieldException { Optional<String> result = new OnlyAttribute(ExampleFactoryA.class,ExampleFactoryA.class.getField("stringAttribute")).validateFactory(); Assertions.assertFalse(result.isPresent()); }