FieldValueTool { public static void cleanNonNegativeInteger(final Consumer<String> fieldSetter, final String newValue, final String oldValue) { String clean = getAsCleanNonNegativeInteger(oldValue, newValue); if (!clean.equals(newValue)) { fieldSetter.accept(clean); } } private  FieldValueTool(); static int getAsInteger(final Supplier<String> fieldGetter, final int defaultValue); static void applyDefaultIfEmpty(final Consumer<String> fieldSetter, final Supplier<String> fieldGetter, final Supplier<Object> defaultGetter); static void cleanNonNegativeInteger(final Consumer<String> fieldSetter, final String newValue, final String oldValue);  }
@Test public void testCleanNonNegativeIntegerUnchanged() { field.set("original"); FieldValueTool.cleanNonNegativeInteger(field::set, "123", "0"); assertEquals("original", field.get()); }
@Test public void testCleanNonNegativeIntegerEmpty() { field.set("original"); FieldValueTool.cleanNonNegativeInteger(field::set, "", "0"); assertEquals("original", field.get()); }
@Test public void testCleanNonNegativeIntegerBadValue() { field.set("original"); FieldValueTool.cleanNonNegativeInteger(field::set, "bad", "123"); assertEquals("123", field.get()); }
@Test public void testCleanNonNegativeIntegerNegativeValue() { field.set("original"); FieldValueTool.cleanNonNegativeInteger(field::set, "-1", "123"); assertEquals("123", field.get()); }