Пример #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();
 }
Пример #2
0
 @Test
 public void checkAccountActivityWithdrawal() {
   Account a = new Account(Account.CHECKING);
   a.deposit(10);
   a.withdraw(5);
   assertFalse(a.accountInactive());
 }
Пример #3
0
  @Test
  public void testTransactions() {
    Account a = new Account(Account.SAVINGS);
    a.deposit(100.5);
    a.withdraw(50.5);
    double balance = a.sumTransactions();

    assertEquals(50.0, balance, DOUBLE_DELTA);
  }
Пример #4
0
  @Test
  public void testAddRemoveTimedPayment() {
    // Test addTimedPayment and check if it exists after function call
    testAccount.addTimedPayment("Test", 1, 1, new Money(100, SEK), SweBank, "Alice");
    assertTrue(testAccount.timedPaymentExists("Test"));

    // Try to remove timed payment and check if it is removed
    testAccount.removeTimedPayment("Test");
    assertFalse(testAccount.timedPaymentExists("Test"));
  }
Пример #5
0
  @Test
  public void testAddWithdraw() {
    // Amount before deposit and withdraw
    int preTransferAmountTestaccount = testAccount.getBalance().getAmount();

    // Try to deposit 200 and check if desired value
    testAccount.deposit(new Money(200, SEK));
    assertEquals(
        preTransferAmountTestaccount + 200, testAccount.getBalance().getAmount().intValue());

    // Try to withdraw 200 and check value
    testAccount.withdraw(new Money(200, SEK));
    assertEquals(preTransferAmountTestaccount, testAccount.getBalance().getAmount().intValue());
  }
Пример #6
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();
 }
Пример #7
0
  @Before
  public void setUp() throws Exception {
    SEK = new Currency("SEK", 0.15);
    SweBank = new Bank("SweBank", SEK);
    SweBank.openAccount("Alice");
    testAccount = new Account("Hans", SEK);
    testAccount.deposit(new Money(10000000, SEK));

    SweBank.deposit("Alice", new Money(1000000, SEK));
  }
Пример #8
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();
 }
  @Test
  public void testFindByCreditCard() {
    Account account = repository.findByCreditCard("1234123412341234");
    // assert the returned account contains what you expect given the state of the database
    // and the Account Hibernate mapping configuration
    assertNotNull("account should never be null", account);
    assertEquals("wrong entity id", Long.valueOf(0), account.getEntityId());
    assertEquals("wrong account number", "123456789", account.getNumber());
    assertEquals("wrong name", "Keith and Keri Donald", account.getName());
    assertEquals("wrong beneficiary collection size", 2, account.getBeneficiaries().size());

    Beneficiary b1 = account.getBeneficiary("Annabelle");
    assertNotNull("Annabelle should be a beneficiary", b1);
    assertEquals("wrong savings", MonetaryAmount.valueOf("0.00"), b1.getSavings());
    assertEquals(
        "wrong allocation percentage", Percentage.valueOf("50%"), b1.getAllocationPercentage());

    Beneficiary b2 = account.getBeneficiary("Corgan");
    assertNotNull("Corgan should be a beneficiary", b2);
    assertEquals("wrong savings", MonetaryAmount.valueOf("0.00"), b2.getSavings());
    assertEquals(
        "wrong allocation percentage", Percentage.valueOf("50%"), b2.getAllocationPercentage());
  }
Пример #10
0
 // Test the getName function
 @Test
 public void nametest() {
   Account a = new Account();
   a.setName("Alice");
   assertEquals(a.getName(), "Alice");
 }
Пример #11
0
 @Test
 public void checkAccountActivityDeposit() {
   Account a = new Account(Account.CHECKING);
   a.deposit(10);
   assertTrue(a.accountInactive());
 }
Пример #12
0
 @Test(expected = IllegalArgumentException.class)
 public void testWithdrawIllegalArgumentException() {
   Account a = new Account(Account.SAVINGS);
   a.withdraw(-2);
 }
Пример #13
0
 @Test(expected = IllegalArgumentException.class)
 public void testDepositIllegalArgumentException() {
   Account a = new Account(Account.SAVINGS);
   a.deposit(-2);
 }
Пример #14
0
 // Test the getTransactions function
 @Test
 public void transactionstest() {
   Account a = new Account();
   a.setTransactions(11);
   assertEquals(a.getTransactions(), 11);
 }
Пример #15
0
 // Test the getStudent function
 @Test
 public void studenttest() {
   Account a = new Account();
   a.setStudent(true);
   assertEquals(a.getStudent(), true);
 }
Пример #16
0
 // Test the getCreated function
 @Test
 public void createdtest() {
   Account a = new Account();
   a.setCreated(true);
   assertEquals(a.getCreated(), true);
 }
Пример #17
0
 // Test the getFrozen function
 @Test
 public void frozentest() {
   Account a = new Account();
   a.setFrozen(678.99);
   assertEquals(a.getFrozen(), 678.99, 0.001);
 }
Пример #18
0
 // Test the getBalance function
 @Test
 public void balancetest() {
   Account a = new Account();
   a.setBalance(678.99);
   assertEquals(a.getBalance(), 678.99, 0.001);
 }
