Skip to content

Commit 64b682b

Browse files
committed
test: add more tests and align to match order
1 parent fbb8e32 commit 64b682b

File tree

1 file changed

+73
-21
lines changed
  • dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/select

1 file changed

+73
-21
lines changed

dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/select/SelectDslTest.kt

+73-21
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ class SelectDslTest : WithAssertions {
2020
private class Dto
2121
private class View
2222

23+
@Test
24+
fun `select() with a KClass and an expression`() {
25+
// when
26+
val select = queryPart {
27+
select(
28+
BigDecimal::class,
29+
expression1,
30+
).from(
31+
entity1,
32+
)
33+
}.toQuery()
34+
35+
val actual: SelectQuery<BigDecimal> = select // for type check
36+
37+
// then
38+
val expected = SelectQueries.selectQuery(
39+
returnType = BigDecimal::class,
40+
distinct = false,
41+
select = listOf(expression1),
42+
from = listOf(entity1),
43+
)
44+
45+
assertThat(actual).isEqualTo(expected)
46+
}
47+
2348
@Test
2449
fun `select() with an expression`() {
2550
// when
@@ -44,6 +69,32 @@ class SelectDslTest : WithAssertions {
4469
assertThat(actual).isEqualTo(expected)
4570
}
4671

72+
@Test
73+
fun `select() with a KClass and expressions`() {
74+
// when
75+
val select = queryPart {
76+
select(
77+
View::class,
78+
expression1,
79+
expression2,
80+
).from(
81+
entity1,
82+
)
83+
}.toQuery()
84+
85+
val actual: SelectQuery<View> = select // for type check
86+
87+
// then
88+
val expected = SelectQueries.selectQuery(
89+
returnType = View::class,
90+
distinct = false,
91+
select = listOf(expression1, expression2),
92+
from = listOf(entity1),
93+
)
94+
95+
assertThat(actual).isEqualTo(expected)
96+
}
97+
4798
@Test
4899
fun `select() with a generic type and expressions`() {
49100
// when
@@ -70,10 +121,10 @@ class SelectDslTest : WithAssertions {
70121
}
71122

72123
@Test
73-
fun `select() with a KClass`() {
124+
fun `selectDistinct() with a KClass and an expression`() {
74125
// when
75126
val select = queryPart {
76-
select(
127+
selectDistinct(
77128
BigDecimal::class,
78129
expression1,
79130
).from(
@@ -86,7 +137,7 @@ class SelectDslTest : WithAssertions {
86137
// then
87138
val expected = SelectQueries.selectQuery(
88139
returnType = BigDecimal::class,
89-
distinct = false,
140+
distinct = true,
90141
select = listOf(expression1),
91142
from = listOf(entity1),
92143
)
@@ -119,10 +170,11 @@ class SelectDslTest : WithAssertions {
119170
}
120171

121172
@Test
122-
fun `selectDistinct() with a generic type and expressions`() {
173+
fun `selectDistinct() with a KClass and expressions`() {
123174
// when
124175
val select = queryPart {
125-
selectDistinct<View>(
176+
selectDistinct(
177+
View::class,
126178
expression1,
127179
expression2,
128180
).from(
@@ -144,35 +196,36 @@ class SelectDslTest : WithAssertions {
144196
}
145197

146198
@Test
147-
fun `selectDistinct() with a KClass`() {
199+
fun `selectDistinct() with a generic type and expressions`() {
148200
// when
149201
val select = queryPart {
150-
selectDistinct(
151-
BigDecimal::class,
202+
selectDistinct<View>(
152203
expression1,
204+
expression2,
153205
).from(
154206
entity1,
155207
)
156208
}.toQuery()
157209

158-
val actual: SelectQuery<BigDecimal> = select // for type check
210+
val actual: SelectQuery<View> = select // for type check
159211

160212
// then
161213
val expected = SelectQueries.selectQuery(
162-
returnType = BigDecimal::class,
214+
returnType = View::class,
163215
distinct = true,
164-
select = listOf(expression1),
216+
select = listOf(expression1, expression2),
165217
from = listOf(entity1),
166218
)
167219

168220
assertThat(actual).isEqualTo(expected)
169221
}
170222

171223
@Test
172-
fun `selectNew() with a generic type and expressions`() {
224+
fun `selectNew() with a KClass and expressions`() {
173225
// when
174226
val select = queryPart {
175-
selectNew<Dto>(
227+
selectNew(
228+
Dto::class,
176229
expression1,
177230
expression2,
178231
).from(
@@ -199,11 +252,10 @@ class SelectDslTest : WithAssertions {
199252
}
200253

201254
@Test
202-
fun `selectNew() with a KClass`() {
255+
fun `selectNew() with a generic type and expressions`() {
203256
// when
204257
val select = queryPart {
205-
selectNew(
206-
Dto::class,
258+
selectNew<Dto>(
207259
expression1,
208260
expression2,
209261
).from(
@@ -230,10 +282,11 @@ class SelectDslTest : WithAssertions {
230282
}
231283

232284
@Test
233-
fun `selectDistinctNew() with a generic type and expressions`() {
285+
fun `selectDistinctNew() with a KClass and expressions`() {
234286
// when
235287
val select = queryPart {
236-
selectDistinctNew<Dto>(
288+
selectDistinctNew(
289+
Dto::class,
237290
expression1,
238291
expression2,
239292
).from(
@@ -260,11 +313,10 @@ class SelectDslTest : WithAssertions {
260313
}
261314

262315
@Test
263-
fun `selectDistinctNew() with a KClass`() {
316+
fun `selectDistinctNew() with a generic type and expressions`() {
264317
// when
265318
val select = queryPart {
266-
selectDistinctNew(
267-
Dto::class,
319+
selectDistinctNew<Dto>(
268320
expression1,
269321
expression2,
270322
).from(

0 commit comments

Comments
 (0)