Skip to content

Commit c2c3e12

Browse files
committed
Better Kotlin Style
1 parent 0696425 commit c2c3e12

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTemplateDirectTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class CanonicalSpringKotlinTemplateDirectTest {
304304
.from(Person) {
305305
allRows()
306306
orderBy(id)
307-
}.withRowMapper(::personRowMapper)
307+
}.withRowMapper(personRowMapper)
308308

309309
assertThat(rows).hasSize(6)
310310
}
@@ -320,7 +320,7 @@ class CanonicalSpringKotlinTemplateDirectTest {
320320
and(occupation, isNotNull())
321321
orderBy(id)
322322
limit(3)
323-
}.withRowMapper(::personRowMapper)
323+
}.withRowMapper(personRowMapper)
324324

325325
assertThat(rows).hasSize(2)
326326
with(rows[0]) {
@@ -352,7 +352,7 @@ class CanonicalSpringKotlinTemplateDirectTest {
352352
where(id, isEqualTo(2))
353353
}
354354
}
355-
}.withRowMapper(::personRowMapper)
355+
}.withRowMapper(personRowMapper)
356356

357357
assertThat(rows).hasSize(2)
358358
with(rows[0]) {
@@ -384,7 +384,7 @@ class CanonicalSpringKotlinTemplateDirectTest {
384384
where(id, isEqualTo(2))
385385
}
386386
}
387-
}.withRowMapper(::personRowMapper)
387+
}.withRowMapper(personRowMapper)
388388

389389
assertThat(rows).hasSize(3)
390390
with(rows[0]) {
@@ -404,7 +404,7 @@ class CanonicalSpringKotlinTemplateDirectTest {
404404
id.`as`("A_ID"), firstName, lastName, birthDate, employed, occupation, addressId)
405405
.from(Person) {
406406
where(id, isEqualTo(1))
407-
}.withRowMapper(::personRowMapper)
407+
}.withRowMapper(personRowMapper)
408408

409409
with(record!!) {
410410
assertThat(id).isEqualTo(1)
@@ -465,7 +465,7 @@ class CanonicalSpringKotlinTemplateDirectTest {
465465
where(id, isLessThan(4))
466466
orderBy(id)
467467
limit(3)
468-
}.withRowMapper(::personWithAddressRowMapper)
468+
}.withRowMapper(personWithAddressRowMapper)
469469

470470

471471
assertThat(rows).hasSize(3)
@@ -496,7 +496,7 @@ class CanonicalSpringKotlinTemplateDirectTest {
496496
}
497497
orderBy(id)
498498
limit(3)
499-
}.withRowMapper(::personRowMapper)
499+
}.withRowMapper(personRowMapper)
500500

501501
assertThat(rows).hasSize(1)
502502
with(rows[0]) {
@@ -523,7 +523,7 @@ class CanonicalSpringKotlinTemplateDirectTest {
523523
}
524524
orderBy(id)
525525
limit(3)
526-
}.withRowMapper(::personRowMapper)
526+
}.withRowMapper(personRowMapper)
527527

