Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b527ee2
Add ModelSetup to unify setup codes
TimothyGillespie Mar 21, 2021
480b883
Merge branch 'master' into TimothyGillespie/addOrderByTests
TimothyGillespie Mar 31, 2021
49e4fa0
Add assertOrderByContains method
TimothyGillespie Mar 31, 2021
8aaedb2
Add SectionIndexOutOfBoundException
TimothyGillespie Mar 31, 2021
1ae8ac8
Add retrieval methods for the sections
TimothyGillespie Mar 31, 2021
5d4e233
Add JavaDocs for getSectionList too
TimothyGillespie Mar 31, 2021
89c48dc
Add JavaDocs for getSectionList too
TimothyGillespie Mar 31, 2021
51907a4
Reorder methods more logically
TimothyGillespie Mar 31, 2021
ac7140e
Add assertSectionEquals method
TimothyGillespie Mar 31, 2021
5491a48
Remove OrderBy specific contains method
TimothyGillespie Mar 31, 2021
6f97433
Make assertion methods chainable
TimothyGillespie Mar 31, 2021
b73d7db
Add better fitting internal assert for the equal assertion
TimothyGillespie Mar 31, 2021
710b6c5
Add tests for OrderBy Clauses
TimothyGillespie Mar 31, 2021
9e857cf
Merge branch 'TimothyGillespie/addOrderByTests' of github.com:JavaWeb…
TimothyGillespie Mar 31, 2021
e4d3fc0
Remove explicit ASC as discussed
TimothyGillespie Apr 1, 2021
0037a3a
Merge branch 'TimothyGillespie/enableMultipleOrderBy' into TimothyGil…
TimothyGillespie Apr 2, 2021
fb00e4d
Adjust MySQL Query Building for the new OrderBy and fix OrderBy test
TimothyGillespie Apr 2, 2021
018ce02
Add test to assert the correct sort priority
TimothyGillespie Apr 2, 2021
c8e9a40
Add error case for calling order on same column twice
TimothyGillespie Apr 2, 2021
37ed312
Add note of purpose of OrderByClauseTest
TimothyGillespie Apr 2, 2021
5a74b53
Add JavaDocs to QueryOrderBy
TimothyGillespie Apr 2, 2021
5210447
Add JavaDocs to QueryOrderByElement
TimothyGillespie Apr 2, 2021
3bff425
Add JavaDocs to the order method on Query
TimothyGillespie Apr 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add assertSectionEquals method
  • Loading branch information
TimothyGillespie committed Mar 31, 2021
commit ac7140ef85e6376b5e37fa7ba45f1ddd8f7871d8
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ public void assertSectionContains(String topLevelKeyword, String containedSubstr
try {
sectionString = getSection(topLevelKeyword, sectionIndex);
} catch (SectionIndexOutOfBoundException e) {
fail(String.format(
"A top level section of type %s and index %d was tested but only %d sections of that type existed.",
e.getTopLevelKeyword(),
e.getAttemptedIndex(),
e.getSectionCount()
));
this.failDueToSectionIndexOutOfBounds(e);
}

assertTrue(
Expand All @@ -74,6 +69,39 @@ public void assertOrderByContains(String containedSubstring) {
this.assertSectionContains("ORDER BY", containedSubstring);
}

/**
* Asserts that the first occurring section of a given top level keyword is equal to the given string.
* This method uses the String.equals method internally and is therefore case sensitive.
*
* @param topLevelKeyword The top level keyword that prefaces the section.
* @param expectedString The substring which the first section of the given type should be equal to.
*/
public void assertSectionEquals(String topLevelKeyword, String expectedString) {
this.assertSectionEquals(topLevelKeyword, expectedString, 0);
}

/**
* Asserts that the i-th occurring section of a given top level keyword equal to the given string.
* This method uses the String.equals method internally and is therefore case sensitive.
*
* @param topLevelKeyword The top level keyword that prefaces the section.
* @param expectedString The substring which the specified section of the given type should be equal to.
* @param sectionIndex The index of the section to be checked, thus 0 refers to the first occurrence etc.
*/
public void assertSectionEquals(String topLevelKeyword, String expectedString, int sectionIndex) {
String sectionString = null;
try {
sectionString = getSection(topLevelKeyword, sectionIndex);
} catch (SectionIndexOutOfBoundException e) {
this.failDueToSectionIndexOutOfBounds(e);
}

assertTrue(
sectionString.equals(expectedString),
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)
);
}

/**
* Retrieves the inner part of a section by its keyword. With multiple occurrences it will only retrieve the first
* one. It does not include the keyword and one whitespaces at start and end.
Expand Down Expand Up @@ -123,4 +151,13 @@ public List<String> getSectionList(String topLevelKeyword) {
.getTopLevelSectionsByKeyword(topLevelKeyword);
}

private void failDueToSectionIndexOutOfBounds(SectionIndexOutOfBoundException exception) {
fail(String.format(
"A top level section of type %s and index %d was tested but only %d sections of that type existed.",
exception.getTopLevelKeyword(),
exception.getAttemptedIndex(),
exception.getSectionCount()
));
}

}