Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

End of episode 128

  • Loading branch information...
commit 5d43b649889912c3ee5a8f98714f38563b15d046 1 parent df0b947
@jamesshore authored
View
10 scratchpad.txt
@@ -1,9 +1,3 @@
-Add remaining fields so that starting conditions can be set at runtime
-
-Address duplication for DollarsTextField configuration in ConfigurationPanel (tests and production)
-
-Why are first year's sales changing when cost basis is changed through UI?
-
Why is starting balance field not turning red when negative?
When tabbing to DollarsTextField, should the value be selected?
@@ -14,6 +8,10 @@ Need to handle case where cost basis is larger than starting balance--that shoul
---
+Add remaining fields so that starting conditions can be set at runtime
+
+---
+
Check that keyboard shortcuts work (including tabbing between components)
Run Swing-related stuff on event dispatching thread: http://download.oracle.com/javase/6/docs/api/javax/swing/package-summary.html#threading
View
5 src/com/jamesshore/finances/ui/ApplicationModel.java
@@ -48,6 +48,11 @@ public void setStartingCostBasis(Dollars startingCostBasis) {
stockMarketTableModel.setProjection(stockMarketProjection());
}
+ public void setYearlySpending(Dollars yearlySpending) {
+ this.yearlySpending = yearlySpending;
+ stockMarketTableModel.setProjection(stockMarketProjection());
+ }
+
public StockMarketProjection stockMarketProjection() {
StockMarketYear firstYear = new StockMarketYear(startingYear, startingBalance, startingCostBasis, growthRate, capitalGainsTaxRate);
return new StockMarketProjection(firstYear, endingYear, yearlySpending);
View
5 src/com/jamesshore/finances/ui/ConfigurationPanel.java
@@ -47,6 +47,11 @@ public void textChanged() {
private DollarsTextField yearlySpendingField() {
final DollarsTextField field = new DollarsTextField(applicationModel.yearlySpending());
+ field.addTextChangeListener(new ChangeListener() {
+ public void textChanged() {
+ applicationModel.setYearlySpending(field.getDollars());
+ }
+ });
return field;
}
}
View
4 src/com/jamesshore/finances/ui/StockMarketTableModel.java
@@ -72,4 +72,8 @@ public Dollars startingBalance() {
public Dollars startingCostBasis() {
return projection.getYearOffset(0).startingCostBasis();
}
+
+ public Dollars yearlySpending() {
+ return projection.getYearOffset(0).totalSellOrders();
+ }
}
View
6 src/com/jamesshore/finances/ui/_ApplicationModelTest.java
@@ -45,4 +45,10 @@ public void changingStartingCostBasisShouldChangeStockMarketTableModel() {
assertEquals(ValidDollars.create(39), model.stockMarketTableModel().startingCostBasis());
}
+ @Test
+ public void changingYearlySpendingShouldChangeStockMarketTableModel() {
+ model.setYearlySpending(ValidDollars.create(423));
+ assertEquals(ValidDollars.create(423), model.stockMarketTableModel().yearlySpending());
+ }
+
}
View
19 src/com/jamesshore/finances/ui/_ConfigurationPanelTest.java
@@ -78,12 +78,11 @@ public void costBasisFieldUpdatesApplicationModel() {
@Test
public void yearlySpendingFieldUpdatesApplicationModel() {
- // MockApplicationModel mockModel = new MockApplicationModel();
- // panel = new ConfigurationPanel(mockModel);
- //
- // costBasisField().setText("672");
- // assertEquals("applicationModel should be updated", ValidDollars.create(672),
- // mockModel.setYearlySpendingCalledWith);
+ MockApplicationModel mockModel = new MockApplicationModel();
+ panel = new ConfigurationPanel(mockModel);
+
+ yearlySpendingField().setText("672");
+ assertEquals("applicationModel should be updated", ValidDollars.create(672), mockModel.setYearlySpendingCalledWith);
}
@@ -102,10 +101,10 @@ public void setStartingCostBasis(Dollars startingCostBasis) {
setStartingCostBasisCalledWith = startingCostBasis;
}
- // @Override
- // public void setYearlySpending(Dollars yearlySpending) {
- // setYearlySpendingCalledWith = yearlySpending;
- // }
+ @Override
+ public void setYearlySpending(Dollars yearlySpending) {
+ setYearlySpendingCalledWith = yearlySpending;
+ }
}
}
View
24 src/com/jamesshore/finances/ui/_StockMarketTableModelTest.java
@@ -11,6 +11,7 @@
private static final Year ENDING_YEAR = new Year(2050);
private static final Dollars STARTING_BALANCE = ValidDollars.create(10000);
private static final Dollars STARTING_COST_BASIS = ValidDollars.create(7000);
+ private static final Dollars YEARLY_SPENDING = ValidDollars.create(36);
private StockMarketYear startingYear;
private StockMarketTableModel model;
@@ -18,11 +19,18 @@
@Before
public void setup() {
startingYear = new StockMarketYear(STARTING_YEAR, STARTING_BALANCE, STARTING_COST_BASIS, new GrowthRate(10), new TaxRate(25));
- StockMarketProjection projection = new StockMarketProjection(startingYear, ENDING_YEAR, ValidDollars.create(0));
+ StockMarketProjection projection = new StockMarketProjection(startingYear, ENDING_YEAR, YEARLY_SPENDING);
model = new StockMarketTableModel(projection);
}
@Test
+ public void startingValues() {
+ assertEquals(STARTING_BALANCE, model.startingBalance());
+ assertEquals(STARTING_COST_BASIS, model.startingCostBasis());
+ assertEquals(YEARLY_SPENDING, model.yearlySpending());
+ }
+
+ @Test
public void columns() {
assertEquals(6, model.getColumnCount());
assertEquals("Year", model.getColumnName(0));
@@ -46,9 +54,9 @@ public void oneRow() {
assertEquals("year", STARTING_YEAR, model.getValueAt(0, 0));
assertEquals("starting balance", STARTING_BALANCE, model.getValueAt(0, 1));
assertEquals("starting principal", STARTING_COST_BASIS, model.getValueAt(0, 2));
- assertEquals("withdrawals", ValidDollars.create(0), model.getValueAt(0, 3));
- assertEquals("appreciation", ValidDollars.create(1000), model.getValueAt(0, 4));
- assertEquals("ending balance", ValidDollars.create(11000), model.getValueAt(0, 5));
+ assertEquals("withdrawals", ValidDollars.create(48), model.getValueAt(0, 3));
+ assertEquals("appreciation", ValidDollars.create(995), model.getValueAt(0, 4));
+ assertEquals("ending balance", ValidDollars.create(10947), model.getValueAt(0, 5));
}
@Test
@@ -56,7 +64,7 @@ public void multipleRows() {
assertEquals(41, model.getRowCount());
assertEquals(STARTING_YEAR, model.getValueAt(0, 0));
assertEquals(STARTING_BALANCE, model.getValueAt(0, 1));
- assertEquals(ValidDollars.create(11000), model.getValueAt(1, 1));
+ assertEquals(ValidDollars.create(10947), model.getValueAt(1, 1));
assertEquals(ENDING_YEAR, model.getValueAt(40, 0));
}
@@ -92,10 +100,4 @@ public void tableChanged(TableModelEvent e) {
assertEquals("whole table should change (last row)", Integer.MAX_VALUE, listener.lastRowChanged.intValue());
}
- @Test
- public void startingValues() {
- assertEquals(STARTING_BALANCE, model.startingBalance());
- assertEquals(STARTING_COST_BASIS, model.startingCostBasis());
- }
-
}
Please sign in to comment.
Something went wrong with that request. Please try again.