Messages { static String extractClientFrom(String payload) { if (payload.startsWith(MAGIC) && payload.length() > MAGIC.length()) { payload = payload.substring(MAGIC.length()); int i = payload.indexOf(SEPARATOR); return payload.substring(0, i); } return null; } private  Messages();   }
@Test public void extractClientFromPayloadWithoutMagic() throws Exception { assertNull(extractClientFrom("wrong")); }
@Test public void extractClientFromEmptyPayload() throws Exception { assertNull(extractClientFrom("Standby-CMD@")); }
@Test public void extractClientFromPayloadWithClient() throws Exception { assertEquals("client", extractClientFrom("Standby-CMD@client:message")); }
@Test public void extractClientFromPayloadWithoutClient() throws Exception { assertEquals("", extractClientFrom("Standby-CMD@:message")); }