MessageIdUtils { public static String createContentId(final String msgId) { String leftPart, rightPart; if (Utils.isNullOrEmpty(msgId)) return createMessageId(); else { final int i = msgId.indexOf("@"); if (i > 0) { leftPart = msgId.substring(0, i); rightPart = msgId.substring(i); } else { leftPart = msgId; rightPart = ""; } leftPart += "-" + String.valueOf(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE)); return (leftPart + rightPart).replaceAll("[^" + VALID_CHARS + "]", "_"); } }  static String createMessageId(); static String createContentId(final String msgId); static boolean isAllowed(final String messageId); static boolean isCorrectFormat(final String messageId); static String stripBrackets(final String messageId);  }
@Test public void testCreateContentId() throws Exception { String id = MessageIdUtils.createMessageId(); String[] idParts = id.split("@"); String contentId = MessageIdUtils.createContentId(id); assertNotNull(contentId); String[] contentIdParts = contentId.split("@"); assertTrue(contentIdParts.length == 2); assertTrue(contentIdParts[0].contains(idParts[0])); assertEquals(idParts[0], contentIdParts[0].substring(0, contentIdParts[0].lastIndexOf("-"))); assertTrue(contentIdParts[0].length()>0); assertEquals(contentIdParts[1], hostname); }