@Test public void testStringToInputStream() throws Exception { Transmorph converter = new Transmorph(new StringToInputStream()); InputStream is = converter.convert("Hello world", InputStream.class); assertNotNull(is); }
@Test public void testStringToBooleanPrimitive() throws Exception { Transmorph converter = new Transmorph(new DefaultConverters()); // String => boolean (StringToBooleanConverter) boolean myBoolean = converter.convert("false", Boolean.TYPE); assertEquals(false, myBoolean); myBoolean = converter.convert("true", Boolean.TYPE); assertEquals(true, myBoolean); try { myBoolean = converter.convert(null, Boolean.TYPE); fail("Should not have been converted"); } catch (ConverterException e) { } }
@Test public void testOtherStringToBooleanPrimitive() throws Exception { DefaultConverters defaultConverters = new DefaultConverters(); StringToBoolean stringToBoolean = defaultConverters.getStringToBoolean(); Transmorph converter = new Transmorph(defaultConverters); boolean myBoolean; try { myBoolean = converter.convert("faux", Boolean.TYPE); fail("Should not have been converted"); } catch (ConverterException e) { } stringToBoolean.setCaseSensitive(false); stringToBoolean.setTrueString("vrai"); stringToBoolean.setFalseString("faux"); myBoolean = converter.convert("Faux", Boolean.TYPE); assertEquals(false, myBoolean); myBoolean = converter.convert("Vrai", Boolean.TYPE); assertEquals(true, myBoolean); }
@Test public void testBooleanToBooleanWrapper() throws Exception { Transmorph converter = new Transmorph(new DefaultConverters()); Boolean booleanObject = converter.convert(null, Boolean.class); assertNull(booleanObject); }