From 40872fb3cb6a0732969e788d0d98df817c67808b Mon Sep 17 00:00:00 2001 From: Pavan Baloju Date: Thu, 5 Oct 2023 13:29:54 +0530 Subject: [PATCH] Update change calculator test to use assertj (#2147) --- .../src/test/java/ChangeCalculatorTest.java | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/exercises/practice/change/src/test/java/ChangeCalculatorTest.java b/exercises/practice/change/src/test/java/ChangeCalculatorTest.java index a26fc61c8..8e70a8def 100644 --- a/exercises/practice/change/src/test/java/ChangeCalculatorTest.java +++ b/exercises/practice/change/src/test/java/ChangeCalculatorTest.java @@ -1,21 +1,18 @@ -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.Assert.assertEquals; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - import org.junit.Ignore; import org.junit.Test; +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + public class ChangeCalculatorTest { @Test public void testChangeThatCanBeGivenInASingleCoin() { ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 5, 10, 25, 100)); - assertEquals( - singletonList(25), - changeCalculator.computeMostEfficientChange(25)); + assertThat(changeCalculator.computeMostEfficientChange(25)) + .containsExactly(25); } @Ignore("Remove to run test") @@ -23,9 +20,8 @@ public void testChangeThatCanBeGivenInASingleCoin() { public void testChangeThatMustBeGivenInMultipleCoins() { ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 5, 10, 25, 100)); - assertEquals( - asList(5, 10), - changeCalculator.computeMostEfficientChange(15)); + assertThat(changeCalculator.computeMostEfficientChange(15)) + .containsExactly(5, 10); } @Ignore("Remove to run test") @@ -34,9 +30,8 @@ public void testChangeThatMustBeGivenInMultipleCoins() { public void testLilliputianCurrency() { ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 4, 15, 20, 50)); - assertEquals( - asList(4, 4, 15), - changeCalculator.computeMostEfficientChange(23)); + assertThat(changeCalculator.computeMostEfficientChange(23)) + .containsExactly(4, 4, 15); } @Ignore("Remove to run test") @@ -45,9 +40,8 @@ public void testLilliputianCurrency() { public void testLowerElbonianCurrency() { ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 5, 10, 21, 25)); - assertEquals( - asList(21, 21, 21), - changeCalculator.computeMostEfficientChange(63)); + assertThat(changeCalculator.computeMostEfficientChange(63)) + .containsExactly(21, 21, 21); } @Ignore("Remove to run test") @@ -55,9 +49,8 @@ public void testLowerElbonianCurrency() { public void testLargeAmountOfChange() { ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 2, 5, 10, 20, 50, 100)); - assertEquals( - asList(2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100), - changeCalculator.computeMostEfficientChange(999)); + assertThat(changeCalculator.computeMostEfficientChange(999)) + .containsExactly(2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100); } @Ignore("Remove to run test") @@ -66,9 +59,8 @@ public void testLargeAmountOfChange() { public void testPossibleChangeWithoutUnitCoinAvailable() { ChangeCalculator changeCalculator = new ChangeCalculator(asList(2, 5, 10, 20, 50)); - assertEquals( - asList(2, 2, 2, 5, 10), - changeCalculator.computeMostEfficientChange(21)); + assertThat(changeCalculator.computeMostEfficientChange(21)) + .containsExactly(2, 2, 2, 5, 10); } @Ignore("Remove to run test") @@ -77,9 +69,8 @@ public void testPossibleChangeWithoutUnitCoinAvailable() { public void testAnotherPossibleChangeWithoutUnitCoinAvailable() { ChangeCalculator changeCalculator = new ChangeCalculator(asList(4, 5)); - assertEquals( - asList(4, 4, 4, 5, 5, 5), - changeCalculator.computeMostEfficientChange(27)); + assertThat(changeCalculator.computeMostEfficientChange(27)) + .containsExactly(4, 4, 4, 5, 5, 5); } @Ignore("Remove to run test") @@ -87,9 +78,8 @@ public void testAnotherPossibleChangeWithoutUnitCoinAvailable() { public void testZeroChange() { ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 5, 10, 21, 25)); - assertEquals( - emptyList(), - changeCalculator.computeMostEfficientChange(0)); + assertThat(changeCalculator.computeMostEfficientChange(0)) + .isEmpty(); } @Ignore("Remove to run test")