LocaleAttributeValidation implements FactoryStyleValidation { @Override public Optional<String> validateFactory() { try { if (Strings.isNullOrEmpty(((Attribute<?, ?>) attributeField.get(factoryBase)).internal_getPreferredLabelText(locale))) { return Optional.of("locale: '" + locale + "' should be set: " + factoryBase.getClass().getName() + "#" + attributeField.getName()); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } return Optional.empty(); } LocaleAttributeValidation(FactoryBase<?,?> factoryBase, Field attributeField, Locale locale); @Override Optional<String> validateFactory();  }
@Test public void test() throws NoSuchFieldException { Optional<String> result = new LocaleAttributeValidation(new LocaleBrokenFactory(), LocaleBrokenFactory.class.getField("stringAttribute"), Locale.GERMAN).validateFactory(); Assertions.assertTrue(result.isPresent()); }
@Test public void test_negative() throws NoSuchFieldException { Optional<String> result = new LocaleAttributeValidation(new LocaleFactory(),LocaleFactory.class.getField("stringAttribute"), Locale.GERMAN).validateFactory(); Assertions.assertFalse(result.isPresent()); }