ChatAlyticsEventEncoder implements Encoder.Text<ChatAlyticsEvent> { @Override public String encode(ChatAlyticsEvent object) throws EncodeException { try { return objectMapper.writeValueAsString(object); } catch (JsonProcessingException e) { throw new EncodeException(object, "Can't encode object. Reason: " + e.getMessage()); } } ChatAlyticsEventEncoder(); @Override void init(EndpointConfig config); @Override String encode(ChatAlyticsEvent object); @Override void destroy();  }
@Test public void testEncode() 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 = underTest.encode(event); ChatAlyticsEvent decodedEvent = new ChatAlyticsEventDecoder().decode(jsonStr); assertEquals(event, decodedEvent); }
@Test(expected = EncodeException.class) public void testEncode_badSerializable() throws Exception { underTest.encode(new ChatAlyticsEvent(DateTime.now(), "type", mock(MessageSummary.class))); }