Skip to content

Commit 1782764

Browse files
committed
Comment assertions with script.
1 parent c7d94e1 commit 1782764

10 files changed

+49
-77
lines changed

java-junit/src/test/java/org/codecop/Session1_GreeterTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ public class Session1_GreeterTest {
1414
@Test
1515
public void shouldReturnHelloName() {
1616
Greeter greeter = new Greeter();
17-
assertEquals("Hello Peter", greeter.greet("Peter"));
17+
// TODO Check that "Hello Peter", greeter.greet("Peter").
1818
}
1919

2020
@Test
2121
public void shouldReturnHelloForNull() {
2222
Greeter greeter = new Greeter();
23-
assertEquals("Hello", greeter.greet(null));
23+
// TODO Check that "Hello", greeter.greet(null).
2424
}
2525

2626
@Test
2727
public void shouldIgnoreWhitespace() {
2828
Greeter greeter = new Greeter();
29-
assertEquals("Hello Peter", greeter.greet(" Peter "));
29+
// TODO Check that "Hello Peter", greeter.greet(" Peter ").
3030
}
3131

3232
}

java-junit/src/test/java/org/codecop/Session2a_WordCounterTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,49 @@ public class Session2a_WordCounterTest {
2121
@Test
2222
public void shouldCountNumberOfWords() {
2323
WordCounter counter = new WordCounter("Keep the bar green to keep the code clean.");
24-
assertEquals(9, counter.numberOfWords());
24+
// TODO Check that 9, counter.numberOfWords().
2525
}
2626

2727
@Test
2828
public void shouldVerifyContainmentOfWord() {
2929
WordCounter counter = new WordCounter("green bar green hat");
30-
assertTrue(counter.containsWord("bar"));
30+
// TODO Check that counter.containsWord("bar").
3131
}
3232

3333
@Test
3434
public void shouldVerifyNonContainmentOfWord() {
3535
WordCounter counter = new WordCounter("green hat");
36-
assertFalse(counter.containsWord("red"));
36+
// TODO Check that counter.containsWord("red") is false.
3737
}
3838

3939
@Test
4040
public void shouldReturnNullForUnknownWordCount() {
4141
WordCounter counter = new WordCounter("green bar green hat");
42-
assertNull(counter.countOf("else"));
42+
// TODO Check that counter.countOf("else") is null.
4343
}
4444

4545
@Test
4646
public void shouldReturnNotNullWordCountForExistingWord() {
4747
WordCounter counter = new WordCounter("green bar green hat");
48-
assertNotNull(counter.countOf("green"));
48+
// TODO Check that counter.countOf("green") is not null.
4949
}
5050

5151
@Test
5252
public void shouldCountGreenTwice() {
5353
WordCounter counter = new WordCounter("green bar green hat");
54-
assertEquals(Integer.valueOf(2), counter.countOf("green"));
54+
// TODO Check that 2, counter.countOf("green").
5555
}
5656

5757
@Test
5858
public void shouldFindUniqueWords() {
5959
WordCounter counter = new WordCounter("green bar green hat");
60-
assertArrayEquals(new String[] { "bar", "green", "hat" }, counter.uniqueWords());
60+
// TODO Check that new String[] { "bar", "green", "hat" }, counter.uniqueWords().
6161
}
6262

6363
@Test
6464
public void shouldReturnRatioOfWords() {
6565
WordCounter counter = new WordCounter("green bar green");
66-
assertEquals(0.33, counter.ratioOf("bar"), 0.01);
66+
// TODO Check that 0.33, counter.ratioOf("bar").
6767
// Note that floating point numbers need an accuracy delta, e.g. 0.01.
6868
}
6969

java-junit/src/test/java/org/codecop/Session2c_WordCounterTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,33 @@ public class Session2c_WordCounterTest {
2525
@Test
2626
public void shouldCountNumberOfWords() {
2727
WordCounter counter = new WordCounter("Keep the bar green to keep the code clean.");
28-
assertEquals(9, counter.numberOfWords()); // keep
28+
assertEquals(9, counter.numberOfWords());
2929
// Hamcrest improves readability:
30-
assertThat(counter.numberOfWords(), equalTo(9));
30+
// TODO Check that counter.numberOfWords(), equalTo 9.
3131
}
3232

3333
@Test
3434
public void shouldContainUniqueWord() {
3535
WordCounter counter = new WordCounter("green bar green hat");
36-
assertTrue(Arrays.asList(counter.uniqueWords()).contains("bar")); // keep
36+
assertTrue(Arrays.asList(counter.uniqueWords()).contains("bar"));
3737
// Hamcrest improves readability:
38-
assertThat(counter.uniqueWords(), hasItemInArray("bar"));
38+
// TODO Check that counter.uniqueWords(), hasItemInArray "bar".
3939
}
4040

4141
@Test
4242
public void shouldNotContainUniqueWord() {
4343
WordCounter counter = new WordCounter("green bar green hat");
44-
assertFalse(Arrays.asList(counter.uniqueWords()).contains("foo")); // keep
44+
assertFalse(Arrays.asList(counter.uniqueWords()).contains("foo"));
4545
// Hamcrest improves readability:
46-
assertThat(counter.uniqueWords(), not(hasItemInArray("foo")));
46+
// TODO Check that counter.uniqueWords(), not hasItemInArray "foo".
4747
}
4848

4949
@Test
5050
public void shouldFindNumberOfUniqueWords() {
5151
WordCounter counter = new WordCounter("green bar green hat");
52-
assertEquals(3, counter.uniqueWords().length); // keep
52+
assertEquals(3, counter.uniqueWords().length);
5353
// Hamcrest improves readability:
54-
assertThat(counter.uniqueWords(), arrayWithSize(3));
54+
// TODO Check that counter.uniqueWords(), arrayWithSize 3.
5555
}
5656

5757
}

java-junit/src/test/java/org/codecop/Session2d_WordCounterTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@ public class Session2d_WordCounterTest {
2323
@Test
2424
public void shouldCountNumberOfWords() {
2525
WordCounter counter = new WordCounter("Keep the bar green to keep the code clean.");
26-
assertEquals(9, counter.numberOfWords()); // keep
26+
assertEquals(9, counter.numberOfWords());
2727
// AssertJ is fluent:
28-
assertThat(counter.numberOfWords()).isEqualTo(9);
28+
// TODO Check that counter.numberOfWords() isEqualTo 9.
2929
}
3030

3131
@Test
3232
public void shouldContainUniqueWord() {
3333
WordCounter counter = new WordCounter("green bar green hat");
34-
assertTrue(Arrays.asList(counter.uniqueWords()).contains("bar")); // keep
34+
assertTrue(Arrays.asList(counter.uniqueWords()).contains("bar"));
3535
// AssertJ is fluent:
36-
assertThat(counter.uniqueWords()).contains("bar");
36+
// TODO Check that counter.uniqueWords() contains "bar".
3737
}
3838

3939
@Test
4040
public void shouldNotContainUniqueWord() {
4141
WordCounter counter = new WordCounter("green bar green hat");
42-
assertFalse(Arrays.asList(counter.uniqueWords()).contains("foo")); // keep
42+
assertFalse(Arrays.asList(counter.uniqueWords()).contains("foo"));
4343
// AssertJ is fluent:
44-
assertThat(counter.uniqueWords()).doesNotContain("foo");
44+
// TODO Check that counter.uniqueWords() doesNotContain "foo".
4545
}
4646

4747
@Test
4848
public void shouldFindNumberOfUniqueWords() {
4949
WordCounter counter = new WordCounter("green bar green hat");
50-
assertEquals(3, counter.uniqueWords().length); // keep
50+
assertEquals(3, counter.uniqueWords().length);
5151
// AssertJ is fluent:
52-
assertThat(counter.uniqueWords()).hasSize(3);
52+
// TODO Check that counter.uniqueWords() hasSize 3.
5353
}
5454
}

java-junit/src/test/java/org/codecop/Session3_WordCounterFileTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void shouldReturnCountOfWords() throws IOException {
2222
StringToFile.write("Keep the bar green to keep the code clean.", file);
2323

2424
WordCounter counter = new WordCounter(file);
25-
assertEquals(9, counter.numberOfWords()); // keep
25+
assertEquals(9, counter.numberOfWords());
2626

2727
file.delete();
2828
}
@@ -34,27 +34,27 @@ public void shouldReturnCountOfWords() throws IOException {
3434

3535
private final File testFile = new File("FileWordCounterTest.tmp");
3636

37-
@Before // This method should be called before each test.
37+
// TODO This method should be called before each test.
3838
public void createFreshTestFileForEachTest() throws IOException {
3939
StringToFile.write("Keep the bar green to keep the code clean.", testFile);
4040
}
4141

42-
@After // This method should be called after each test.
42+
// TODO This method should be called after each test.
4343
public void deleteTestFile() {
44-
assertTrue(testFile.delete()); // keep
44+
assertTrue(testFile.delete());
4545
}
4646

4747
// TODO add the proper assertions to complete the tests.
4848

4949
@Test
5050
public void shouldReturnCountOfWordsBetter() throws IOException {
5151
WordCounter counter = new WordCounter(testFile);
52-
assertEquals(9, counter.numberOfWords());
52+
// TODO Check that 9, counter.numberOfWords().
5353
}
5454

5555
@Test
5656
public void shouldVerifyContainmentOfWord() throws IOException {
5757
WordCounter counter = new WordCounter(testFile);
58-
assertTrue(counter.containsWord("bar"));
58+
// TODO Check that counter.containsWord("bar").
5959
}
6060
}

java-junit/src/test/java/org/codecop/Session4_WordCounterFailureTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public class Session4_WordCounterFailureTest {
1616

1717
// TODO Add the needed code/annotations to test for an expected exception.
1818

19-
@Test(expected = IOException.class)
19+
// TODO Mark this test to expect IOException.class.
2020
public void shouldThrowIOExceptionOnMissingFile() throws IOException {
2121
new WordCounter(new File("IamSureThisDoesNotExist.txt"));
2222
}
2323

24-
@Test(expected = IllegalArgumentException.class)
24+
// TODO Mark this test to expect IllegalArgumentException.class.
2525
public void shouldThrowIllegalArgumentExceptionForUnknownWord() {
2626
WordCounter counter = new WordCounter("green bar green");
2727
counter.ratioOf("missingWord");
@@ -31,10 +31,10 @@ public void shouldThrowIllegalArgumentExceptionForUnknownWord() {
3131
// but we will do that tomorrow. For today let's ignore it.
3232

3333
@Test
34-
@Ignore("work in progress, will continue tomorrow")
34+
// TODO Mark this test as ignored with "work in progress, will continue tomorrow".
3535
public void shouldCountUniqueWordsCaseInsensitive() {
3636
WordCounter counter = new WordCounter("green bar Green hat");
37-
assertArrayEquals(new String[] { "bar", "green", "hat" }, counter.uniqueWords()); // keep
37+
assertArrayEquals(new String[] { "bar", "green", "hat" }, counter.uniqueWords());
3838
}
3939

4040
}

java-junit/src/test/java/org/codecop/Session4b_WordCounterFailureTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public class Session4b_WordCounterFailureTest {
2020
@Test
2121
public void shouldThrowIllegalArgumentExceptionWithMessageOnUnknownWord() {
2222
WordCounter counter = new WordCounter("green bar green");
23-
verifyException(counter, IllegalArgumentException.class).ratioOf("missingWord");
23+
// TODO Verify IllegalArgumentException.class is thrown from counter.ratioOf("missingWord");
2424

2525
// Hamcrest improves readability:
26-
catchException(counter).ratioOf("missingWord"); // keep
27-
assertThat(caughtException(), IsInstanceOf.instanceOf(IllegalArgumentException.class));
28-
assertEquals("missingWord not in sentence", caughtException().getMessage());
26+
catchException(counter).ratioOf("missingWord");
27+
// TODO Check that caughtException(), IsInstanceOf.instanceOf IllegalArgumentException.class.
28+
// TODO Check that "missingWord not in sentence", caughtException().getMessage().
2929
}
3030

3131
}

java-junit/src/test/java/org/codecop/Session5_WordCounterRatioTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Session 5: WordCounterRatioTest - parameterised/table driven tests. <br />
1515
* @see "https://github.com/junit-team/junit/wiki/Parameterized-tests"
1616
*/
17-
@RunWith(Parameterized.class) // Mark this test as parameterised
17+
// TODO Mark this test as parameterised
1818
public class Session5_WordCounterRatioTest {
1919

2020
// TODO Add the needed annotations to run this test with all examples.
@@ -27,7 +27,7 @@ public class Session5_WordCounterRatioTest {
2727
new Object[] { "green bar green", "bar", 0.33 } //
2828
);
2929

30-
@Parameters(name = "ratio of '{1}' in words '{0}' should be {2}") // This method returns the parameters
30+
// TODO This method returns the parameters
3131
public static List<Object[]> getTestCases() {
3232
return TEST_CASES;
3333
}
@@ -45,7 +45,7 @@ public Session5_WordCounterRatioTest(String sentence, String word, double expect
4545
@Test
4646
public void shouldReturnRatioOfGivenWord() {
4747
WordCounter counter = new WordCounter(sentence);
48-
assertEquals(expectedRatio, counter.ratioOf(word), 0.01); // keep
48+
assertEquals(expectedRatio, counter.ratioOf(word), 0.01);
4949
}
5050

5151
}

java-junit/src/test/java/org/codecop/Session5b_WordCounterRatioTest.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,24 @@
1111
* Session 5b: WordCounterRatioTest - parameterised/table driven tests with JUnitParams. <br />
1212
* @see "https://github.com/Pragmatists/junitparams"
1313
*/
14-
@RunWith(JUnitParamsRunner.class) // Mark this test as parameterised with JUnitParams
14+
// TODO Mark this test as parameterised with JUnitParams
1515
public class Session5b_WordCounterRatioTest {
1616

1717
// TODO Add the needed annotations to run this test with all examples.
1818

19-
@Test // keep
19+
@Test
2020
// We want to test more cases for the ratio. Here is a table of test cases.
21-
@Parameters( // drop
22-
// use /*
21+
/*
2322
{ //
2423
"green, green, 1.0", //
2524
"green bar green, green, 0.66", //
2625
"green bar green bar, green, 0.5", //
2726
"green bar green, bar, 0.33" //
2827
}
29-
// use */
30-
) // drop
28+
*/
3129
public void shouldReturnRatioOfGivenWord(String sentence, String word, double expectedRatio) {
3230
WordCounter counter = new WordCounter(sentence);
33-
assertEquals(expectedRatio, counter.ratioOf(word), 0.01); // keep
31+
assertEquals(expectedRatio, counter.ratioOf(word), 0.01);
3432
}
3533

3634
}

java-junit/src/test/java/org/codecop/StringToFileTest.java

-26
This file was deleted.

0 commit comments

Comments
 (0)