예제 #1
0
  @Test
  public void testGetMonthlyPayment_GetLoanScheduleArray3() {
    Loan loanBean = new Loan(10000, 8.9, 10);
    assertEquals(125.27, loanBean.getMonthlyPayment(), 0.00);

    LoanSchedule[] loanScheduleArray = loanBean.getLoanScheduleArray();
    LoanSchedule loanSchedule1 = loanScheduleArray[0];
    assertEquals(1, loanSchedule1.getPaymentNumber());
    assertEquals(72.83, loanSchedule1.getInterestPaid(), 0.00);
    assertEquals(52.44, loanSchedule1.getPrincipalPaid(), 0.00);
    assertEquals(9947.56, loanSchedule1.getRemainingBalance(), 0.00);
    LoanSchedule loanSchedule2 = loanScheduleArray[1];
    assertEquals(2, loanSchedule2.getPaymentNumber());
    assertEquals(72.45, loanSchedule2.getInterestPaid(), 0.00);
    assertEquals(52.82, loanSchedule2.getPrincipalPaid(), 0.00);
    assertEquals(9894.74, loanSchedule2.getRemainingBalance(), 0.00);
    LoanSchedule loanSchedule119 = loanScheduleArray[118];
    assertEquals(119, loanSchedule119.getPaymentNumber());
    assertEquals(1.80, loanSchedule119.getInterestPaid(), 0.00);
    assertEquals(123.47, loanSchedule119.getPrincipalPaid(), 0.00);
    assertEquals(124.29, loanSchedule119.getRemainingBalance(), 0.00);
    LoanSchedule loanSchedule120 = loanScheduleArray[119];
    assertEquals(120, loanSchedule120.getPaymentNumber());
    assertEquals(0.91, loanSchedule120.getInterestPaid(), 0.00);
    assertEquals(124.29, loanSchedule120.getPrincipalPaid(), 0.00);
    assertEquals(0.00, loanSchedule120.getRemainingBalance(), 0.00);
  }
예제 #2
0
  @Test
  public void testGetMonthlyPayment_GetLoanScheduleArray2() {
    Loan loanBean = new Loan(5000, 5, 2);
    assertEquals(219.24, loanBean.getMonthlyPayment(), 0.00);

    LoanSchedule[] loanScheduleArray = loanBean.getLoanScheduleArray();
    LoanSchedule loanSchedule1 = loanScheduleArray[0];
    assertEquals(1, loanSchedule1.getPaymentNumber());
    assertEquals(20.62, loanSchedule1.getInterestPaid(), 0.00);
    assertEquals(198.62, loanSchedule1.getPrincipalPaid(), 0.00);
    assertEquals(4801.38, loanSchedule1.getRemainingBalance(), 0.00);
    LoanSchedule loanSchedule2 = loanScheduleArray[1];
    assertEquals(2, loanSchedule2.getPaymentNumber());
    assertEquals(19.80, loanSchedule2.getInterestPaid(), 0.00);
    assertEquals(199.44, loanSchedule2.getPrincipalPaid(), 0.00);
    assertEquals(4601.94, loanSchedule2.getRemainingBalance(), 0.00);
    LoanSchedule loanSchedule23 = loanScheduleArray[22];
    assertEquals(23, loanSchedule23.getPaymentNumber());
    assertEquals(1.80, loanSchedule23.getInterestPaid(), 0.00);
    assertEquals(217.44, loanSchedule23.getPrincipalPaid(), 0.00);
    assertEquals(218.37, loanSchedule23.getRemainingBalance(), 0.00);
    LoanSchedule loanSchedule24 = loanScheduleArray[23];
    assertEquals(24, loanSchedule24.getPaymentNumber());
    assertEquals(0.90, loanSchedule24.getInterestPaid(), 0.00);
    assertEquals(218.37, loanSchedule24.getPrincipalPaid(), 0.00);
    assertEquals(0.00, loanSchedule24.getRemainingBalance(), 0.00);
  }
