1
1
import static org .junit .Assert .assertEquals ;
2
2
3
3
import java .util .ArrayList ;
4
+ import java .util .List ;
4
5
5
6
import org .junit .Before ;
6
7
import org .junit .Test ;
7
8
8
9
public class VendingMachineTest {
9
10
10
- private static final Double DIME = (Double ) 0.10 ;
11
- private static final Double NICKEL = (Double ) 0.05 ;
12
- private static final Double PENNY = (Double ) 0.01 ;
11
+
13
12
private static final Double NO_COIN = (Double ) 0.0 ;
14
- private static final Double QUARTER_VALUE = (Double ) 0.25 ;
15
13
16
14
private VendingMachine vendingMachine ;
17
15
@@ -25,49 +23,56 @@ public void shouldAcceptQuarter() {
25
23
26
24
vendingMachine .insert (Coin .QUARTER );
27
25
28
- assertEquals (QUARTER_VALUE , vendingMachine .getCurrentAmount ());
26
+ assertEquals (Coin . QUARTER . getValue () , vendingMachine .getCurrentAmount ());
29
27
}
30
28
31
29
@ Test
32
30
public void shouldResetCurrentAmountEqualToZeroWhenReturnCoinsIsPressed () {
33
31
34
- vendingMachine .setCurrentAmount (QUARTER_VALUE );
32
+ vendingMachine .setCurrentAmount (Coin . QUARTER . getValue () );
35
33
36
34
vendingMachine .returnCoins ();
37
35
38
36
assertEquals (NO_COIN , vendingMachine .getCurrentAmount ());
39
37
}
40
38
41
39
@ Test
42
- public void shouldNotAcceptPenny () {
40
+ public void pennyShouldGoToCoinReturn () {
43
41
vendingMachine .insert (Coin .PENNY );
44
42
45
- assertEquals (PENNY , vendingMachine .getCoinReturnAmount ());
43
+ assertEquals (Coin . PENNY . getValue () , vendingMachine .getCoinReturnAmount ());
46
44
}
47
45
46
+ @ Test
47
+ public void shouldNotAddPennyToCurrentValue () {
48
+ vendingMachine .insert (Coin .PENNY );
49
+
50
+ assertEquals (NO_COIN , vendingMachine .getCurrentAmount ());
51
+ }
52
+
48
53
@ Test
49
54
public void shouldAcceptNickel () {
50
55
vendingMachine .insert (Coin .NICKEL );
51
56
52
- assertEquals (NICKEL , vendingMachine .getCurrentAmount ());
57
+ assertEquals (Coin . NICKEL . getValue () , vendingMachine .getCurrentAmount ());
53
58
}
54
59
55
60
@ Test
56
61
public void shouldAcceptDime () {
57
62
vendingMachine .insert (Coin .DIME );
58
63
59
- assertEquals (DIME , vendingMachine .getCurrentAmount ());
64
+ assertEquals (Coin . DIME . getValue () , vendingMachine .getCurrentAmount ());
60
65
}
61
66
62
67
@ Test
63
68
public void pressingCoinReturnShouldReturnExactCoinsInserted () {
64
69
insertFiftyCentsInQuarters ();
65
70
vendingMachine .insert (Coin .NICKEL );
66
71
67
- ArrayList < Double > expectedCoinList = new ArrayList <Double >();
68
- expectedCoinList .add (QUARTER_VALUE );
69
- expectedCoinList .add (QUARTER_VALUE );
70
- expectedCoinList .add (NICKEL );
72
+ List < Coin > expectedCoinList = new ArrayList <Coin >();
73
+ expectedCoinList .add (Coin . QUARTER );
74
+ expectedCoinList .add (Coin . QUARTER );
75
+ expectedCoinList .add (Coin . NICKEL );
71
76
72
77
assertEquals (expectedCoinList , vendingMachine .returnCoins ());
73
78
}
@@ -78,11 +83,11 @@ public void returnCoinSlotShouldHoldAllCoinsReturned() {
78
83
insertFiftyCentsInQuarters ();
79
84
vendingMachine .insert (Coin .NICKEL );
80
85
81
- ArrayList < Double > expectedCoinList = new ArrayList <Double >();
82
- expectedCoinList .add (PENNY );
83
- expectedCoinList .add (QUARTER_VALUE );
84
- expectedCoinList .add (QUARTER_VALUE );
85
- expectedCoinList .add (NICKEL );
86
+ List < Coin > expectedCoinList = new ArrayList <Coin >();
87
+ expectedCoinList .add (Coin . PENNY );
88
+ expectedCoinList .add (Coin . QUARTER );
89
+ expectedCoinList .add (Coin . QUARTER );
90
+ expectedCoinList .add (Coin . NICKEL );
86
91
87
92
vendingMachine .returnCoins ();
88
93
@@ -206,7 +211,7 @@ public void machineShouldMakeChangeIfTooMuchMoneyPaidForSoda() {
206
211
vendingMachine .sodaButton ();
207
212
vendingMachine .returnCoins ();
208
213
209
- assertEquals (QUARTER_VALUE , vendingMachine .getCoinReturnAmount ());
214
+ assertEquals (Coin . QUARTER . getValue () , vendingMachine .getCoinReturnAmount ());
210
215
}
211
216
212
217
private void insertDollarInQuarters () {
0 commit comments