PJF16

Mockito Test - verbessert

Jan 7th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1.   @Test
  2.     public void itShouldNotRevokeSecondAccountAfterTwoFailedAttemptsFirstAccount()
  3.     {
  4.         this.willPasswordMatch(false);
  5.  
  6.         IAccount secondAccount = mock(IAccount.class);
  7.         when(secondAccount.passwordMatches(anyString())).thenReturn(false);
  8.         when(this.repository.find(anyString())).thenReturn(secondAccount);
  9.         /*Wird benötigt da ansonsten immer "secondAccount" geliefert wird und
  10.         damit dieser auf "Revoked" gesetzt wird. Mit diesem Befehl wird bei
  11.         Eingabe von "schuchert" der erste Accont geliefert.
  12.         */
  13.         when(this.repository.find("brett")).thenReturn(account);
  14.         when(secondAccount.getId()).thenReturn("asdf");
  15.  
  16.         service.login("brett", "password");
  17.         service.login("brett", "password");
  18.         service.login("schuchert", "password");
  19.  
  20.         verify(secondAccount, never()).setLoggedIn(true);
  21.         verify (secondAccount, never()).setRevoked(true);
  22.         verify (account,never()).setRevoked(true);
  23.      
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment