ChatAlyticsEventDecoder implements Decoder.Text<ChatAlyticsEvent> { @Override public ChatAlyticsEvent decode(String str) throws DecodeException { try { return objectMapper.readValue(str, ChatAlyticsEvent.class); } catch (IOException e) { throw new DecodeException("Could not decode event", e.getMessage()); } } ChatAlyticsEventDecoder(); @Override void init(EndpointConfig config); @Override ChatAlyticsEvent decode(String str); @Override boolean willDecode(String str); @Override void destroy();  }
@Test public void testDecode() throws Exception { DateTime eventTime = DateTime.now(DateTimeZone.UTC); MessageSummary msgSummary = new MessageSummary("user", "room", DateTime.now(DateTimeZone.UTC), MessageType.BOT_MESSAGE, 1, false); ChatAlyticsEvent event = new ChatAlyticsEvent(eventTime, msgSummary.getClass().getName(), msgSummary); String jsonStr = new ChatAlyticsEventEncoder().encode(event); ChatAlyticsEvent decodedEvent = underTest.decode(jsonStr); assertEquals(event, decodedEvent); }
@Test(expected = DecodeException.class) public void testDecode_withBadJson() throws Exception { underTest.decode("bad json"); }