Skip to content

Commit

Permalink
#106 Improve unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dusan-rychnovsky committed Jun 10, 2017
1 parent e3ad5a8 commit aeb61ef
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/test/java/org/cactoos/text/ReplacedTextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,17 @@ public void notReplaceTextWhenSubstringNotFound() {
new TextHasString(text)
);
}

@Test
public void replacesAllOccurrences() {
MatcherAssert.assertThat(
"Can't replace a text with multiple needle occurrences",
new ReplacedText(
new StringAsText("one cat, two cats, three cats"),
"cat",
"dog"
),
new TextHasString("one dog, two dogs, three dogs")
);
}
}
10 changes: 10 additions & 0 deletions src/test/java/org/cactoos/text/ReversedTextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ public void reverseText() {
);
}

@Test
public void reversedEmptyTextIsEmptyText() {
MatcherAssert.assertThat(
"Can't reverse empty text",
new ReversedText(
new StringAsText("")
),
new TextHasString("")
);
}
}
9 changes: 9 additions & 0 deletions src/test/java/org/cactoos/text/TextAsBoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ public void falseTest() throws IOException {
Matchers.equalTo(false)
);
}

@Test
public void isFalseIfTextDoesNotRepresentABoolean() throws IOException {
MatcherAssert.assertThat(
"Can't parse a non-boolean string",
new TextAsBool("abc").asValue(),
Matchers.equalTo(false)
);
}
}
5 changes: 5 additions & 0 deletions src/test/java/org/cactoos/text/TextAsDoubleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public strictfp void numberTest() throws IOException {
Matchers.equalTo(185.65156465123)
);
}

@Test(expected = NumberFormatException.class)
public void failsIfTextDoesNotRepresentADouble() throws IOException {
new TextAsDouble("abc").asValue();
}
}
5 changes: 5 additions & 0 deletions src/test/java/org/cactoos/text/TextAsFloatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public strictfp void numberTest() throws IOException {
Matchers.equalTo(1656.894F)
);
}

@Test(expected = NumberFormatException.class)
public void failsIfTextDoesNotRepresentAFloat() throws IOException {
new TextAsFloat("abc").asValue();
}
}
5 changes: 5 additions & 0 deletions src/test/java/org/cactoos/text/TextAsIntTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public void numberTest() throws IOException {
Matchers.equalTo(1867892354)
);
}

@Test(expected = NumberFormatException.class)
public void failsIfTextDoesNotRepresentAnInt() throws IOException {
new TextAsDouble("abc").asValue();
}
}
5 changes: 5 additions & 0 deletions src/test/java/org/cactoos/text/TextAsLongTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public void numberTest() throws IOException {
Matchers.equalTo(186789235425346L)
);
}

@Test(expected = NumberFormatException.class)
public void failsIfTextDoesNotRepresentALong() throws IOException {
new TextAsLong("abc").asValue();
}
}
8 changes: 8 additions & 0 deletions src/test/java/org/cactoos/text/TrimmedTextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@ public void convertsText() {
);
}

@Test
public void trimmedBlankTextIsEmptyText() {
MatcherAssert.assertThat(
"Can't trim a blank text",
new TrimmedText(new StringAsText(" \t ")),
new TextHasString("")
);
}
}

0 comments on commit aeb61ef

Please sign in to comment.