Skip to content

Commit 6f97433

Browse files
Make assertion methods chainable
1 parent 5491a48 commit 6f97433

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/test/java/org/javawebstack/orm/test/shared/verification/QueryVerification.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ public QueryVerification(Query<?> query) {
3333
* @param topLevelKeyword The top level keyword that prefaces the section.
3434
* @param containedSubstring The substring which should be contained in the first section of the given type.
3535
*/
36-
public void assertSectionContains(String topLevelKeyword, String containedSubstring) {
36+
public QueryVerification assertSectionContains(String topLevelKeyword, String containedSubstring) {
3737
this.assertSectionContains(topLevelKeyword, containedSubstring, 0);
38+
return this;
3839
}
3940

4041
/**
@@ -45,18 +46,21 @@ public void assertSectionContains(String topLevelKeyword, String containedSubstr
4546
* @param containedSubstring The substring which should be contained in the first section of the given type.
4647
* @param sectionIndex The index of the section to be checked, thus 0 refers to the first occurrence etc.
4748
*/
48-
public void assertSectionContains(String topLevelKeyword, String containedSubstring, int sectionIndex) {
49+
public QueryVerification assertSectionContains(String topLevelKeyword, String containedSubstring, int sectionIndex) {
4950
String sectionString = null;
5051
try {
5152
sectionString = getSection(topLevelKeyword, sectionIndex);
5253
} catch (SectionIndexOutOfBoundException e) {
5354
this.failDueToSectionIndexOutOfBounds(e);
55+
return this;
5456
}
5557

5658
assertTrue(
5759
sectionString.contains(containedSubstring),
5860
String.format("The occurrence of index %d of %s section of the query did not contain a substring %s but looked like this: %s. Note that the match is case-sensitive.", sectionIndex, topLevelKeyword, containedSubstring, sectionString)
5961
);
62+
63+
return this;
6064
}
6165

6266
/**
@@ -66,8 +70,9 @@ public void assertSectionContains(String topLevelKeyword, String containedSubstr
6670
* @param topLevelKeyword The top level keyword that prefaces the section.
6771
* @param expectedString The substring which the first section of the given type should be equal to.
6872
*/
69-
public void assertSectionEquals(String topLevelKeyword, String expectedString) {
73+
public QueryVerification assertSectionEquals(String topLevelKeyword, String expectedString) {
7074
this.assertSectionEquals(topLevelKeyword, expectedString, 0);
75+
return this;
7176
}
7277

7378
/**
@@ -78,18 +83,21 @@ public void assertSectionEquals(String topLevelKeyword, String expectedString) {
7883
* @param expectedString The substring which the specified section of the given type should be equal to.
7984
* @param sectionIndex The index of the section to be checked, thus 0 refers to the first occurrence etc.
8085
*/
81-
public void assertSectionEquals(String topLevelKeyword, String expectedString, int sectionIndex) {
86+
public QueryVerification assertSectionEquals(String topLevelKeyword, String expectedString, int sectionIndex) {
8287
String sectionString = null;
8388
try {
8489
sectionString = getSection(topLevelKeyword, sectionIndex);
8590
} catch (SectionIndexOutOfBoundException e) {
8691
this.failDueToSectionIndexOutOfBounds(e);
92+
return this;
8793
}
8894

8995
assertTrue(
9096
sectionString.equals(expectedString),
9197
String.format("The occurrence of index %d of %s section of the query was not equal to the string %s but looked like this: %s. Note that the match is case-sensitive.", sectionIndex, topLevelKeyword, expectedString, sectionString)
9298
);
99+
100+
return this;
93101
}
94102

95103
/**

0 commit comments

Comments
 (0)