@Test
    public void testCN() {
        Pattern cnPattern = Pattern.compile("(?i)(cn=)([^,]*)");
        String text = "EMAILADDRESS=XXXXX@scifi.com, CN=scifi.com, CN=jabber.scifi.com, OU=Domain validated only, O=XX, L=Skx, C=SE";
        List<String> found = new ArrayList<>();
        Matcher matcher = cnPattern.matcher(text);
        while (matcher.find()) {
            found.add(matcher.group(2));
        }
        assertEquals(2, found.size(), "Incorrect number of CNs were found");
        assertEquals("scifi.com" , found.get(0), "Incorrect CN found");
        assertEquals("jabber.scifi.com" , found.get(1), "Incorrect CN found");
    }
Verify that all CN elements are found.
xmppserver/src/test/java/org/jivesoftware/util/CertificateTest.java