assertTrue("6 character email confirmation key generated", mockDj
.getEmailConfirmation().length() == 6);
}
public void testConfirmEmailAddress() throws InvalidKeyException {
JizzDj mockDj = new JizzDj();
try {
jizzDjServices.confirmEmailAddress(mockDj, null);
fail("Expected invalid key exception for empty key");
} catch (InvalidKeyException kEx) {
// Good!
logger.debug("Expected error", kEx);
}
try {
jizzDjServices.confirmEmailAddress(mockDj, "");
fail("Expected invalid key exception for empty key");
} catch (InvalidKeyException kEx) {
// Good!
logger.debug("Expected error", kEx);
}
expect(mockJizzDjDao.getDj(mockDj.getId())).andReturn(mockDj);
replayAll();
try {
jizzDjServices.confirmEmailAddress(mockDj, "123456");
fail("Expected invalid key exception for empty email");
} catch (InvalidKeyException kEx) {
// Good!
logger.debug("Expected error", kEx);
}
verifyAll();
resetAll();
mockDj.setEmail("");
expect(mockJizzDjDao.getDj(mockDj.getId())).andReturn(mockDj);
replayAll();
try {
jizzDjServices.confirmEmailAddress(mockDj, "123456");
fail("Expected invalid key exception for empty email");
} catch (InvalidKeyException kEx) {
// Good!
logger.debug("Expected error", kEx);
}
verifyAll();
resetAll();
mockDj.setEmail("test@test.com");
expect(mockJizzDjDao.getDj(mockDj.getId())).andReturn(mockDj);
replayAll();
try {
jizzDjServices.confirmEmailAddress(mockDj, "123456");
fail("Expected invalid key exception for email already being "
+ "confirmed");
} catch (InvalidKeyException kEx) {
// Good!
logger.debug("Expected error", kEx);
}
verifyAll();
resetAll();
mockDj.setEmailConfirmation("654321");
expect(mockJizzDjDao.getDj(mockDj.getId())).andReturn(mockDj);
replayAll();
try {
jizzDjServices.confirmEmailAddress(mockDj, "123456");
fail("Expected invalid key exception for keys not matching");
} catch (InvalidKeyException kEx) {
// Good!
logger.debug("Expected error", kEx);
}
verifyAll();
resetAll();
mockDj.setEmailConfirmation("123456");
expect(mockJizzDjDao.getDj(mockDj.getId())).andReturn(mockDj);
expect(mockJizzDjDao.createOrUpdateDj(mockDj)).andReturn(mockDj);
replayAll();
jizzDjServices.confirmEmailAddress(mockDj, "123456");
verifyAll();
assertNull("Email should be confirmed", mockDj.getEmailConfirmation());
}