コード例 #1
0
ファイル: ATMTest.java プロジェクト: RomarioGorilyi/ATM
 @Test(expected = NullPointerException.class)
 public void testValidateCardNullCard() throws NoCardInsertedException {
   System.out.println("validateNullCard");
   ATM atmTest = new ATM(100);
   int pinCode = 7777;
   atmTest.validateCard(null, pinCode);
 }
コード例 #2
0
ファイル: ATMTest.java プロジェクト: RomarioGorilyi/ATM
 @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();
 }
コード例 #3
0
ファイル: ATMTest.java プロジェクト: RomarioGorilyi/ATM
 @Test
 public void testValidateCardWithInvalidPin() throws NoCardInsertedException {
   System.out.println("validateCardWithInvalidPin");
   ATM atmTest = new ATM(1000.0);
   Card mockCard = mock(Card.class);
   int pinCode = 7777;
   when(mockCard.isBlocked()).thenReturn(false);
   when(mockCard.checkPin(pinCode)).thenReturn(false);
   assertFalse(atmTest.validateCard(mockCard, pinCode));
 }
コード例 #4
0
ファイル: ATMTest.java プロジェクト: RomarioGorilyi/ATM
 @Test
 public void testValidateValidCard() throws NoCardInsertedException {
   System.out.println("validateValidCard");
   ATM atmTest = new ATM(1000.0);
   Card mockCard = mock(Card.class);
   int pinCode = 7777;
   when(mockCard.isBlocked()).thenReturn(false);
   when(mockCard.checkPin(pinCode)).thenReturn(true);
   boolean expResult = true;
   boolean result = atmTest.validateCard(mockCard, pinCode);
   assertEquals(expResult, result);
   InOrder inOrder = inOrder(mockCard);
   inOrder.verify(mockCard).isBlocked();
   inOrder.verify(mockCard).checkPin(pinCode);
 }
コード例 #5
0
ファイル: ATMTest.java プロジェクト: RomarioGorilyi/ATM
 @Test(expected = NotEnoughMoneyInATMException.class)
 public void testGetCashNotEnoughMoneyInATM()
     throws NoCardInsertedException, NotEnoughMoneyInAccountException,
         NotEnoughMoneyInATMException {
   System.out.println("getCashNotEnoughMoneyInATM");
   ATM atmTest = new ATM(1000.0);
   Card mockCard = mock(Card.class);
   Account mockAccount = mock(Account.class);
   double amount = 1100.0;
   int pinCode = 7777;
   atmTest.insertCard(mockCard); // ver.2
   when(mockCard.getAccount()).thenReturn(mockAccount);
   when(mockCard.checkPin(pinCode)).thenReturn(true);
   atmTest.validateCard(mockCard, pinCode);
   atmTest.getCash(amount);
   InOrder inOrder = inOrder(mockCard, mockAccount);
   inOrder.verify(mockCard).getAccount();
   inOrder.verify(mockAccount).getBalance();
 }