예제 #3
0
 @Test
 public void testGetMonthlyPayment_GetLoanScheduleArray5() {
   Loan loanBean = new Loan(100000, 7.9, 20);
   assertEquals(822.37, loanBean.getMonthlyPayment(), 0.00);
   LoanSchedule[] loanScheduleArray = loanBean.getLoanScheduleArray();
   LoanSchedule loanSchedule1 = loanScheduleArray[0];
   assertEquals(1, loanSchedule1.getPaymentNumber());
   assertEquals(647.75, loanSchedule1.getInterestPaid(), 0.00);
   assertEquals(174.62, loanSchedule1.getPrincipalPaid(), 0.00);
   assertEquals(99825.38, loanSchedule1.getRemainingBalance(), 0.00);
   LoanSchedule loanSchedule2 = loanScheduleArray[1];
   assertEquals(2, loanSchedule2.getPaymentNumber());
   assertEquals(646.62, loanSchedule2.getInterestPaid(), 0.00);
   assertEquals(175.75, loanSchedule2.getPrincipalPaid(), 0.00);
   assertEquals(99649.63, loanSchedule2.getRemainingBalance(), 0.00);
   LoanSchedule loanSchedule239 = loanScheduleArray[238];
   assertEquals(239, loanSchedule239.getPaymentNumber());
   assertEquals(10.55, loanSchedule239.getInterestPaid(), 0.00);
   assertEquals(811.82, loanSchedule239.getPrincipalPaid(), 0.00);
   assertEquals(817.14, loanSchedule239.getRemainingBalance(), 0.00);
   LoanSchedule loanSchedule240 = loanScheduleArray[239];
   assertEquals(240, loanSchedule240.getPaymentNumber());
   assertEquals(5.29, loanSchedule240.getInterestPaid(), 0.00);
   assertEquals(817.14, loanSchedule240.getPrincipalPaid(), 0.00);
   assertEquals(0.00, loanSchedule240.getRemainingBalance(), 0.00);
 }
예제 #4
0
 @Test
 public void testGetMonthlyPayment_GetLoanScheduleArray4() {
   Loan loanBean = new Loan(300000, 5.390, 25);
   assertEquals(1812.01, loanBean.getMonthlyPayment(), 0.00);
   LoanSchedule[] loanScheduleArray = loanBean.getLoanScheduleArray();
   LoanSchedule loanSchedule1 = loanScheduleArray[0];
   assertEquals(1, loanSchedule1.getPaymentNumber());
   assertEquals(1332.61, loanSchedule1.getInterestPaid(), 0.00);
   assertEquals(479.40, loanSchedule1.getPrincipalPaid(), 0.00);
   assertEquals(299520.60, loanSchedule1.getRemainingBalance(), 0.00);
   LoanSchedule loanSchedule2 = loanScheduleArray[1];
   assertEquals(2, loanSchedule2.getPaymentNumber());
   assertEquals(1330.48, loanSchedule2.getInterestPaid(), 0.00);
   assertEquals(481.53, loanSchedule2.getPrincipalPaid(), 0.00);
   assertEquals(299039.07, loanSchedule2.getRemainingBalance(), 0.00);
   LoanSchedule loanSchedule299 = loanScheduleArray[298];
   assertEquals(299, loanSchedule299.getPaymentNumber());
   assertEquals(15.99, loanSchedule299.getInterestPaid(), 0.00);
   assertEquals(1796.02, loanSchedule299.getPrincipalPaid(), 0.00);
   assertEquals(1804.55, loanSchedule299.getRemainingBalance(), 0.00);
   LoanSchedule loanSchedule300 = loanScheduleArray[299];
   assertEquals(300, loanSchedule300.getPaymentNumber());
   assertEquals(8.02, loanSchedule300.getInterestPaid(), 0.00);
   assertEquals(1804.55, loanSchedule300.getPrincipalPaid(), 0.00);
   assertEquals(0.00, loanSchedule300.getRemainingBalance(), 0.00);
 }
  @Test
  public void testSetAmount2() throws Exception {
    System.out.println("setAmount2");

    /* Set up a new loan */
    Loan target = new Loan();

    /* get the setAmount method details */
    Method method = Loan.class.getDeclaredMethod("setAmount", double.class);

    /* make the field assessible */
    method.setAccessible(true);

    /* invoke the method setAmount with the value 3000.0 */
    method.invoke(target, 3000.0);

    /*access the field loanAmount and check its value is set the 3000.0*/
    Class secretClass = target.getClass();
    Field f = secretClass.getDeclaredField("loanAmount");
    f.setAccessible(true);

    double result = f.getDouble(target);

    assertEquals("The amounts should be equal", 3000.00, result, 0.0);
  }
예제 #6
0
  @Test
  public void testGetMonthlyPayment_GetLoanScheduleArray6() {
    Loan loanBean = new Loan(250000, 5.19, 25);
    assertEquals(1481.17, loanBean.getMonthlyPayment(), 0.00);
    LoanSchedule[] loanScheduleArray = loanBean.getLoanScheduleArray();

    LoanSchedule loanSchedule1 = loanScheduleArray[0];
    assertEquals(1, loanSchedule1.getPaymentNumber());
    assertEquals(1069.74, loanSchedule1.getInterestPaid(), 0.00);
    assertEquals(411.43, loanSchedule1.getPrincipalPaid(), 0.00);
    assertEquals(249588.57, loanSchedule1.getRemainingBalance(), 0.00);

    LoanSchedule loanSchedule240 = loanScheduleArray[299];
    assertEquals(300, loanSchedule240.getPaymentNumber());
    assertEquals(6.31, loanSchedule240.getInterestPaid(), 0.00);
    assertEquals(1474.86, loanSchedule240.getPrincipalPaid(), 0.00);
    assertEquals(0.00, loanSchedule240.getRemainingBalance(), 0.00);
  }