528528
assertThat(rows).hasSize(3)
529529
with(rows[2]) {

src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTest.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class CanonicalSpringKotlinTest {
273273
val record = template.selectOne(id, firstName, lastName, birthDate, employed, occupation, addressId)
274274
.from(Person) {
275275
where(id, isEqualTo(100))
276-
}.withRowMapper(::personRowMapper)
276+
}.withRowMapper(personRowMapper)
277277

278278
assertThat(rows).isEqualTo(1)
279279
with(record!!) {
@@ -402,7 +402,7 @@ class CanonicalSpringKotlinTest {
402402
limit(3)
403403
}
404404

405-
val rows = template.selectList(selectStatement, ::personRowMapper)
405+
val rows = template.selectList(selectStatement, personRowMapper)
406406

407407
assertThat(rows).hasSize(2)
408408
with(rows[0]) {
@@ -425,7 +425,7 @@ class CanonicalSpringKotlinTest {
425425
where(id, isEqualTo(300))
426426
}
427427

428-
val record = template.selectOne(selectStatement, ::personRowMapper)
428+
val record = template.selectOne(selectStatement, personRowMapper)
429429

430430
assertThat(record).isNull()
431431
}
@@ -439,7 +439,7 @@ class CanonicalSpringKotlinTest {
439439
where(id, isEqualTo(1))
440440
}
441441

442-
val record = template.selectOne(selectStatement, ::personRowMapper)
442+
val record = template.selectOne(selectStatement, personRowMapper)
443443

444444
with(record!!) {
445445
assertThat(id).isEqualTo(1)
@@ -491,7 +491,7 @@ class CanonicalSpringKotlinTest {
491491

492492
assertThat(selectStatement.selectStatement).isEqualTo(expected)
493493

494-
val records = template.selectList(selectStatement, ::personRowMapper)
494+
val records = template.selectList(selectStatement, personRowMapper)
495495

496496
assertThat(records).hasSize(3)
497497
with(records[0]) {
@@ -554,7 +554,7 @@ class CanonicalSpringKotlinTest {
554554

555555
assertThat(selectStatement.selectStatement).isEqualTo(expected)
556556

557-
val records = template.selectList(selectStatement, ::personRowMapper)
557+
val records = template.selectList(selectStatement, personRowMapper)
558558

559559
assertThat(records).hasSize(3)
560560
with(records[0]) {
@@ -617,7 +617,7 @@ class CanonicalSpringKotlinTest {
617617

618618
assertThat(selectStatement.selectStatement).isEqualTo(expected)
619619

620-
val records = template.selectList(selectStatement, ::personRowMapper)
620+
val records = template.selectList(selectStatement, personRowMapper)
621621

622622
assertThat(records).hasSize(3)
623623
with(records[0]) {
@@ -681,7 +681,7 @@ class CanonicalSpringKotlinTest {
681681

682682
assertThat(selectStatement.selectStatement).isEqualTo(expected)
683683

684-
val records = template.selectList(selectStatement, ::personRowMapper)
684+
val records = template.selectList(selectStatement, personRowMapper)
685685

686686
assertThat(records).hasSize(8)
687687
with(records[0]) {
@@ -727,7 +727,7 @@ class CanonicalSpringKotlinTest {
727727

728728
assertThat(selectStatement.selectStatement).isEqualTo(expected)
729729

730-
val rows = template.selectList(selectStatement, ::personWithAddressRowMapper)
730+
val rows = template.selectList(selectStatement, personWithAddressRowMapper)
731731

732732

733733
with(rows[0]) {
@@ -769,7 +769,7 @@ class CanonicalSpringKotlinTest {
769769

770770
assertThat(selectStatement.selectStatement).isEqualTo(expected)
771771

772-
val rows = template.selectList(selectStatement, ::personRowMapper)
772+
val rows = template.selectList(selectStatement, personRowMapper)
773773

774774
assertThat(rows).hasSize(1)
775775
with(rows[0]) {
@@ -808,7 +808,7 @@ class CanonicalSpringKotlinTest {
808808

809809
assertThat(selectStatement.selectStatement).isEqualTo(expected)
810810

811-
val rows = template.selectList(selectStatement, ::personRowMapper)
811+
val rows = template.selectList(selectStatement, personRowMapper)
812812

813813
assertThat(rows).hasSize(3)
814814
with(rows[2]) {
@@ -957,7 +957,7 @@ class CanonicalSpringKotlinTest {
957957
where(id, isEqualTo(record::id))
958958
}
959959

960-
val returnedRecord = template.selectOne(selectStatement, ::personRowMapper)
960+
val returnedRecord = template.selectOne(selectStatement, personRowMapper)
961961
assertThat(returnedRecord).isNotNull()
962962
assertThat(returnedRecord!!.lastName).isNull()
963963
}
@@ -993,7 +993,7 @@ class CanonicalSpringKotlinTest {
993993
where(id, isEqualTo(record::id))
994994
}
995995

996-
val returnedRecord = template.selectOne(selectStatement, ::personRowMapper)
996+
val returnedRecord = template.selectOne(selectStatement, personRowMapper)
997997
assertThat(returnedRecord).isNotNull()
998998
assertThat(returnedRecord!!.lastName?.name).isEqualTo("Smith")
999999
}

src/test/kotlin/examples/kotlin/spring/canonical/RowMappers.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package examples.kotlin.spring.canonical
1717

1818
import java.sql.ResultSet
1919

20-
fun personRowMapper(rs: ResultSet, rowNum: Int) =
20+
val personRowMapper: (ResultSet, Int) -> PersonRecord = { rs, _ ->
2121
PersonRecord().apply {
2222
id = rs.getInt(1)
2323
firstName = rs.getString(2)
@@ -27,8 +27,9 @@ fun personRowMapper(rs: ResultSet, rowNum: Int) =
2727
occupation = rs.getString(6)
2828
addressId = rs.getInt(7)
2929
}
30+
}
3031

31-
fun personWithAddressRowMapper(rs: ResultSet, rowNum: Int) =
32+
val personWithAddressRowMapper: (ResultSet, Int) -> PersonWithAddress = { rs, _ ->
3233
PersonWithAddress().apply {
3334
id = rs.getInt(1)
3435
firstName = rs.getString(2)
@@ -44,3 +45,4 @@ fun personWithAddressRowMapper(rs: ResultSet, rowNum: Int) =
4445
state = rs.getString(10)
4546
}
4647
}
48+
}

0 commit comments

Comments
 (0)