### Question:
TypeConverterImpl extends de.odysseus.el.misc.TypeConverterImpl { @Override @SuppressWarnings("unchecked") public <T> T convert(Object value, Class<T> type) throws ELException { if (type == URI.class && value instanceof String) { return (T) URI.create((String) value); } return super.convert(value, type); }  @Override @SuppressWarnings("unchecked") T convert(Object value, Class<T> type);  }### Answer:
@Test public void shouldConvertStringToURI() throws Exception { TypeConverter converter = new TypeConverterImpl(); String location = "http: URI expected = URI.create(location); Object o = converter.convert(location, URI.class); assertThat(o, instanceOf(URI.class)); assertEquals(expected, o); }
@Test(expected = ELException.class) public void shouldNotConvertToURI() throws Exception { TypeConverter converter = new TypeConverterImpl(); converter.convert(converter, URI.class); }
@Test() public void shouldConvertByteArrayToByteArray() throws Exception { TypeConverter converter = new TypeConverterImpl(); byte[] byteArr = { 1, 2, 3, 4, 5, 6 }; Object o = converter.convert(byteArr, byte[].class); assertThat(o, instanceOf(byte[].class)); assertArrayEquals(byteArr, (byte[]) o); }
@Test() public void shouldConvertAnObjectToCompatibleObject() throws Exception { TypeConverter converter = new TypeConverterImpl(); Object o = converter.convert(converter, TypeConverter.class); assertThat(o, instanceOf(TypeConverter.class)); assertThat(o, instanceOf(TypeConverterImpl.class)); assertEquals(converter, o); }
@Test(expected = ELException.class) public void shouldNotConvertToByteArray() throws Exception { TypeConverter converter = new TypeConverterImpl(); converter.convert(converter, byte[].class); }