@Test public void toStrings() { GlobalConverter converter = new BooleanConverter(new MockConfiguration()); String str = converter.convertToString(Character.class, null, "testExpr", null); assertNull(str); str = converter.convertToString(Character.class, null, "testExpr", 'c'); assertEquals(str, "c"); str = converter.convertToString(Character.TYPE, null, "testExpr", 'c'); assertEquals(str, "c"); }
@Test public void fromStrings() { GlobalConverter converter = new CharacterConverter(new MockConfiguration()); Character cw = (Character) converter.convertFromStrings( Character.class, null, "testExpr", ArrayUtils.toArray((String) null)); assertNull(cw); char c = (Character) converter.convertFromStrings( Character.TYPE, null, "testExpr", ArrayUtils.toArray((String) null)); assertEquals(c, '\u0000'); cw = (Character) converter.convertFromStrings( Character.class, null, "testExpr", ArrayUtils.toArray("c")); assertEquals((char) cw, 'c'); c = (Character) converter.convertFromStrings(Character.TYPE, null, "testExpr", ArrayUtils.toArray("c")); assertEquals(c, 'c'); cw = (Character) converter.convertFromStrings( Character.class, null, "testExpr", ArrayUtils.toArray(" ")); assertNull(cw); c = (Character) converter.convertFromStrings(Character.TYPE, null, "testExpr", ArrayUtils.toArray(" ")); assertEquals(c, 0); Character[] ca = (Character[]) converter.convertFromStrings( Character[].class, null, "testExpr", ArrayUtils.toArray("c", "d")); assertEquals(ca[0], (Character) 'c'); assertEquals(ca[1], (Character) 'd'); char[] cpa = (char[]) converter.convertFromStrings( char[].class, null, "testExpr", ArrayUtils.toArray("c", "d")); assertEquals(cpa[0], 'c'); assertEquals(cpa[1], 'd'); try { converter.convertFromStrings(Character.class, null, "testExpr", ArrayUtils.toArray("bad")); fail("Should have failed"); } catch (ConversionException ce) { // Expected } try { converter.convertFromStrings(Character.TYPE, null, "testExpr", ArrayUtils.toArray("bad")); fail("Should have failed"); } catch (ConversionException ce) { // Expected } }