HexToStringService extends ReformatMetadata { public void setCharset(String encoding) { charset = encoding; } HexToStringService();  HexToStringService(String regex); String getCharset(); void setCharset(String encoding); @Override String reformat(String s, String msgCharset);  }
@Test public void testService() throws Exception { HexToStringService service = new HexToStringService(); service.setCharset("UTF-8"); service.setMetadataKeyRegexp(SOURCE_METADATA_KEY); AdaptrisMessage msg = createMessage(); execute(service, msg); assertTrue(msg.containsKey(SOURCE_METADATA_KEY)); assertEquals(PLAIN_TEXT, msg.getMetadataValue(SOURCE_METADATA_KEY)); }
@Test public void testService_NotHex() throws Exception { HexToStringService service = new HexToStringService(); service.setCharset("UTF-8"); service.setMetadataKeyRegexp(BAD_METADATA_KEY); AdaptrisMessage msg = createMessage(); try { execute(service, msg); fail(); } catch (ServiceException expected) { } }
@Test public void testService_BadEncodingChoice() throws Exception { HexToStringService service = new HexToStringService(); service.setCharset("RandomEncoding!"); service.setMetadataKeyRegexp(SOURCE_METADATA_KEY); AdaptrisMessage msg = createMessage(); try { execute(service, msg); fail(); } catch (ServiceException expected) { } }