Skip to content

Commit 4db7da6

Browse files
author
MerkushevKirill
committed
rft - replace assertTrue and assertFalse with assertThat with matcher
1 parent c7554c1 commit 4db7da6

File tree

3 files changed

+60
-58
lines changed

3 files changed

+60
-58
lines changed

src/test/java/ru/lanwen/verbalregex/BasicFunctionalityUnitTest.java

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
import static org.hamcrest.CoreMatchers.*;
66
import static org.junit.Assert.*;
77
import static ru.lanwen.verbalregex.VerbalExpression.regex;
8+
import static ru.lanwen.verbalregex.matchers.TestMatchMatcher.matchesTo;
89
import static ru.lanwen.verbalregex.matchers.TestsExactMatcher.matchesExactly;
910

1011
public class BasicFunctionalityUnitTest {
1112
@Test
1213
public void testSomething() {
1314
VerbalExpression testRegex = new VerbalExpression.Builder().something().build();
1415

15-
assertFalse("Null object doesn't have something", testRegex.test(null));
16-
assertFalse("empty string doesn't have something", testRegex.test(""));
17-
assertTrue("a", testRegex.test("a"));
16+
assertThat("Null object doesn't have something", testRegex, not(matchesTo(null)));
17+
assertThat("empty string doesn't have something", testRegex, not(matchesTo("")));
18+
assertThat("a", testRegex, matchesTo("a"));
1819
}
1920

2021
@Test
@@ -24,9 +25,9 @@ public void testAnything() {
2425
.anything()
2526
.build();
2627

27-
assertTrue(testRegex.test("what"));
28-
assertFalse(testRegex.test(""));
29-
assertTrue(testRegex.test(" "));
28+
assertThat(testRegex, matchesTo("what"));
29+
assertThat(testRegex, not(matchesTo("")));
30+
assertThat(testRegex, matchesTo(" "));
3031
}
3132

3233
@Test
@@ -63,9 +64,9 @@ public void testStartOfLine() {
6364

6465
assertFalse("Null string", testRegex.testExact(null));
6566
assertFalse("empty string doesn't have something", testRegex.testExact(""));
66-
assertTrue("Starts with a", testRegex.test("a"));
67-
assertTrue("Starts with a", testRegex.test("ab"));
68-
assertFalse("Doesn't start with a", testRegex.test("ba"));
67+
assertThat("Starts with a", testRegex, matchesTo("a"));
68+
assertThat("Starts with a", testRegex, matchesTo("ab"));
69+
assertThat("Doesn't start with a", testRegex, not(matchesTo("ba")));
6970
}
7071

7172
@Test
@@ -74,17 +75,17 @@ public void testStartOfLineFalse() {
7475
.startOfLine(false)
7576
.then("a")
7677
.build();
77-
assertThat(testRegex.test("ba"), is(true));
78-
assertThat(testRegex.test("ab"), is(true));
78+
assertThat(testRegex, matchesTo("ba"));
79+
assertThat(testRegex, matchesTo("ab"));
7980
}
8081

8182
@Test
8283
public void testRangeWithMultiplyRanges() throws Exception {
8384
VerbalExpression regex = regex().range("a", "z", "A", "Z").build();
8485

8586
assertThat("Regex with multi-range differs from expected", regex.toString(), equalTo("[a-zA-Z]"));
86-
assertThat("Regex don't matches letter", regex.test("b"), is(true));
87-
assertThat("Regex matches digit, but should match only letter", regex.test("1"), is(false));
87+
assertThat("Regex don't matches letter", regex, matchesTo("b"));
88+
assertThat("Regex matches digit, but should match only letter", regex, not(matchesTo("1")));
8889
}
8990

9091
@Test
@@ -94,10 +95,10 @@ public void testEndOfLine() {
9495
.endOfLine()
9596
.build();
9697

97-
assertTrue("Ends with a", testRegex.test("bba"));
98-
assertTrue("Ends with a", testRegex.test("a"));
99-
assertFalse("Ends with a", testRegex.test(null));
100-
assertFalse("Doesn't end with a", testRegex.test("ab"));
98+
assertThat("Ends with a", testRegex, matchesTo("bba"));
99+
assertThat("Ends with a", testRegex, matchesTo("a"));
100+
assertThat("Ends with a", testRegex, not(matchesTo(null)));
101+
assertThat("Doesn't end with a", testRegex, not(matchesTo("ab")));
101102
}
102103

103104

@@ -107,8 +108,8 @@ public void testEndOfLineIsFalse() {
107108
.find("a")
108109
.endOfLine(false)
109110
.build();
110-
assertThat(testRegex.test("ba"), is(true));
111-
assertThat(testRegex.test("ab"), is(true));
111+
assertThat(testRegex, matchesTo("ba"));
112+
assertThat(testRegex, matchesTo("ab"));
112113
}
113114

114115

@@ -122,9 +123,9 @@ public void testMaybe() {
122123

123124
assertThat("Regex isn't correct", testRegex.toString(), equalTo("^(?:a)(?:b)?"));
124125

125-
assertTrue("Maybe has a 'b' after an 'a'", testRegex.test("acb"));
126-
assertTrue("Maybe has a 'b' after an 'a'", testRegex.test("abc"));
127-
assertFalse("Maybe has a 'b' after an 'a'", testRegex.test("cab"));
126+
assertThat("Maybe has a 'b' after an 'a'", testRegex, matchesTo("acb"));
127+
assertThat("Maybe has a 'b' after an 'a'", testRegex, matchesTo("abc"));
128+
assertThat("Maybe has a 'b' after an 'a'", testRegex, not(matchesTo("cab")));
128129
}
129130

130131
@Test
@@ -135,8 +136,8 @@ public void testAnyOf() {
135136
.anyOf("xyz")
136137
.build();
137138

138-
assertTrue("Has an x, y, or z after a", testRegex.test("ay"));
139-
assertFalse("Doesn't have an x, y, or z after a", testRegex.test("abc"));
139+
assertThat("Has an x, y, or z after a", testRegex, matchesTo("ay"));
140+
assertThat("Doesn't have an x, y, or z after a", testRegex, not(matchesTo("abc")));
140141
}
141142

142143

@@ -156,8 +157,8 @@ public void testOr() {
156157
.or("def")
157158
.build();
158159

159-
assertTrue("Starts with abc or def", testRegex.test("defzzz"));
160-
assertFalse("Doesn't start with abc or def", testRegex.test("xyzabc"));
160+
assertThat("Starts with abc or def", testRegex, matchesTo("defzzz"));
161+
assertThat("Doesn't start with abc or def", testRegex, not(matchesTo("xyzabc")));
161162
}
162163

163164
@Test
@@ -169,9 +170,9 @@ public void testLineBreak() {
169170
.then("def")
170171
.build();
171172

172-
assertTrue("abc then line break then def", testRegex.test("abc\r\ndef"));
173-
assertTrue("abc then line break then def", testRegex.test("abc\ndef"));
174-
assertFalse("abc then line break then space then def", testRegex.test("abc\r\n def"));
173+
assertThat("abc then line break then def", testRegex, matchesTo("abc\r\ndef"));
174+
assertThat("abc then line break then def", testRegex, matchesTo("abc\ndef"));
175+
assertThat("abc then line break then space then def", testRegex, not(matchesTo("abc\r\n def")));
175176
}
176177

177178
@Test
@@ -201,8 +202,8 @@ public void testTab() {
201202
.then("abc")
202203
.build();
203204

204-
assertTrue("tab then abc", testRegex.test("\tabc"));
205-
assertFalse("no tab then abc", testRegex.test("abc"));
205+
assertThat("tab then abc", testRegex, matchesTo("\tabc"));
206+
assertThat("no tab then abc", testRegex, not(matchesTo("abc")));
206207
}
207208

208209
@Test
@@ -212,15 +213,15 @@ public void testWithAnyCase() {
212213
.then("a")
213214
.build();
214215

215-
assertFalse("not case insensitive", testRegex.test("A"));
216+
assertThat("not case insensitive", testRegex, not(matchesTo("A")));
216217
testRegex = new VerbalExpression.Builder()
217218
.startOfLine()
218219
.then("a")
219220
.withAnyCase()
220221
.build();
221222

222-
assertTrue("case insensitive", testRegex.test("A"));
223-
assertTrue("case insensitive", testRegex.test("a"));
223+
assertThat("case insensitive", testRegex, matchesTo("A"));
224+
assertThat("case insensitive", testRegex, matchesTo("a"));
224225
}
225226

226227
@Test
@@ -232,7 +233,7 @@ public void testWithAnyCaseIsFalse() {
232233
.withAnyCase(false)
233234
.build();
234235

235-
assertThat(testRegex.test("A"), is(false));
236+
assertThat(testRegex, not(matchesTo("A")));
236237
}
237238

238239
@Test
@@ -245,7 +246,7 @@ public void testSearchOneLine() {
245246
.endOfLine()
246247
.build();
247248

248-
assertTrue("b is on the second line", testRegex.test("a\nb"));
249+
assertThat("b is on the second line", testRegex, matchesTo("a\nb"));
249250

250251
testRegex = new VerbalExpression.Builder()
251252
.startOfLine()
@@ -256,7 +257,7 @@ public void testSearchOneLine() {
256257
.searchOneLine(true)
257258
.build();
258259

259-
assertTrue("b is on the second line but we are only searching the first", testRegex.test("a\nb"));
260+
assertThat("b is on the second line but we are only searching the first", testRegex, matchesTo("a\nb"));
260261
}
261262

262263
@Test
@@ -309,7 +310,7 @@ public void testCountWithRange() {
309310

310311
assertThat("regex don't match string", regex.getText(text4c), equalTo("ccc"));
311312
assertThat("regex don't match string", regex.getText(text2c), equalTo("cc"));
312-
assertThat("regex don't match string", regex.test(text1c), is(false));
313+
assertThat("regex don't match string", regex, not(matchesTo(text1c)));
313314
}
314315

315316
@Test
@@ -342,9 +343,9 @@ public void testOrWithCapture() {
342343
.find("abc")
343344
.or("def")
344345
.build();
345-
assertTrue("Starts with abc or def", testRegex.test("defzzz"));
346-
assertTrue("Starts with abc or def", testRegex.test("abczzz"));
347-
assertFalse("Doesn't start with abc or def", testRegex.testExact("xyzabcefg"));
346+
assertThat("Starts with abc or def", testRegex, matchesTo("defzzz"));
347+
assertThat("Starts with abc or def", testRegex, matchesTo("abczzz"));
348+
assertThat("Doesn't start with abc or def", testRegex, not(matchesExactly("xyzabcefg")));
348349

349350
assertThat(testRegex.getText("xxxabcdefzzz", 1), equalTo("abcdef"));
350351
assertThat(testRegex.getText("xxxdefzzz", 2), equalTo("null"));

src/test/java/ru/lanwen/verbalregex/NegativeCasesTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import static org.hamcrest.CoreMatchers.containsString;
88
import static org.hamcrest.CoreMatchers.equalTo;
9-
import static org.hamcrest.CoreMatchers.is;
109
import static org.junit.Assert.assertThat;
10+
import static ru.lanwen.verbalregex.matchers.TestMatchMatcher.matchesTo;
1111

1212
/**
1313
* User: lanwen
@@ -49,8 +49,8 @@ public void rangeWithThreeArgsUsesOnlyFirstTwo() throws Exception {
4949
@Test
5050
public void orWithNullMatchesAny() throws Exception {
5151
VerbalExpression regex = VerbalExpression.regex().startOfLine().then("a").or(null).build();
52-
assertThat("regex don't matches writed letter", regex.test("a"), is(true));
53-
assertThat("or(null) should match any", regex.test("bcd"), is(true));
52+
assertThat("regex don't matches writed letter", regex, matchesTo("a"));
53+
assertThat("or(null) should match any", regex, matchesTo("bcd"));
5454

5555
assertThat("or(null) extract only first", regex.getText("abcd"), equalTo("a"));
5656
}

src/test/java/ru/lanwen/verbalregex/PredefinedCharClassesTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static org.hamcrest.CoreMatchers.not;
88
import static org.hamcrest.MatcherAssert.assertThat;
99
import static ru.lanwen.verbalregex.VerbalExpression.regex;
10+
import static ru.lanwen.verbalregex.matchers.TestMatchMatcher.matchesTo;
1011

1112
/**
1213
* User: lanwen
@@ -24,8 +25,8 @@ public class PredefinedCharClassesTest {
2425
public void testWordChar() throws Exception {
2526
VerbalExpression regex = regex().wordChar().build();
2627

27-
assertThat("Not matches on letters", regex.test(LETTERS_NO_DIGITS + DIGITS), is(true));
28-
assertThat("matches on non letters", regex.test(NON_LETTERS + SPACE), is(false));
28+
assertThat("Not matches on letters", regex, matchesTo(LETTERS_NO_DIGITS + DIGITS));
29+
assertThat("matches on non letters", regex, not(matchesTo((NON_LETTERS + SPACE))));
2930
assertThat("Extracts wrong word chars",
3031
regex.getText(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS + SPACE), equalTo(LETTERS_NO_DIGITS + DIGITS));
3132

@@ -35,8 +36,8 @@ public void testWordChar() throws Exception {
3536
public void testNonWordChar() throws Exception {
3637
VerbalExpression regex = regex().nonWordChar().build();
3738

38-
assertThat("matches on letters", regex.test(LETTERS_NO_DIGITS + DIGITS), is(false));
39-
assertThat("Not matches on non letters", regex.test(NON_LETTERS + SPACE), is(true));
39+
assertThat("matches on letters", regex, not(matchesTo((LETTERS_NO_DIGITS + DIGITS))));
40+
assertThat("Not matches on non letters", regex, matchesTo(NON_LETTERS + SPACE));
4041
assertThat("Extracts wrong chars",
4142
regex.getText(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS + SPACE), equalTo(NON_LETTERS + SPACE));
4243

@@ -46,8 +47,8 @@ public void testNonWordChar() throws Exception {
4647
public void testSpace() throws Exception {
4748
VerbalExpression regex = regex().space().build();
4849

49-
assertThat("matches on letters", regex.test(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS), is(false));
50-
assertThat("Not matches on space", regex.test(SPACE), is(true));
50+
assertThat("matches on letters", regex, not(matchesTo((LETTERS_NO_DIGITS + DIGITS + NON_LETTERS))));
51+
assertThat("Not matches on space", regex, matchesTo(SPACE));
5152
assertThat("Extracts wrong chars",
5253
regex.getText(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS + SPACE), equalTo(SPACE));
5354

@@ -57,8 +58,8 @@ public void testSpace() throws Exception {
5758
public void testNonSpace() throws Exception {
5859
VerbalExpression regex = regex().nonSpace().build();
5960

60-
assertThat("Not matches on non space", regex.test(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS), is(true));
61-
assertThat("matches on space", regex.test(SPACE), is(false));
61+
assertThat("Not matches on non space", regex, matchesTo(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS));
62+
assertThat("matches on space", regex, not(matchesTo((SPACE))));
6263
assertThat("Extracts wrong chars",
6364
regex.getText(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS + SPACE), not(SPACE));
6465

@@ -68,8 +69,8 @@ public void testNonSpace() throws Exception {
6869
public void testDigit() throws Exception {
6970
VerbalExpression regex = regex().digit().build();
7071

71-
assertThat("matches on letters", regex.test(LETTERS_NO_DIGITS + SPACE + NON_LETTERS), is(false));
72-
assertThat("Not matches on digits", regex.test(DIGITS), is(true));
72+
assertThat("matches on letters", regex, not(matchesTo((LETTERS_NO_DIGITS + SPACE + NON_LETTERS))));
73+
assertThat("Not matches on digits", regex, matchesTo(DIGITS));
7374
assertThat("Extracts wrong chars",
7475
regex.getText(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS + SPACE), is(DIGITS));
7576

@@ -79,8 +80,8 @@ public void testDigit() throws Exception {
7980
public void testNonDigit() throws Exception {
8081
VerbalExpression regex = regex().nonDigit().build();
8182

82-
assertThat("Not matches on letters", regex.test(LETTERS_NO_DIGITS + SPACE + NON_LETTERS), is(true));
83-
assertThat("matches on digits", regex.test(DIGITS), is(false));
83+
assertThat("Not matches on letters", regex, matchesTo(LETTERS_NO_DIGITS + SPACE + NON_LETTERS));
84+
assertThat("matches on digits", regex, not(matchesTo((DIGITS))));
8485
assertThat("Extracts wrong chars",
8586
regex.getText(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS + SPACE), not(DIGITS));
8687

@@ -90,8 +91,8 @@ public void testNonDigit() throws Exception {
9091
public void testWord() throws Exception {
9192
VerbalExpression regex = regex().word().build();
9293

93-
assertThat("not matches on word", regex.test(LETTERS_NO_DIGITS + DIGITS), is(true));
94-
assertThat("matches on space and non letters", regex.test(SPACE + NON_LETTERS), is(false));
94+
assertThat("not matches on word", regex, matchesTo(LETTERS_NO_DIGITS + DIGITS));
95+
assertThat("matches on space and non letters", regex, not(matchesTo(SPACE + NON_LETTERS)));
9596
assertThat("extracts wrong chars",
9697
regex.getText(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS + SPACE), is(LETTERS_NO_DIGITS + DIGITS));
9798

0 commit comments

Comments
 (0)