Ejemplo n.º 1
0
  @Test
  public void accountStartDate() throws Exception {
    Document d = ModelFactory.createDocument();
    AccountType at = d.getAccountType("Cash");
    Account a = ModelFactory.createAccount("Test", at);
    BudgetCategory bc = d.getBudgetCategory("Groceries");
    d.addAccount(a);

    // StartDate == null, No transactions; return today
    // We wrap each in getStartOfDay() to avoid millisecond differences, if the get()
    // method takes a few millis.
    assertEquals(DateUtil.getStartOfDay(a.getStartDate()), DateUtil.getStartOfDay(new Date()));

    // StartDate != null, No transactions; return startDate
    Date startDate = DateUtil.getDate(2007, Calendar.JANUARY, 3);
    a.setStartDate(startDate);
    assertEquals(startDate, a.getStartDate());

    // StartDate != null, Transactions exist, and are after startDate; return startDate
    Transaction t =
        ModelFactory.createTransaction(
            DateUtil.getDate(2007, Calendar.JANUARY, 5), "Test", 1234, a, bc);
    d.addTransaction(t);
    assertEquals(a.getStartDate(), startDate);

    // StartDate != null, Transactions exist, and are before startDate; return first transaction
    t =
        ModelFactory.createTransaction(
            DateUtil.getDate(2007, Calendar.JANUARY, 1), "Test", 1234, a, bc);
    d.addTransaction(t);
    assertEquals(a.getStartDate(), DateUtil.getDate(2007, Calendar.JANUARY, 1));

    // StartDate == null, Transactions exist; return first transaction
    a.setStartDate(null);
    assertEquals(a.getStartDate(), DateUtil.getDate(2007, Calendar.JANUARY, 1));
  }
Ejemplo n.º 2
0
  @Test
  public void testGetBalanceDate() {
    try {
      Document d = ModelFactory.createDocument();
      AccountType at = d.getAccountType("Cash");
      Account a = ModelFactory.createAccount("Test", at);
      d.addAccount(a);

      d.addTransaction(
          ModelFactory.createTransaction(
              DateUtil.getDate(2007, Calendar.AUGUST, 1),
              "Test 1",
              100,
              a,
              d.getBudgetCategory("Groceries")));
      d.addTransaction(
          ModelFactory.createTransaction(
              DateUtil.getDate(2007, Calendar.AUGUST, 5),
              "Test 2",
              100,
              a,
              d.getBudgetCategory("Groceries")));
      d.addTransaction(
          ModelFactory.createTransaction(
              DateUtil.getDate(2007, Calendar.AUGUST, 10),
              "Test 3",
              -100,
              a,
              d.getBudgetCategory("Groceries")));
      d.addTransaction(
          ModelFactory.createTransaction(
              DateUtil.getDate(2007, Calendar.SEPTEMBER, 1),
              "Test 4",
              -100,
              a,
              d.getBudgetCategory("Groceries")));
      d.addTransaction(
          ModelFactory.createTransaction(
              DateUtil.getDate(2007, Calendar.SEPTEMBER, 2),
              "Test 5",
              -100,
              a,
              d.getBudgetCategory("Groceries")));

      d.updateAllBalances();

      Object[][] tests = {
        {DateUtil.getDate(2007, Calendar.JULY, 30), 0l},
        {DateUtil.getDate(2007, Calendar.AUGUST, 1), -100l},
        {DateUtil.getDate(2007, Calendar.AUGUST, 2), -100l},
        {DateUtil.getDate(2007, Calendar.AUGUST, 4), -100l},
        {DateUtil.getDate(2007, Calendar.AUGUST, 5), -200l},
        {DateUtil.getDate(2007, Calendar.AUGUST, 6), -200l},
        {DateUtil.getDate(2007, Calendar.AUGUST, 30), -100l},
        {DateUtil.getDate(2007, Calendar.SEPTEMBER, 3), 100l}
      };

      for (Object[] test : tests) {
        assertEquals((Long) test[1], (Long) a.getBalance((Date) test[0]));
      }
    } catch (Exception e) {
      fail("Exception: " + e);
    }
  }