|
1 | 1 | package org.javawebstack.orm.test.querybuilding; |
2 | 2 |
|
| 3 | +import org.javawebstack.orm.exception.ORMQueryException; |
3 | 4 | import org.javawebstack.orm.query.Query; |
4 | 5 | import org.javawebstack.orm.test.exception.SectionIndexOutOfBoundException; |
5 | 6 | import org.javawebstack.orm.test.shared.models.Datatype; |
|
12 | 13 | import java.util.stream.Collectors; |
13 | 14 |
|
14 | 15 | import static org.javawebstack.orm.test.shared.setup.ModelSetup.setUpModel; |
15 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
16 | | -import static org.junit.jupiter.api.Assertions.fail; |
| 16 | +import static org.junit.jupiter.api.Assertions.*; |
17 | 17 |
|
18 | 18 | public class OrderByClauseTest { |
19 | 19 |
|
@@ -92,6 +92,17 @@ void testMultipleOrderByClausesOfMixedOrder() { |
92 | 92 | .assertSectionContains("ORDER BY", "`primitive_integer` DESC"); |
93 | 93 | } |
94 | 94 |
|
| 95 | + @Test |
| 96 | + void testMultipleOrderByClausesOfMixedOrderReversed() { |
| 97 | + Query<Datatype> query = setUpModel(Datatype.class).query() |
| 98 | + .order("primitive_integer", true) |
| 99 | + .order("wrapper_integer", false); |
| 100 | + |
| 101 | + new QueryVerification(query) |
| 102 | + .assertSectionContains("ORDER BY", "`primitive_integer` DESC") |
| 103 | + .assertSectionContains("ORDER BY", "`wrapper_integer`"); |
| 104 | + } |
| 105 | + |
95 | 106 |
|
96 | 107 | @Test |
97 | 108 | // This test is important because putting the order by statements in different order is relevant (they set priorities) |
@@ -129,14 +140,14 @@ void testMultipleOrderByClausesOfRandomOrderForCorrectOrder() throws SectionInde |
129 | 140 |
|
130 | 141 | } |
131 | 142 |
|
| 143 | + /* |
| 144 | + * Error Cases |
| 145 | + */ |
132 | 146 | @Test |
133 | | - void testMultipleOrderByClausesOfMixedOrderReversed() { |
| 147 | + void testCannotCallOrderOnSameColumnTwice() { |
134 | 148 | Query<Datatype> query = setUpModel(Datatype.class).query() |
135 | | - .order("primitive_integer", true) |
136 | | - .order("wrapper_integer", false); |
| 149 | + .order("primitive_integer", true); |
137 | 150 |
|
138 | | - new QueryVerification(query) |
139 | | - .assertSectionContains("ORDER BY", "`primitive_integer` DESC") |
140 | | - .assertSectionContains("ORDER BY", "`wrapper_integer`"); |
| 151 | + assertThrows(ORMQueryException.class, () -> query.order("primitive_integer")); |
141 | 152 | } |
142 | 153 | } |
0 commit comments