DefaultResourceHandler implements IResourceHandler { private String asString(Object value) { if (value instanceof String) { return ((String) value); } else if (value instanceof byte[]) { try { return new String((byte[]) value, "utf-8"); } catch (UnsupportedEncodingException e) { return new String((byte[]) value); } } else { return String.valueOf(value); } }  @Override byte[] getBinaryContent(IResource resource, IResourceContext context); @Override String getContent(IResource resource, IResourceContext context); @Override String getUrl(IResource resource, IResourceContext context);  }
@Test public void testAsString() throws NoSuchMethodException, SecurityException, ReflectiveOperationException, IllegalArgumentException, InvocationTargetException, UnsupportedEncodingException { Class<DefaultResourceHandler> clazz = DefaultResourceHandler.class; Method method = clazz.getDeclaredMethod("asString", Object.class); method.setAccessible(true); String str = "test string for asString"; Assert.assertEquals(str, (String)method.invoke(m_handler, str)); byte[] byteArray = str.getBytes("utf-8"); Assert.assertEquals(str, (String)method.invoke(m_handler, byteArray)); String result = (String)method.invoke(m_handler, new Object()); Assert.assertTrue(result.contains("java.lang.Object")); }