Пример #19
0
  @Test
  public void testTimedPayment() throws AccountDoesNotExistException {
    // The amounts before any ticks and payments
    int preTransferAmountHans = testAccount.getBalance().getAmount();
    int preTransferAmountAlice = SweBank.getBalance("Alice");

    // Set up the payment and tick once
    testAccount.addTimedPayment("Test", 1, 1, new Money(100, SEK), SweBank, "Alice");
    testAccount.tick();

    // There should be the same amount on each account
    assertEquals(preTransferAmountHans, testAccount.getBalance().getAmount().intValue());
    assertEquals(preTransferAmountAlice, SweBank.getBalance("Alice").intValue());

    testAccount.tick();

    // 100 withdrawn from testAccount. Alice gets deposit of 100
    assertEquals(preTransferAmountHans - 100, testAccount.getBalance().getAmount().intValue());
    assertEquals(preTransferAmountAlice + 100, SweBank.getBalance("Alice").intValue());

    // Tick for another payment
    testAccount.tick();
    testAccount.tick();

    // Another 100 withdrawn/deposit
    assertEquals(preTransferAmountHans - 200, testAccount.getBalance().getAmount().intValue());
    assertEquals(preTransferAmountAlice + 200, SweBank.getBalance("Alice").intValue());

    // Remove payment
    testAccount.removeTimedPayment("Test");

    // Tick some times, and afterwards check if the amounts are still the same
    testAccount.tick();
    testAccount.tick();
    testAccount.tick();
    testAccount.tick();

    assertEquals(preTransferAmountHans - 200, testAccount.getBalance().getAmount().intValue());
    assertEquals(preTransferAmountAlice + 200, SweBank.getBalance("Alice").intValue());
  }
Пример #20
0
 @Test
 public void testGetBalance() {
   // Test if we get the correct balance from an account
   assertEquals(10000000, testAccount.getBalance().getAmount().intValue());
 }
Пример #21
0
 // Test the getNum function
 @Test
 public void numtest() {
   Account a = new Account();
   a.setNum("12345");
   assertEquals(a.getNum(), "12345");
 }
  /** Test for fetching zobjects when there is an object that matches the query */
  @Test
  public void getInvoice() throws Exception {

    // Setup Product details
    String productId = getTestProduct();
    String productRatePlanId = getTestProductRatePlan(productId);
    String productRateplanChargeId = getTestProductRatePlanCharge(productRatePlanId);

    assertNotNull(productId);
    assertNotNull(productRatePlanId);
    assertNotNull(productRateplanChargeId);

    SubscribeRequest subscribeReq = new SubscribeRequest();

    // subscribeReq.setAccount(testAccount());
    String uniqueString = UUID.randomUUID().toString();

    Contact contact = new Contact();
    contact.setFirstName(uniqueString);
    contact.setLastName(uniqueString);

    Account account = new Account();
    account.setName(uniqueString);
    account.setBillCycleDay(1);
    account.setCurrency("USD");
    account.setAllowInvoiceEdit(false);
    account.setAutoPay(false);
    account.setStatus("Draft");
    account.setPaymentTerm("Due Upon Receipt");
    account.setBatch("Batch1");

    PaymentMethod paymentMethod = new PaymentMethod();
    paymentMethod.setType("CreditCard");
    paymentMethod.setCreditCardNumber("5105105105105100");
    paymentMethod.setCreditCardType("Visa");
    paymentMethod.setCreditCardExpirationYear(2026);
    paymentMethod.setCreditCardExpirationMonth(5);
    paymentMethod.setCreditCardHolderName("Unit Test");

    // Generate Start and stop days for subscription
    XMLGregorianCalendar effectiveStartDate = null;
    XMLGregorianCalendar effectiveEndDate = null;
    try {
      GregorianCalendar calStart = new GregorianCalendar();
      // calStart.setTime(now);
      calStart.add(Calendar.DATE, -1);

      GregorianCalendar calEnd = new GregorianCalendar();
      // calEnd.setTime(now);
      calEnd.add(Calendar.DATE, 1);

      effectiveStartDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calStart);
      effectiveEndDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calStart);

    } catch (DatatypeConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    Subscription subscription = new Subscription();
    subscription.setContractAcceptanceDate(effectiveStartDate);
    subscription.setContractEffectiveDate(effectiveStartDate);
    subscription.setInitialTerm(12);
    subscription.setRenewalTerm(12);

    RatePlan ratePlan = new RatePlan();
    ratePlan.setProductRatePlanId(productRatePlanId);
    RatePlanData ratePlanData = new RatePlanData();
    ratePlanData.setRatePlan(ratePlan);

    SubscriptionData subscriptionData = new SubscriptionData();
    subscriptionData.setSubscription(subscription);
    subscriptionData.getRatePlanData().add(ratePlanData);

    subscribeReq.setAccount(account);
    subscribeReq.setBillToContact(contact);
    subscribeReq.setSoldToContact(contact);
    subscribeReq.setPaymentMethod(paymentMethod);
    subscribeReq.setSubscriptionData(subscriptionData);

    SubscribeResult subscribeResult =
        module.subscribe(Collections.singletonList(subscribeReq)).get(0);
    assertTrue(subscribeResult.isSuccess());
    assertEquals(0, subscribeResult.getErrors().size());

    Map<String, Object> result = module.getInvoice(subscribeResult.getInvoiceId());

    System.out.println("Result = " + result);

    assertEquals("Posted", result.get("status"));
    // assertEquals("amount",result.get("amount"));
    assertNotSame(0, ((ArrayList) result.get("invoiceitems")).size());

    assertNotNull(result.get("billTo"));
    assertNotNull(result.get("soldTo"));

    DeleteResult deleteResultAccount = null;
    DeleteResult deleteResultProduct = null;
    try {
      deleteResultAccount =
          module
              .delete(
                  ZObjectType.Account, Collections.singletonList(subscribeResult.getAccountId()))
              .get(0);
      deleteResultProduct =
          module.delete(ZObjectType.Product, Collections.singletonList(productId)).get(0);
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    assertTrue(deleteResultAccount.isSuccess());
    assertTrue(deleteResultProduct.isSuccess());
  }
Пример #23
0
 // Test the getStatus function
 @Test
 public void statustest() {
   Account a = new Account();
   a.setStatus("D");
   assertEquals(a.getStatus(), "D");
 }