Messages { static String extractMessageFrom(String payload) { if (payload.startsWith(MAGIC) && payload.length() > MAGIC.length()) { int i = payload.indexOf(SEPARATOR); return payload.substring(i + 1); } return null; } private  Messages();   }
@Test public void extractMessageFromPayloadWithoutMagic() throws Exception { assertNull(extractMessageFrom("wrong")); }
@Test public void extractMessageFromEmptyPayload() throws Exception { assertNull(extractMessageFrom("Standby-CMD@")); }
@Test public void extractMessageFromPayloadWithClient() throws Exception { assertEquals("message", extractMessageFrom("Standby-CMD@client:message")); }
@Test public void extractMessageFromPayloadWithoutClient() throws Exception { assertEquals("message", extractMessageFrom("Standby-CMD@:message")); }