@Test public void testLoadByIdWithInvalidId() throws Exception { final Connection cnn = databaseTestUtils.getConnection(); try { // attempt to load the user using the handler final UserEntityHandler handler = new UserEntityHandler(); final User user = handler.loadUserById(cnn, -1); assertNull("Expected get to return null since the ID could not be found", user); } finally { DbUtils.close(cnn); } }
@Test public void testLoadById() throws Exception { final Connection cnn = databaseTestUtils.getConnection(); try { // insert a test user into the database int testUserId = databaseTestUtils.insertTestUser(cnn); // attempt to load the user using the handler final UserEntityHandler handler = new UserEntityHandler(); final User user = handler.loadUserById(cnn, testUserId); assertTrue("Expected get to return a valid user account", user != null); assertEquals( "Expected email to be the one specified in the database", "*****@*****.**", user.getEmail()); } finally { DbUtils.close(cnn); } }