BasicFormatRenderer implements AttributeRenderer { @Override public String toString(final Object o, final String formatName, final Locale locale) { Check.notNull(o, "o"); final String text = Check.instanceOf(String.class, o); String result = text; if (!text.trim().isEmpty() && formatName != null) { if (formatName.equals("toUpper")) { result = text.toUpperCase(); } else if (formatName.equals("toLower")) { result = text.toLowerCase(); } else if (formatName.equals("toUpperCamelCase")) { result = toUpperCamelCase(text); } else if (formatName.equals("toLowerCamelCase")) { result = toLowerCamelCase(text); } else { throw new IllegalStateOfArgumentException("Unsupported format name: " + formatName); } } return result; }  @Override String toString(final Object o, final String formatName, final Locale locale);  }
@Test public void toString_formatName_isNull() { assertEquals("text", new BasicFormatRenderer().toString("text", null, null)); }
@Test(expected = IllegalStateOfArgumentException.class) public void toString_formatName_unknownName() { new BasicFormatRenderer().toString("text", "unknownFormat", null); }
@Test(expected = IllegalNullArgumentException.class) public void toString_o_isNull() { new BasicFormatRenderer().toString(null, null, null); }
@Test public void toString_toLower() { assertEquals("text", new BasicFormatRenderer().toString("TEXT", "toLower", null)); assertEquals("t", new BasicFormatRenderer().toString("T", "toLower", null)); assertEquals("", new BasicFormatRenderer().toString("", "toLower", null)); assertEquals(" ", new BasicFormatRenderer().toString(" ", "toLower", null)); }
@Test public void toString_toLowerCamelCase() { assertEquals("textText", new BasicFormatRenderer().toString("TextText", "toLowerCamelCase", null)); assertEquals("t", new BasicFormatRenderer().toString("T", "toLowerCamelCase", null)); assertEquals("", new BasicFormatRenderer().toString("", "toLowerCamelCase", null)); assertEquals(" ", new BasicFormatRenderer().toString(" ", "toLowerCamelCase", null)); }
@Test public void toString_toUpper() { assertEquals("TEXT", new BasicFormatRenderer().toString("text", "toUpper", null)); assertEquals("T", new BasicFormatRenderer().toString("t", "toUpper", null)); assertEquals("", new BasicFormatRenderer().toString("", "toUpper", null)); }
@Test public void toString_toUpperCamelCase() { assertEquals("TextText", new BasicFormatRenderer().toString("textText", "toUpperCamelCase", null)); assertEquals("T", new BasicFormatRenderer().toString("t", "toUpperCamelCase", null)); assertEquals("", new BasicFormatRenderer().toString("", "toUpperCamelCase", null)); }