Пример #1
0
 @Test
 public void testGetCash()
     throws NotEnoughMoneyInAccountException, NotEnoughMoneyInATMException,
         NoCardInsertedException {
   System.out.println("getCashNotZeroBalance");
   double atmMoney = 1000.0;
   ATM atmTest = new ATM(atmMoney);
   Card mockCard = mock(Card.class);
   Account mockAccount = mock(Account.class);
   atmTest.insertCard(mockCard); // ver.2
   double balance = 600.0;
   double amount = 100.0;
   int pinCode = 7777;
   when(mockCard.getAccount()).thenReturn(mockAccount);
   when(mockCard.checkPin(pinCode)).thenReturn(true);
   when(mockCard.isBlocked()).thenReturn(false);
   when(mockAccount.getBalance()).thenReturn(balance);
   when(mockAccount.withdrow(amount)).thenReturn(amount);
   atmTest.validateCard(mockCard, pinCode);
   atmTest.getCash(amount);
   when(mockAccount.getBalance()).thenReturn(balance - amount);
   assertEquals(atmTest.getMoneyInATM(), atmMoney - amount, 0.0);
   assertEquals(atmTest.checkBalance(), balance - amount, 0.0);
   InOrder inOrder = inOrder(mockCard, mockAccount);
   inOrder.verify(mockCard).isBlocked();
   inOrder.verify(mockCard).checkPin(pinCode);
   inOrder.verify(mockCard, atLeastOnce()).getAccount();
   verify(mockAccount).withdrow(amount);
   inOrder.verify(mockAccount).getBalance();
 }
  @Test
  public void shouldReturnUserDetails() {
    // arrange
    Account demoUser = new Account("*****@*****.**", "demo", "ROLE_USER");
    when(accountRepositoryMock.findOneByEmail("*****@*****.**")).thenReturn(demoUser);

    // act
    UserDetails userDetails = accountService.loadUserByUsername("*****@*****.**");

    // assert
    assertThat(demoUser.getEmail()).isEqualTo(userDetails.getUsername());
    assertThat(demoUser.getPassword()).isEqualTo(userDetails.getPassword());
    assertThat(hasAuthority(userDetails, demoUser.getRole())).isTrue();
  }
Пример #3
0
 @Test
 public void testCheckBalance() throws NoCardInsertedException {
   System.out.println("checkBalance");
   ATM atmTest = new ATM(1000.0);
   Card mockCard = mock(Card.class);
   Account mockAccount = mock(Account.class);
   atmTest.insertCard(mockCard);
   when(mockCard.getAccount()).thenReturn(mockAccount);
   when(mockAccount.getBalance()).thenReturn(0.0);
   double expResult = 0.0;
   double result = atmTest.checkBalance();
   assertEquals(expResult, result, 0.0);
   InOrder inOrder = inOrder(mockCard, mockAccount);
   inOrder.verify(mockCard).getAccount();
   inOrder.verify(mockAccount).getBalance();
 }
Пример #4
0
 @Test(expected = NotEnoughMoneyInAccountException.class)
 public void testGetCashNotEnoughMoneyInAccount()
     throws NoCardInsertedException, NotEnoughMoneyInAccountException,
         NotEnoughMoneyInATMException {
   System.out.println("getCashNotEnoughMoneyInAccount");
   ATM atmTest = new ATM(1000.0);
   Card mockCard = mock(Card.class);
   Account mockAccount = mock(Account.class);
   int pinCode = 7777;
   double balance = 200.0;
   double amount = 500.0;
   atmTest.insertCard(mockCard); // ver.2
   when(mockCard.getAccount()).thenReturn(mockAccount);
   when(mockAccount.getBalance()).thenReturn(balance);
   when(mockCard.checkPin(pinCode)).thenReturn(true);
   when(mockCard.getAccount().withdrow(amount)).thenReturn(balance - amount);
   atmTest.validateCard(mockCard, pinCode);
   atmTest.getCash(amount);
   InOrder inOrder = inOrder(mockCard, mockAccount);
   inOrder.verify(mockCard).getAccount();
   inOrder.verify(mockAccount).getBalance();
 }