예제 #7
0
  @Test
  public void testGetMonthlyPayment_GetLoanScheduleArray1() {
    Loan loanBean = new Loan(1000, 10, 1);
    assertEquals(87.82, loanBean.getMonthlyPayment(), 0.00);

    LoanSchedule[] loanScheduleArray = loanBean.getLoanScheduleArray();

    LoanSchedule loanSchedule1 = loanScheduleArray[0];
    assertEquals(1, loanSchedule1.getPaymentNumber());
    assertEquals(8.16, loanSchedule1.getInterestPaid(), 0.00);
    assertEquals(79.66, loanSchedule1.getPrincipalPaid(), 0.00);
    assertEquals(920.34, loanSchedule1.getRemainingBalance(), 0.00);

    LoanSchedule loanSchedule2 = loanScheduleArray[1];
    assertEquals(2, loanSchedule2.getPaymentNumber());
    assertEquals(7.51, loanSchedule2.getInterestPaid(), 0.00);
    assertEquals(80.31, loanSchedule2.getPrincipalPaid(), 0.00);
    assertEquals(840.03, loanSchedule2.getRemainingBalance(), 0.00);

    LoanSchedule loanSchedule6 = loanScheduleArray[5];
    assertEquals(6, loanSchedule6.getPaymentNumber());
    assertEquals(4.86, loanSchedule6.getInterestPaid(), 0.00);
    assertEquals(82.96, loanSchedule6.getPrincipalPaid(), 0.00);
    assertEquals(512.20, loanSchedule6.getRemainingBalance(), 0.00);
    LoanSchedule loanSchedule7 = loanScheduleArray[6];
    assertEquals(7, loanSchedule7.getPaymentNumber());
    assertEquals(4.18, loanSchedule7.getInterestPaid(), 0.00);
    assertEquals(83.64, loanSchedule7.getPrincipalPaid(), 0.00);
    assertEquals(428.56, loanSchedule7.getRemainingBalance(), 0.00);

    LoanSchedule loanSchedule11 = loanScheduleArray[10];
    assertEquals(11, loanSchedule11.getPaymentNumber());
    assertEquals(1.42, loanSchedule11.getInterestPaid(), 0.00);
    assertEquals(86.40, loanSchedule11.getPrincipalPaid(), 0.00);
    assertEquals(87.13, loanSchedule11.getRemainingBalance(), 0.00);

    LoanSchedule loanSchedule12 = loanScheduleArray[11];
    assertEquals(12, loanSchedule12.getPaymentNumber());
    assertEquals(0.71, loanSchedule12.getInterestPaid(), 0.00);
    assertEquals(87.13, loanSchedule12.getPrincipalPaid(), 0.00);
    assertEquals(0.00, loanSchedule12.getRemainingBalance(), 0.00);
  }
  @Test
  public void testSetPeriod() throws Exception {
    System.out.println("test setPeriod()");

    Loan target = new Loan();

    Method method = Loan.class.getDeclaredMethod("setPeriod", int.class);

    method.setAccessible(true);

    method.invoke(target, 2);

    Class secretClass = target.getClass();
    Field f = secretClass.getDeclaredField("numberOfPayments");
    f.setAccessible(true);

    int result = f.getInt(target);

    assertEquals("The number of payments should be equal", 24, result);
  }
  /** Accessing a private field Test of loanamount, of class Loan. */
  @Test
  public void testSetAmount1() throws Exception {
    System.out.println("setAmount1");
    Loan target = new Loan(4000.0, 10.0, 5);

    /*creat secret class */
    Class secretClass = target.getClass();

    /* The the private field */
    Field f = secretClass.getDeclaredField("loanAmount");

    /*Set tha field to accessible */
    f.setAccessible(true);
    System.out.println("The value in f is " + f.get(target));

    /*get the value of the field */
    double result = f.getDouble(target);

    /*Assert the value is correct */
    assertEquals("The amounts should be equal", 4000.00, result, 0.0);
  }
예제 #10
0
 @Test
 public void testGetMonthlyPayment1() {
   Loan loan1 = new Loan(250000, 5.29, 25);
   assertEquals(1495.56, loan1.getMonthlyPayment(), 0.0);
 }
예제 #11
0
 @Test
 public void testGetMonthlyPayment3() {
   Loan loan3 = new Loan(250000, 5.29, 20);
   assertEquals(1682.18, loan3.getMonthlyPayment(), 0.0);
 }
예제 #12
0
 @Test
 public void testGetMonthlyPayment2() {
   Loan loan2 = new Loan(250000, 3.09, 25);
   assertEquals(1194.69, loan2.getMonthlyPayment(), 0.0);
 }