MethodUtil { public static String determineMutatorName(@Nonnull final String fieldName) { Check.notEmpty(fieldName, "fieldName"); final Matcher m = PATTERN.matcher(fieldName); Check.stateIsTrue(m.find(), "passed field name '%s' is not applicable", fieldName); final String name = m.group(); return METHOD_SET_PREFIX + name.substring(0, 1).toUpperCase() + name.substring(1); } private  MethodUtil(); static String determineAccessorName(@Nonnull final AccessorPrefix prefix, @Nonnull final String fieldName); static String determineMutatorName(@Nonnull final String fieldName);  }
@Test(expected = IllegalEmptyArgumentException.class) public void determineMutatorName_isEmpty() { MethodUtil.determineMutatorName(""); }
@Test(expected = IllegalNullArgumentException.class) public void determineMutatorName_isNull() { MethodUtil.determineMutatorName(null); }
@Test public void determineMutatorName_successful() { assertEquals("setField", MethodUtil.determineMutatorName("field")); assertEquals("setField", MethodUtil.determineMutatorName("_field")); assertEquals("setField", MethodUtil.determineMutatorName("__field")); assertEquals("setField", MethodUtil.determineMutatorName("__-field")); assertEquals("setField", MethodUtil.determineMutatorName("__-??field")); assertEquals("setField", MethodUtil.determineMutatorName("__-08978field")); assertEquals("setField", MethodUtil.determineMutatorName("_field_")); assertEquals("setField", MethodUtil.determineMutatorName("__field__")); assertEquals("setField", MethodUtil.determineMutatorName("__-field-__")); assertEquals("setField", MethodUtil.determineMutatorName("__-??field??-__")); assertEquals("setField123", MethodUtil.determineMutatorName("__-08978field123-___")); }
@Test(expected = IllegalStateOfArgumentException.class) public void determineMutatorName_wrongFieldName() { MethodUtil.determineMutatorName(" "); }