### Question:
MessageSerializer { public byte[] serialize(Message message) { String json = gson.toJson(message); return (message.getClass().getSimpleName() + ":" + json).getBytes(); }  byte[] serialize(Message message);  }### Answer:
@Test public void serialize() { Gson gson = mock(Gson.class); Message message = mock(Message.class); String className = message.getClass().getSimpleName(); when(gson.toJson(eq(message))).thenReturn("{json}"); MessageSerializer serializer = new MessageSerializer(gson); byte[] serialize = serializer.serialize(message); assertEquals(className + ":{json}", new String(serialize)); }