From c1332c0f48eb06a03f63bc4dbccc5f44efd1a790 Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 15:31:56 +0000 Subject: [PATCH 01/12] Migrate robot-name tests to AssertJ. --- exercises/robot-name/build.gradle | 1 + exercises/robot-name/src/test/java/RobotTest.java | 13 +++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/exercises/robot-name/build.gradle b/exercises/robot-name/build.gradle index 82d705dfd..952e38529 100644 --- a/exercises/robot-name/build.gradle +++ b/exercises/robot-name/build.gradle @@ -8,6 +8,7 @@ repositories { dependencies { testCompile "junit:junit:4.12" + testImplementation "org.assertj:assertj-core:3.15.0" } test { diff --git a/exercises/robot-name/src/test/java/RobotTest.java b/exercises/robot-name/src/test/java/RobotTest.java index e3106138d..7346f97eb 100644 --- a/exercises/robot-name/src/test/java/RobotTest.java +++ b/exercises/robot-name/src/test/java/RobotTest.java @@ -1,12 +1,9 @@ +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; import org.junit.Ignore; import org.junit.Before; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertThat; - public class RobotTest { private static final String EXPECTED_ROBOT_NAME_PATTERN = "[A-Z]{2}\\d{3}"; @@ -25,7 +22,7 @@ public void hasName() { @Ignore("Remove to run test") @Test public void differentRobotsHaveDifferentNames() { - assertThat(robot.getName(), not(equalTo(new Robot().getName()))); + assertThat(robot.getName()).isNotEqualTo(new Robot().getName()); } @Ignore("Remove to run test") @@ -34,11 +31,11 @@ public void resetName() { final String name = robot.getName(); robot.reset(); final String name2 = robot.getName(); - assertThat(name, not(equalTo(name2))); + assertThat(name).isNotEqualTo(name2); assertIsValidName(name2); } private static void assertIsValidName(String name) { - assertThat(name.matches(EXPECTED_ROBOT_NAME_PATTERN), is(true)); + assertThat(name).matches(EXPECTED_ROBOT_NAME_PATTERN); } } From 3dcf0512bc52fc83b2d8f2cc6844fdb9e3cbc575 Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 16:04:25 +0000 Subject: [PATCH 02/12] Migrate nucleotide-count to AssertJ. --- exercises/nucleotide-count/build.gradle | 4 +- .../src/test/java/NucleotideCounterTest.java | 49 +++++++------------ 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/exercises/nucleotide-count/build.gradle b/exercises/nucleotide-count/build.gradle index 45a3918a0..141356913 100644 --- a/exercises/nucleotide-count/build.gradle +++ b/exercises/nucleotide-count/build.gradle @@ -8,12 +8,12 @@ repositories { dependencies { testCompile "junit:junit:4.12" - testCompile 'org.hamcrest:hamcrest-library:1.3' + testImplementation "org.assertj:assertj-core:3.15.0" } test { testLogging { - exceptionFormat = 'short' + exceptionFormat = 'full' showStandardStreams = true events = ["passed", "failed", "skipped"] } diff --git a/exercises/nucleotide-count/src/test/java/NucleotideCounterTest.java b/exercises/nucleotide-count/src/test/java/NucleotideCounterTest.java index 29e9836d8..968b5260e 100644 --- a/exercises/nucleotide-count/src/test/java/NucleotideCounterTest.java +++ b/exercises/nucleotide-count/src/test/java/NucleotideCounterTest.java @@ -1,3 +1,5 @@ +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Ignore; import org.junit.Test; import org.junit.Rule; @@ -5,9 +7,6 @@ import java.util.Map; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - public class NucleotideCounterTest { @Rule @@ -16,39 +15,30 @@ public class NucleotideCounterTest { @Test public void testEmptyDnaStringHasNoNucleotides() { NucleotideCounter nucleotideCounter = new NucleotideCounter(""); - Map counts = nucleotideCounter.nucleotideCounts(); - assertThat(counts, allOf( - hasEntry('A', 0), - hasEntry('C', 0), - hasEntry('G', 0), - hasEntry('T', 0) - )); + + assertThat(nucleotideCounter.nucleotideCounts()) + .containsExactlyInAnyOrderEntriesOf​( + Map.of('A', 0, 'C', 0, 'G', 0, 'T', 0)); } @Ignore("Remove to run test") @Test public void testDnaStringHasOneNucleotide() { NucleotideCounter nucleotideCounter = new NucleotideCounter("G"); - Map counts = nucleotideCounter.nucleotideCounts(); - assertThat(counts, allOf( - hasEntry('A', 0), - hasEntry('C', 0), - hasEntry('G', 1), - hasEntry('T', 0) - )); + + assertThat(nucleotideCounter.nucleotideCounts()) + .containsExactlyInAnyOrderEntriesOf​( + Map.of('A', 0, 'C', 0, 'G', 1, 'T', 0)); } @Ignore("Remove to run test") @Test public void testRepetitiveSequenceWithOnlyGuanine() { NucleotideCounter nucleotideCounter = new NucleotideCounter("GGGGGGG"); - Map counts = nucleotideCounter.nucleotideCounts(); - assertThat(counts, allOf( - hasEntry('A', 0), - hasEntry('C', 0), - hasEntry('G', 7), - hasEntry('T', 0) - )); + + assertThat(nucleotideCounter.nucleotideCounts()) + .containsExactlyInAnyOrderEntriesOf​( + Map.of('A', 0, 'C', 0, 'G', 7, 'T', 0)); } @Ignore("Remove to run test") @@ -56,13 +46,10 @@ public void testRepetitiveSequenceWithOnlyGuanine() { public void testDnaStringHasMultipleNucleotide() { NucleotideCounter nucleotideCounter = new NucleotideCounter("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"); - Map counts = nucleotideCounter.nucleotideCounts(); - assertThat(counts, allOf( - hasEntry('A', 20), - hasEntry('C', 12), - hasEntry('G', 17), - hasEntry('T', 21) - )); + + assertThat(nucleotideCounter.nucleotideCounts()) + .containsExactlyInAnyOrderEntriesOf​( + Map.of('A', 20, 'C', 12, 'G', 17, 'T', 21)); } @Ignore("Remove to run test") From 1e9a2e6bdb61a08dd6a9121dde67d1259c73e784 Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 16:26:17 +0000 Subject: [PATCH 03/12] Remove unused hamcrest dependency in grade-school. --- exercises/grade-school/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/grade-school/build.gradle b/exercises/grade-school/build.gradle index 64eed3f41..82d705dfd 100644 --- a/exercises/grade-school/build.gradle +++ b/exercises/grade-school/build.gradle @@ -7,7 +7,6 @@ repositories { } dependencies { - testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3' testCompile "junit:junit:4.12" } From b441d339ab78c6e368d480356f1e45762be5ded8 Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 16:29:48 +0000 Subject: [PATCH 04/12] Migrate nth-prime to AssertJ. --- exercises/nth-prime/build.gradle | 1 + .../src/test/java/PrimeCalculatorTest.java | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/exercises/nth-prime/build.gradle b/exercises/nth-prime/build.gradle index 82d705dfd..952e38529 100644 --- a/exercises/nth-prime/build.gradle +++ b/exercises/nth-prime/build.gradle @@ -8,6 +8,7 @@ repositories { dependencies { testCompile "junit:junit:4.12" + testImplementation "org.assertj:assertj-core:3.15.0" } test { diff --git a/exercises/nth-prime/src/test/java/PrimeCalculatorTest.java b/exercises/nth-prime/src/test/java/PrimeCalculatorTest.java index f4b8de1c5..b59c4b245 100644 --- a/exercises/nth-prime/src/test/java/PrimeCalculatorTest.java +++ b/exercises/nth-prime/src/test/java/PrimeCalculatorTest.java @@ -1,12 +1,11 @@ +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; - public class PrimeCalculatorTest { private PrimeCalculator primeCalculator; @@ -20,25 +19,25 @@ public void setup() { @Test public void testFirstPrime() { - assertThat(primeCalculator.nth(1), is(2)); + assertThat(primeCalculator.nth(1)).isEqualTo(2); } @Ignore("Remove to run test") @Test public void testSecondPrime() { - assertThat(primeCalculator.nth(2), is(3)); + assertThat(primeCalculator.nth(2)).isEqualTo(3); } @Ignore("Remove to run test") @Test public void testSixthPrime() { - assertThat(primeCalculator.nth(6), is(13)); + assertThat(primeCalculator.nth(6)).isEqualTo(13); } @Ignore("Remove to run test") @Test public void testBigPrime() { - assertThat(primeCalculator.nth(10001), is(104743)); + assertThat(primeCalculator.nth(10001)).isEqualTo(104743); } @Ignore("Remove to run test") From 657f15de91e139ccf93cced8c43d587890ba674c Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 16:36:52 +0000 Subject: [PATCH 05/12] Migrate diamond to AssertJ. --- exercises/diamond/build.gradle | 1 + .../src/test/java/DiamondPrinterTest.java | 155 +++++++++--------- 2 files changed, 79 insertions(+), 77 deletions(-) diff --git a/exercises/diamond/build.gradle b/exercises/diamond/build.gradle index 82d705dfd..952e38529 100644 --- a/exercises/diamond/build.gradle +++ b/exercises/diamond/build.gradle @@ -8,6 +8,7 @@ repositories { dependencies { testCompile "junit:junit:4.12" + testImplementation "org.assertj:assertj-core:3.15.0" } test { diff --git a/exercises/diamond/src/test/java/DiamondPrinterTest.java b/exercises/diamond/src/test/java/DiamondPrinterTest.java index ba21ffec9..d9d894c84 100644 --- a/exercises/diamond/src/test/java/DiamondPrinterTest.java +++ b/exercises/diamond/src/test/java/DiamondPrinterTest.java @@ -1,14 +1,11 @@ +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Ignore; import org.junit.Before; import org.junit.Test; import java.util.List; -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - public class DiamondPrinterTest { private DiamondPrinter diamondPrinter; @@ -20,98 +17,102 @@ public void setUp() { @Test public void testOneByOneDiamond() { - List output = diamondPrinter.printToList('A'); - assertThat(output, is(singletonList("A"))); + assertThat(diamondPrinter.printToList('A')) + .containsExactly("A"); } @Ignore("Remove to run test") @Test public void testTwoByTwoDiamond() { - List output = diamondPrinter.printToList('B'); - assertThat(output, is(asList(" A ", - "B B", - " A "))); + assertThat(diamondPrinter.printToList('B')) + .containsExactly( + " A ", + "B B", + " A "); } @Ignore("Remove to run test") @Test public void testThreeByThreeDiamond() { - List output = diamondPrinter.printToList('C'); - assertThat(output, is(asList(" A ", - " B B ", - "C C", - " B B ", - " A "))); + assertThat(diamondPrinter.printToList('C')) + .containsExactly( + " A ", + " B B ", + "C C", + " B B ", + " A "); } @Ignore("Remove to run test") @Test public void testFourByFourDiamond() { - List output = diamondPrinter.printToList('D'); - assertThat(output, is(asList(" A ", - " B B ", - " C C ", - "D D", - " C C ", - " B B ", - " A "))); + assertThat(diamondPrinter.printToList('D')) + .containsExactly( + " A ", + " B B ", + " C C ", + "D D", + " C C ", + " B B ", + " A "); } @Ignore("Remove to run test") @Test public void testFullDiamond() { - List output = diamondPrinter.printToList('Z'); - assertThat(output, is(asList(" A ", - " B B ", - " C C ", - " D D ", - " E E ", - " F F ", - " G G ", - " H H ", - " I I ", - " J J ", - " K K ", - " L L ", - " M M ", - " N N ", - " O O ", - " P P ", - " Q Q ", - " R R ", - " S S ", - " T T ", - " U U ", - " V V ", - " W W ", - " X X ", - " Y Y ", - "Z Z", - " Y Y ", - " X X ", - " W W ", - " V V ", - " U U ", - " T T ", - " S S ", - " R R ", - " Q Q ", - " P P ", - " O O ", - " N N ", - " M M ", - " L L ", - " K K ", - " J J ", - " I I ", - " H H ", - " G G ", - " F F ", - " E E ", - " D D ", - " C C ", - " B B ", - " A "))); + assertThat(diamondPrinter.printToList('Z')) + .containsExactly( + " A ", + " B B ", + " C C ", + " D D ", + " E E ", + " F F ", + " G G ", + " H H ", + " I I ", + " J J ", + " K K ", + " L L ", + " M M ", + " N N ", + " O O ", + " P P ", + " Q Q ", + " R R ", + " S S ", + " T T ", + " U U ", + " V V ", + " W W ", + " X X ", + " Y Y ", + "Z Z", + " Y Y ", + " X X ", + " W W ", + " V V ", + " U U ", + " T T ", + " S S ", + " R R ", + " Q Q ", + " P P ", + " O O ", + " N N ", + " M M ", + " L L ", + " K K ", + " J J ", + " I I ", + " H H ", + " G G ", + " F F ", + " E E ", + " D D ", + " C C ", + " B B ", + " A "); } } From d29be0f5549119e6765767fdccced8f786fcc574 Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 16:49:45 +0000 Subject: [PATCH 06/12] Migrate simple-linked-list to AssertJ. --- exercises/simple-linked-list/build.gradle | 1 + .../src/test/java/SimpleLinkedListTest.java | 28 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/exercises/simple-linked-list/build.gradle b/exercises/simple-linked-list/build.gradle index 82d705dfd..952e38529 100644 --- a/exercises/simple-linked-list/build.gradle +++ b/exercises/simple-linked-list/build.gradle @@ -8,6 +8,7 @@ repositories { dependencies { testCompile "junit:junit:4.12" + testImplementation "org.assertj:assertj-core:3.15.0" } test { diff --git a/exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java b/exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java index 02f465921..600c7f632 100644 --- a/exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java +++ b/exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java @@ -1,3 +1,6 @@ +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertArrayEquals; + import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -5,9 +8,6 @@ import java.util.NoSuchElementException; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; - public class SimpleLinkedListTest { @Rule @@ -16,7 +16,7 @@ public class SimpleLinkedListTest { @Test public void aNewListIsEmpty() { SimpleLinkedList list = new SimpleLinkedList<>(); - assertThat(list.size(), is(0)); + assertThat(list.size()).isEqualTo(0); } @Ignore("Remove to run test") @@ -24,7 +24,7 @@ public void aNewListIsEmpty() { public void canCreateFromArray() { Character[] values = new Character[]{'1', '2', '3'}; SimpleLinkedList list = new SimpleLinkedList(values); - assertThat(list.size(), is(3)); + assertThat(list.size()).isEqualTo(3); } @Ignore("Remove to run test") @@ -41,10 +41,10 @@ public void popReturnsLastAddedElement() { SimpleLinkedList list = new SimpleLinkedList(); list.push(9); list.push(8); - assertThat(list.size(), is(2)); - assertThat(list.pop(), is(8)); - assertThat(list.pop(), is(9)); - assertThat(list.size(), is(0)); + assertThat(list.size()).isEqualTo(2); + assertThat(list.pop()).isEqualTo(8); + assertThat(list.pop()).isEqualTo(9); + assertThat(list.size()).isEqualTo(0); } @Ignore("Remove to run test") @@ -57,11 +57,11 @@ public void reverseReversesList() { list.push("6"); list.push("5"); list.reverse(); - assertThat(list.pop(), is("9")); - assertThat(list.pop(), is("8")); - assertThat(list.pop(), is("7")); - assertThat(list.pop(), is("6")); - assertThat(list.pop(), is("5")); + assertThat(list.pop()).isEqualTo("9"); + assertThat(list.pop()).isEqualTo("8"); + assertThat(list.pop()).isEqualTo("7"); + assertThat(list.pop()).isEqualTo("6"); + assertThat(list.pop()).isEqualTo("5"); } @Ignore("Remove to run test") From dd1a27c4b0afdcba548b9f9707b832e208cea58c Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 16:54:35 +0000 Subject: [PATCH 07/12] Migrate linked-list to AssertJ. --- exercises/linked-list/build.gradle | 1 + .../src/test/java/DoublyLinkedListTest.java | 39 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/exercises/linked-list/build.gradle b/exercises/linked-list/build.gradle index 82d705dfd..952e38529 100644 --- a/exercises/linked-list/build.gradle +++ b/exercises/linked-list/build.gradle @@ -8,6 +8,7 @@ repositories { dependencies { testCompile "junit:junit:4.12" + testImplementation "org.assertj:assertj-core:3.15.0" } test { diff --git a/exercises/linked-list/src/test/java/DoublyLinkedListTest.java b/exercises/linked-list/src/test/java/DoublyLinkedListTest.java index 2c9b4ea91..777cfa74c 100644 --- a/exercises/linked-list/src/test/java/DoublyLinkedListTest.java +++ b/exercises/linked-list/src/test/java/DoublyLinkedListTest.java @@ -1,9 +1,8 @@ +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Ignore; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - public class DoublyLinkedListTest { @Test @@ -14,9 +13,9 @@ public void testPushPop() { list.push(20); list.push(30); - assertThat(list.pop(), is(30)); - assertThat(list.pop(), is(20)); - assertThat(list.pop(), is(10)); + assertThat(list.pop()).isEqualTo(30); + assertThat(list.pop()).isEqualTo(20); + assertThat(list.pop()).isEqualTo(10); } @Ignore("Remove to run test") @@ -28,9 +27,9 @@ public void testPushShift() { list.push("20"); list.push("30"); - assertThat(list.shift(), is("10")); - assertThat(list.shift(), is("20")); - assertThat(list.shift(), is("30")); + assertThat(list.shift()).isEqualTo("10"); + assertThat(list.shift()).isEqualTo("20"); + assertThat(list.shift()).isEqualTo("30"); } @Ignore("Remove to run test") @@ -42,9 +41,9 @@ public void testUnshiftShift() { list.unshift('2'); list.unshift('3'); - assertThat(list.shift(), is('3')); - assertThat(list.shift(), is('2')); - assertThat(list.shift(), is('1')); + assertThat(list.shift()).isEqualTo('3'); + assertThat(list.shift()).isEqualTo('2'); + assertThat(list.shift()).isEqualTo('1'); } @Ignore("Remove to run test") @@ -56,9 +55,9 @@ public void testUnshiftPop() { list.unshift(20); list.unshift(30); - assertThat(list.pop(), is(10)); - assertThat(list.pop(), is(20)); - assertThat(list.pop(), is(30)); + assertThat(list.pop()).isEqualTo(10); + assertThat(list.pop()).isEqualTo(20); + assertThat(list.pop()).isEqualTo(30); } @Ignore("Remove to run test") @@ -69,18 +68,18 @@ public void testExample() { list.push("ten"); list.push("twenty"); - assertThat(list.pop(), is("twenty")); + assertThat(list.pop()).isEqualTo("twenty"); list.push("thirty"); - assertThat(list.shift(), is("ten")); + assertThat(list.shift()).isEqualTo("ten"); list.unshift("forty"); list.push("fifty"); - assertThat(list.shift(), is("forty")); - assertThat(list.pop(), is("fifty")); - assertThat(list.shift(), is("thirty")); + assertThat(list.shift()).isEqualTo("forty"); + assertThat(list.pop()).isEqualTo("fifty"); + assertThat(list.shift()).isEqualTo("thirty"); } } From 4f991159c9bbc86743e4d0f098e965140bd1932c Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 17:01:12 +0000 Subject: [PATCH 08/12] Migrate proverb to AssertJ. --- exercises/proverb/build.gradle | 1 + .../proverb/src/test/java/ProverbTest.java | 62 +++++++++---------- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/exercises/proverb/build.gradle b/exercises/proverb/build.gradle index 82d705dfd..952e38529 100644 --- a/exercises/proverb/build.gradle +++ b/exercises/proverb/build.gradle @@ -8,6 +8,7 @@ repositories { dependencies { testCompile "junit:junit:4.12" + testImplementation "org.assertj:assertj-core:3.15.0" } test { diff --git a/exercises/proverb/src/test/java/ProverbTest.java b/exercises/proverb/src/test/java/ProverbTest.java index 787d0774c..600577616 100644 --- a/exercises/proverb/src/test/java/ProverbTest.java +++ b/exercises/proverb/src/test/java/ProverbTest.java @@ -1,80 +1,76 @@ +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Ignore; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - public class ProverbTest { @Test public void zeroWordsAreGiven() { String[] words = new String[0]; - String proverb = new Proverb(words).recite(), - expected = ""; - assertThat(proverb, is(expected)); + assertThat(new Proverb(words).recite()).isEqualTo(""); } @Ignore("Remove to run test") @Test public void singlePieceOfProverb() { String[] words = new String[]{"nail"}; - String proverb = new Proverb(words).recite(), - expected = "And all for the want of a nail."; - assertThat(proverb, is(expected)); + assertThat(new Proverb(words).recite()) + .isEqualTo("And all for the want of a nail."); } @Ignore("Remove to run test") @Test public void twoPiecesOfProverb() { String[] words = new String[]{"nail", "shoe"}; - String proverb = new Proverb(words).recite(), - expected = "For want of a nail the shoe was lost.\n" + - "And all for the want of a nail."; - assertThat(proverb, is(expected)); + assertThat(new Proverb(words).recite()) + .isEqualTo( + "For want of a nail the shoe was lost.\n" + + "And all for the want of a nail."); } @Ignore("Remove to run test") @Test public void shortChainOfConsequences() { String[] words = new String[]{"nail", "shoe", "horse"}; - String proverb = new Proverb(words).recite(), - expected = "For want of a nail the shoe was lost.\n" + - "For want of a shoe the horse was lost.\n" + - "And all for the want of a nail."; - assertThat(proverb, is(expected)); + assertThat(new Proverb(words).recite()) + .isEqualTo( + "For want of a nail the shoe was lost.\n" + + "For want of a shoe the horse was lost.\n" + + "And all for the want of a nail."); } @Ignore("Remove to run test") @Test public void fullProverb() { String[] words = new String[]{"nail", "shoe", "horse", "rider", "message", "battle", "kingdom"}; - String proverb = new Proverb(words).recite(), - expected = "For want of a nail the shoe was lost.\n" + - "For want of a shoe the horse was lost.\n" + - "For want of a horse the rider was lost.\n" + - "For want of a rider the message was lost.\n" + - "For want of a message the battle was lost.\n" + - "For want of a battle the kingdom was lost.\n" + - "And all for the want of a nail."; - assertThat(proverb, is(expected)); + assertThat(new Proverb(words).recite()) + .isEqualTo( + "For want of a nail the shoe was lost.\n" + + "For want of a shoe the horse was lost.\n" + + "For want of a horse the rider was lost.\n" + + "For want of a rider the message was lost.\n" + + "For want of a message the battle was lost.\n" + + "For want of a battle the kingdom was lost.\n" + + "And all for the want of a nail."); } @Ignore("Remove to run test") @Test public void fourPiecesModernizedProverb() { String[] words = new String[]{"pin", "gun", "soldier", "battle"}; - String proverb = new Proverb(words).recite(), - expected = "For want of a pin the gun was lost.\n" + - "For want of a gun the soldier was lost.\n" + - "For want of a soldier the battle was lost.\n" + - "And all for the want of a pin."; - assertThat(proverb, is(expected)); + assertThat(new Proverb(words).recite()) + .isEqualTo( + "For want of a pin the gun was lost.\n" + + "For want of a gun the soldier was lost.\n" + + "For want of a soldier the battle was lost.\n" + + "And all for the want of a pin."); } } From b06b34f7787005240c6a47e5cda8149a23af51df Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 17:13:27 +0000 Subject: [PATCH 09/12] Migrate anagram to AssertJ. --- exercises/anagram/build.gradle | 1 + .../anagram/src/test/java/AnagramTest.java | 87 +++++++++++++------ 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/exercises/anagram/build.gradle b/exercises/anagram/build.gradle index 82d705dfd..952e38529 100644 --- a/exercises/anagram/build.gradle +++ b/exercises/anagram/build.gradle @@ -8,6 +8,7 @@ repositories { dependencies { testCompile "junit:junit:4.12" + testImplementation "org.assertj:assertj-core:3.15.0" } test { diff --git a/exercises/anagram/src/test/java/AnagramTest.java b/exercises/anagram/src/test/java/AnagramTest.java index a42e479cc..7e833af7e 100644 --- a/exercises/anagram/src/test/java/AnagramTest.java +++ b/exercises/anagram/src/test/java/AnagramTest.java @@ -1,3 +1,5 @@ +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Ignore; import org.junit.Test; @@ -5,117 +7,148 @@ import java.util.Collections; import java.util.List; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; - public class AnagramTest { @Test public void testNoMatches() { Anagram detector = new Anagram("diaper"); - assertTrue(detector.match(Arrays.asList("hello", "world", "zombies", "pants")).isEmpty()); + + assertThat( + detector.match( + Arrays.asList("hello", "world", "zombies", "pants"))) + .isEmpty(); } @Ignore("Remove to run test") @Test public void testDetectMultipleAnagrams() { Anagram detector = new Anagram("master"); - List anagrams = detector.match(Arrays.asList("stream", "pigeon", "maters")); - assertThat(anagrams, allOf(hasItem("maters"), hasItem("stream"))); + + assertThat(detector.match(Arrays.asList("stream", "pigeon", "maters"))) + .containsExactlyInAnyOrder​("maters", "stream"); } @Ignore("Remove to run test") @Test public void testEliminateAnagramSubsets() { Anagram detector = new Anagram("good"); - assertTrue(detector.match(Arrays.asList("dog", "goody")).isEmpty()); + + assertThat(detector.match(Arrays.asList("dog", "goody"))).isEmpty(); } @Ignore("Remove to run test") @Test public void testDetectLongerAnagram() { Anagram detector = new Anagram("listen"); - List anagrams = detector.match(Arrays.asList("enlists", "google", "inlets", "banana")); - assertThat(anagrams, hasItem("inlets")); + + assertThat( + detector.match( + Arrays.asList("enlists", "google", "inlets", "banana"))) + .containsExactlyInAnyOrder​("inlets"); } @Ignore("Remove to run test") @Test public void testDetectMultipleAnagramsForLongerWord() { Anagram detector = new Anagram("allergy"); - List anagrams = detector.match(Arrays.asList("gallery", "ballerina", - "regally", "clergy", - "largely", "leading")); - assertThat(anagrams, allOf(hasItem("gallery"), hasItem("regally"), hasItem("largely"))); + assertThat( + detector.match( + Arrays.asList( + "gallery", + "ballerina", + "regally", + "clergy", + "largely", + "leading"))) + .containsExactlyInAnyOrder​("gallery", "regally", "largely"); } @Ignore("Remove to run test") @Test public void testDetectsMultipleAnagramsWithDifferentCase() { Anagram detector = new Anagram("nose"); - List anagrams = detector.match(Arrays.asList("Eons", "ONES")); - assertThat(anagrams, allOf(hasItem("Eons"), hasItem("ONES"))); + + assertThat(detector.match(Arrays.asList("Eons", "ONES"))) + .containsExactlyInAnyOrder​("Eons", "ONES"); } @Ignore("Remove to run test") @Test public void testEliminateAnagramsWithSameChecksum() { Anagram detector = new Anagram("mass"); - assertTrue(detector.match(Collections.singletonList("last")).isEmpty()); + + assertThat(detector.match(Collections.singletonList("last"))) + .isEmpty(); } @Ignore("Remove to run test") @Test public void testCaseInsensitiveWhenBothAnagramAndSubjectStartWithUpperCaseLetter() { Anagram detector = new Anagram("Orchestra"); - List anagrams = detector.match(Arrays.asList("cashregister", "Carthorse", "radishes")); - assertThat(anagrams, hasItem("Carthorse")); + + assertThat( + detector.match( + Arrays.asList("cashregister", "Carthorse", "radishes"))) + .containsExactlyInAnyOrder​("Carthorse"); } @Ignore("Remove to run test") @Test public void testCaseInsensitiveWhenSubjectStartsWithUpperCaseLetter() { Anagram detector = new Anagram("Orchestra"); - List anagrams = detector.match(Arrays.asList("cashregister", "carthorse", "radishes")); - assertThat(anagrams, hasItem("carthorse")); + + assertThat( + detector.match( + Arrays.asList("cashregister", "carthorse", "radishes"))) + .containsExactlyInAnyOrder​("carthorse"); } @Ignore("Remove to run test") @Test public void testCaseInsensitiveWhenAnagramStartsWithUpperCaseLetter() { Anagram detector = new Anagram("orchestra"); - List anagrams = detector.match(Arrays.asList("cashregister", "Carthorse", "radishes")); - assertThat(anagrams, hasItem("Carthorse")); + + assertThat( + detector.match( + Arrays.asList("cashregister", "Carthorse", "radishes"))) + .containsExactlyInAnyOrder​("Carthorse"); } @Ignore("Remove to run test") @Test public void testIdenticalWordRepeatedIsNotAnagram() { Anagram detector = new Anagram("go"); - assertTrue(detector.match(Collections.singletonList("go Go GO")).isEmpty()); + + assertThat(detector.match(Collections.singletonList("go Go GO"))) + .isEmpty(); } @Ignore("Remove to run test") @Test public void testAnagramMustUseAllLettersExactlyOnce() { Anagram detector = new Anagram("tapper"); - assertTrue(detector.match(Collections.singletonList("patter")).isEmpty()); + + assertThat(detector.match(Collections.singletonList("patter"))) + .isEmpty(); } @Ignore("Remove to run test") @Test public void testWordsAreNotAnagramsOfThemselvesCaseInsensitive() { Anagram detector = new Anagram("BANANA"); - assertTrue(detector.match(Arrays.asList("BANANA", "Banana", "banana")).isEmpty()); + + assertThat(detector.match(Arrays.asList("BANANA", "Banana", "banana"))) + .isEmpty(); } @Ignore("Remove to run test") @Test public void testWordsOtherThanThemselvesCanBeAnagrams() { Anagram detector = new Anagram("LISTEN"); - List anagrams = detector.match(Arrays.asList("Listen", "Silent", "LISTEN")); - assertThat(anagrams, hasItem("Silent")); + + assertThat(detector.match(Arrays.asList("Listen", "Silent", "LISTEN"))) + .containsExactlyInAnyOrder​("Silent"); } } From bd3cf0d1115c75cce35b2cfaf58c01106e087bda Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 17:18:30 +0000 Subject: [PATCH 10/12] Migrate circular-buffer to AssertJ. --- exercises/circular-buffer/build.gradle | 1 + .../src/test/java/CircularBufferTest.java | 45 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/exercises/circular-buffer/build.gradle b/exercises/circular-buffer/build.gradle index 479746285..20f3abb34 100644 --- a/exercises/circular-buffer/build.gradle +++ b/exercises/circular-buffer/build.gradle @@ -8,6 +8,7 @@ repositories { dependencies { testCompile "junit:junit:4.12" + testImplementation "org.assertj:assertj-core:3.15.0" } test { diff --git a/exercises/circular-buffer/src/test/java/CircularBufferTest.java b/exercises/circular-buffer/src/test/java/CircularBufferTest.java index 526bb0d5a..906ecf07a 100644 --- a/exercises/circular-buffer/src/test/java/CircularBufferTest.java +++ b/exercises/circular-buffer/src/test/java/CircularBufferTest.java @@ -1,5 +1,4 @@ -import static org.junit.Assert.assertThat; -import static org.hamcrest.CoreMatchers.is; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.Ignore; import org.junit.Rule; @@ -26,7 +25,7 @@ public void canReadItemJustWritten() throws BufferIOException { CircularBuffer buffer = new CircularBuffer<>(1); buffer.write(1); - assertThat(buffer.read(), is(1)); + assertThat(buffer.read()).isEqualTo(1); } @Ignore("Remove to run test") @@ -35,7 +34,7 @@ public void canReadItemOnlyOnce() throws BufferIOException { CircularBuffer buffer = new CircularBuffer<>(1); buffer.write(1); - assertThat(buffer.read(), is(1)); + assertThat(buffer.read()).isEqualTo(1); expectedException.expect(BufferIOException.class); expectedException.expectMessage("Tried to read from empty buffer"); @@ -49,8 +48,8 @@ public void readsItemsInOrderWritten() throws BufferIOException { buffer.write(1); buffer.write(2); - assertThat(buffer.read(), is(1)); - assertThat(buffer.read(), is(2)); + assertThat(buffer.read()).isEqualTo(1); + assertThat(buffer.read()).isEqualTo(2); } @Ignore("Remove to run test") @@ -70,9 +69,9 @@ public void readFreesUpSpaceForWrite() throws BufferIOException { CircularBuffer buffer = new CircularBuffer<>(1); buffer.write(1); - assertThat(buffer.read(), is(1)); + assertThat(buffer.read()).isEqualTo(1); buffer.write(2); - assertThat(buffer.read(), is(2)); + assertThat(buffer.read()).isEqualTo(2); } @Ignore("Remove to run test") @@ -82,10 +81,10 @@ public void maintainsReadPositionAcrossWrites() throws BufferIOException { buffer.write(1); buffer.write(2); - assertThat(buffer.read(), is(1)); + assertThat(buffer.read()).isEqualTo(1); buffer.write(3); - assertThat(buffer.read(), is(2)); - assertThat(buffer.read(), is(3)); + assertThat(buffer.read()).isEqualTo(2); + assertThat(buffer.read()).isEqualTo(3); } @Ignore("Remove to run test") @@ -108,7 +107,7 @@ public void clearFreesUpCapacity() throws BufferIOException { buffer.write(1); buffer.clear(); buffer.write(2); - assertThat(buffer.read(), is(2)); + assertThat(buffer.read()).isEqualTo(2); } @Ignore("Remove to run test") @@ -118,7 +117,7 @@ public void clearDoesNothingOnEmptyBuffer() throws BufferIOException { buffer.clear(); buffer.write(1); - assertThat(buffer.read(), is(1)); + assertThat(buffer.read()).isEqualTo(1); } @Ignore("Remove to run test") @@ -128,8 +127,8 @@ public void overwriteActsLikeWriteOnNonFullBuffer() throws BufferIOException { buffer.write(1); buffer.overwrite(2); - assertThat(buffer.read(), is(1)); - assertThat(buffer.read(), is(2)); + assertThat(buffer.read()).isEqualTo(1); + assertThat(buffer.read()).isEqualTo(2); } @Ignore("Remove to run test") @@ -140,8 +139,8 @@ public void overwriteRemovesOldestElementOnFullBuffer() throws BufferIOException buffer.write(1); buffer.write(2); buffer.overwrite(3); - assertThat(buffer.read(), is(2)); - assertThat(buffer.read(), is(3)); + assertThat(buffer.read()).isEqualTo(2); + assertThat(buffer.read()).isEqualTo(3); } @Ignore("Remove to run test") @@ -152,12 +151,12 @@ public void overwriteDoesntRemoveAnAlreadyReadElement() throws BufferIOException buffer.write(1); buffer.write(2); buffer.write(3); - assertThat(buffer.read(), is(1)); + assertThat(buffer.read()).isEqualTo(1); buffer.write(4); buffer.overwrite(5); - assertThat(buffer.read(), is(3)); - assertThat(buffer.read(), is(4)); - assertThat(buffer.read(), is(5)); + assertThat(buffer.read()).isEqualTo(3); + assertThat(buffer.read()).isEqualTo(4); + assertThat(buffer.read()).isEqualTo(5); } @Ignore("Remove to run test") @@ -170,8 +169,8 @@ public void initialClearDoesNotAffectWrappingAround() throws BufferIOException { buffer.write(2); buffer.overwrite(3); buffer.overwrite(4); - assertThat(buffer.read(), is(3)); - assertThat(buffer.read(), is(4)); + assertThat(buffer.read()).isEqualTo(3); + assertThat(buffer.read()).isEqualTo(4); expectedException.expect(BufferIOException.class); expectedException.expectMessage("Tried to read from empty buffer"); buffer.read(); From 6649ab142bddffefbc8ed84656750a5af518648d Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 17:22:02 +0000 Subject: [PATCH 11/12] Remove unnecessary hamcrest usage from alphametics. --- exercises/alphametics/src/test/java/AlphameticsTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/alphametics/src/test/java/AlphameticsTest.java b/exercises/alphametics/src/test/java/AlphameticsTest.java index dab8a7554..4109cea15 100644 --- a/exercises/alphametics/src/test/java/AlphameticsTest.java +++ b/exercises/alphametics/src/test/java/AlphameticsTest.java @@ -1,3 +1,5 @@ +import static org.junit.Assert.assertEquals; + import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -5,8 +7,6 @@ import java.util.LinkedHashMap; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; public class AlphameticsTest { @Rule @@ -33,7 +33,7 @@ public void testUniqueValue() throws UnsolvablePuzzleException { @Test public void testLeadingZero() throws UnsolvablePuzzleException { expectedException.expect(UnsolvablePuzzleException.class); - assertNull(new Alphametics("ACA + DD == BD").solve()); + new Alphametics("ACA + DD == BD").solve(); } @Ignore("Remove to run test") From 0a093a0a5be509f8a35f083245b08457c2969aa4 Mon Sep 17 00:00:00 2001 From: Jason Runkle Date: Wed, 22 Apr 2020 17:22:43 +0000 Subject: [PATCH 12/12] Update .gitignore to ignore generated files from the IDE. --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index c6a561e56..08046b8b0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,13 @@ bin/configlet bin/configlet.exe /exercises/.nb-gradle/ **/out +exercises/.project +exercises/.settings/ +exercises/*/bin +exercises/*/.classpath +exercises/*/.project +exercises/*/.settings/ +_template/bin +_template/.classpath +_template/.project +_template/.settings/ \ No newline at end of file