|
1 | | -import static org.assertj.core.api.Assertions.assertThat; |
| 1 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
2 | 2 | import static org.junit.Assert.assertEquals; |
3 | | -import static org.junit.Assert.assertThrows; |
4 | 3 | import static java.util.Arrays.asList; |
5 | 4 | import static java.util.Collections.emptyList; |
6 | 5 | import static java.util.Collections.singletonList; |
@@ -98,41 +97,29 @@ public void testZeroChange() { |
98 | 97 | public void testChangeLessThanSmallestCoinInCurrencyCannotBeRepresented() { |
99 | 98 | ChangeCalculator changeCalculator = new ChangeCalculator(asList(5, 10)); |
100 | 99 |
|
101 | | - IllegalArgumentException expected = |
102 | | - assertThrows( |
103 | | - IllegalArgumentException.class, |
104 | | - () -> changeCalculator.computeMostEfficientChange(3)); |
105 | | - |
106 | | - assertThat(expected) |
107 | | - .hasMessage("The total 3 cannot be represented in the given currency."); |
| 100 | + assertThatExceptionOfType(IllegalArgumentException.class) |
| 101 | + .isThrownBy(() -> changeCalculator.computeMostEfficientChange(3)) |
| 102 | + .withMessage("The total 3 cannot be represented in the given currency."); |
108 | 103 | } |
109 | 104 |
|
110 | 105 | @Ignore("Remove to run test") |
111 | 106 | @Test |
112 | 107 | public void testChangeLargerThanAllCoinsInCurrencyThatCannotBeRepresented() { |
113 | 108 | ChangeCalculator changeCalculator = new ChangeCalculator(asList(5, 10)); |
114 | 109 |
|
115 | | - IllegalArgumentException expected = |
116 | | - assertThrows( |
117 | | - IllegalArgumentException.class, |
118 | | - () -> changeCalculator.computeMostEfficientChange(94)); |
119 | | - |
120 | | - assertThat(expected) |
121 | | - .hasMessage("The total 94 cannot be represented in the given currency."); |
| 110 | + assertThatExceptionOfType(IllegalArgumentException.class) |
| 111 | + .isThrownBy(() -> changeCalculator.computeMostEfficientChange(94)) |
| 112 | + .withMessage("The total 94 cannot be represented in the given currency."); |
122 | 113 | } |
123 | 114 |
|
124 | 115 | @Ignore("Remove to run test") |
125 | 116 | @Test |
126 | 117 | public void testNegativeChangeIsRejected() { |
127 | 118 | ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 2, 5)); |
128 | 119 |
|
129 | | - IllegalArgumentException expected = |
130 | | - assertThrows( |
131 | | - IllegalArgumentException.class, |
132 | | - () -> changeCalculator.computeMostEfficientChange(-5)); |
133 | | - |
134 | | - assertThat(expected) |
135 | | - .hasMessage("Negative totals are not allowed."); |
| 120 | + assertThatExceptionOfType(IllegalArgumentException.class) |
| 121 | + .isThrownBy(() -> changeCalculator.computeMostEfficientChange(-5)) |
| 122 | + .withMessage("Negative totals are not allowed."); |
136 | 123 | } |
137 | 124 |
|
138 | 125 | } |
0 commit comments