TestAccountpublic class TestAccount extends TestCase
Fields Summary |
---|
private AccountTableModel | acctTableModel | private Account[] | accounts |
Constructors Summary |
---|
public TestAccount(String name)
super(name);
|
Methods Summary |
---|
protected void | setUp()
this.acctTableModel = new AccountTableModel();
for (int i = 0; i < this.accounts.length; i++) {
this.acctTableModel.addAccount(this.accounts[i]);
}
| public void | testAddAccountEvent()
MockTableModelListener mockListener = new MockTableModelListener();
mockListener.setExpectedEventCount(1);
TableModelEvent evt = new TableModelEvent(
this.acctTableModel,
this.accounts.length,
this.accounts.length,
TableModelEvent.ALL_COLUMNS,
TableModelEvent.INSERT);
mockListener.addExpectedEvent(evt);
this.acctTableModel.addTableModelListener(mockListener);
this.acctTableModel.addAccount(new Account(
Account.CHECKING, "12345", 100.50));
mockListener.verify();
| public void | testAddAccountEventBasic()
MockTableModelListener mockListener = new MockTableModelListener();
this.acctTableModel.addTableModelListener(mockListener);
this.acctTableModel.addAccount(new Account(
Account.CHECKING, "12345", 100.50));
assertEquals("Event count", 1, mockListener.getEventCount());
TableModelEvent evt = (TableModelEvent)
mockListener.getEvents().get(0);
assertEquals("Event type",
TableModelEvent.INSERT, evt.getType());
assertEquals("Column",
TableModelEvent.ALL_COLUMNS, evt.getColumn());
assertEquals("First row",
this.acctTableModel.getRowCount()-1,
evt.getFirstRow());
assertEquals("Last row",
this.acctTableModel.getRowCount()-1,
evt.getLastRow());
| public void | testBalanceToString()
assertEquals("balanceToString()", "1.00",
Account.balanceToString(1.00));
assertEquals("balanceToString()", "100000.00",
Account.balanceToString(100000));
assertEquals("balanceToString()", "1.00",
Account.balanceToString(1.0));
assertEquals("balanceToString()", "0.56",
Account.balanceToString(0.56));
assertEquals("balanceToString()", "10.02",
Account.balanceToString(10.019));
| public void | testGetRowCount()
assertEquals("row count", this.accounts.length,
this.acctTableModel.getRowCount());
| public void | testGetValueAt()
for (int row = 0; row < this.accounts.length; row++) {
Integer typeInteger = (Integer) this.acctTableModel.
getValueAt(row, AccountTableModel.ACCT_TYPE_COL);
assertEquals("account type",
this.accounts[row].getAccountType(),
typeInteger.intValue());
assertEquals("account number",
this.accounts[row].getAccountNumber(),
this.acctTableModel.getValueAt(
row, AccountTableModel.ACCT_NUMBER_COL));
Double balanceDouble = (Double) this.acctTableModel.
getValueAt(row, AccountTableModel.ACCT_BALANCE_COL);
assertEquals("account balance",
this.accounts[row].getBalance(),
balanceDouble.doubleValue(), 0.001);
}
| public void | testPropertyChangeEvent1()
Account acct = new Account(Account.CHECKING, "123", 0.0);
MockPropertyChangeListener pcl = new MockPropertyChangeListener();
pcl.addExpectedEvent(new PropertyChangeEvent(acct,
"balance", new Double(0.0), new Double(100.0)));
acct.addPropertyChangeListener(pcl);
acct.setBalance(100.0);
pcl.verify();
| public void | testPropertyChangeEvent2()
Account acct = new Account(Account.CHECKING, "123", 0.0);
MockPropertyChangeListener pcl = new MockPropertyChangeListener();
pcl.setExpectedEventCount(1);
acct.addPropertyChangeListener(pcl);
acct.setBalance(100.0);
pcl.verify();
| public void | testWithoutMock()
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Account acct = new Account(Account.CHECKING, "123", 1874.93);
acct.writeCsv(pw);
assertEquals("CSV Output", "CHECKING,123,1874.93", sw.toString());
| public void | testWriteCheckingCsv()
MockPrintWriter writer = new MockPrintWriter();
writer.setExpectedOutput("CHECKING,123,1874.93");
Account acct = new Account(Account.CHECKING, "123", 1874.93);
acct.writeCsv(writer);
writer.verify();
| public void | testWriteSavingsCsv()
MockPrintWriter writer = new MockPrintWriter();
writer.setExpectedOutput("SAVINGS,456,1.00");
Account acct = new Account(Account.SAVINGS, "456", 1.00);
acct.writeCsv(writer);
writer.verify();
|
|