usernameGeneratorParams.setPrefix(null);
usernameGeneratorParams.setPostfix(null);
UsernameGenerator usernameGenerator = UsernameGenerator.getInstance(usernameGeneratorParams);
final String errorMessage = "Did not generate an expected username.";
assertEquals(errorMessage, "test", usernameGenerator.generateUsername(new X509Name("CN=test").toString()));
assertEquals(errorMessage, null, usernameGenerator.generateUsername("".toString()));
assertEquals(errorMessage, null, usernameGenerator.generateUsername(" ".toString()));
assertEquals(errorMessage, "test", usernameGenerator.generateUsername(new X509Name("CN=test, serialNumber=1234").toString()));
assertEquals(errorMessage, null, usernameGenerator.generateUsername(new X509Name("O=org").toString()));
assertEquals(errorMessage, "12345", usernameGenerator.generateUsername("CN=test, SN=12345"));
assertEquals(errorMessage, "1234", usernameGenerator.generateUsername("SN=1234"));
// These wont work since new X509Name converts SN to SERIALNUMBER in toString()
// Is this something we should compensate for in CertTools.getPartFromDN(...) ?