public AccountDaoImplTest() { testAccountNotActivated = new Account(0, "Hello"); testAccountNotActivated.setPassword("World"); testAccountNotActivated.setActivated(false); testAccountActivated = new Account(1, "Hello"); testAccountActivated.setPassword("World"); testAccountActivated.setActivated(true); }
@Test @Rollback(true) public void testGetAccount_String_ValidName() { Account account = null; // Check if account was retieved correctly try { account = this.accountDaoImpl.getAccount("Hello"); } catch (Exception e) { fail("Account was not retrieved correctly with error : " + e.getLocalizedMessage()); } assertNotNull(account); assertEquals(account.getName(), this.testAccountNotActivated.getName()); assertEquals(account.getId().intValue(), this.testAccountNotActivated.getId().intValue()); assertEquals(account.getPassword(), this.testAccountNotActivated.getPassword()); assertFalse(account.getActivated()); System.out.println("testGetAccount_String_ValidName() passed"); }
@Test @Rollback(true) public void testSaveAccount_NewAccount() { // Save new Account try { Account account = new Account(3, "World"); this.accountDaoImpl.saveAccount(account); Account returnAccount = this.accountDaoImpl.getAccount("World"); assertNotNull(returnAccount); assertEquals(account.getId().intValue(), returnAccount.getId().intValue()); assertEquals(account.getName(), returnAccount.getName()); } catch (DataAccessException e) { fail("DataAccessException was thrown for new Account"); } System.out.println("testSaveAccount_NewAccount() passed"); }
@Test @Rollback(true) public void testSaveAccount_OldAccount() { // Save old Account try { this.accountDaoImpl.saveAccount(testAccountNotActivated); } catch (Exception e) { fail("Could not save test account for saveAccount()"); } try { Account account = this.accountDaoImpl.getAccount(0); account.setPassword("1234"); this.accountDaoImpl.saveAccount(account); account = this.accountDaoImpl.getAccount(0); assertNotNull(account); assertEquals(account.getName(), this.testAccountNotActivated.getName()); assertEquals(account.getId().intValue(), this.testAccountNotActivated.getId().intValue()); assertEquals(account.getPassword(), this.testAccountNotActivated.getPassword()); assertFalse(account.getActivated()); } catch (DataAccessException e) { fail("DataAccessException was thrown for resave"); } System.out.println("testSaveAccount_OldAccount() passed"); }