Skip to content

Commit 1287c64

Browse files
committed
correspondence to Spring Boot 2.2
1. junit 4 to 5 2. spring boot 1 to 2 3. kotlin 1.2.21 to 1.3.61 4. gradle 4.5.1 to 5.6.4
1 parent 89233c8 commit 1287c64

File tree

5 files changed

+71
-62
lines changed

5 files changed

+71
-62
lines changed

build.gradle

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
12
plugins {
2-
id 'nebula.kotlin' version '1.2.21'
3-
id 'nebula.project' version '3.4.0'
4-
id 'nebula.release' version '6.3.0'
53
id 'nebula.maven-publish' version '7.0.1'
64
id 'nebula.nebula-bintray' version '3.5.2'
5+
id 'nebula.project' version '3.4.0'
6+
id 'nebula.release' version '6.3.0'
7+
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
8+
id 'org.jetbrains.kotlin.kapt' version '1.3.61'
79
}
810

911
group 'au.com.console'
@@ -16,12 +18,14 @@ sourceCompatibility = JavaVersion.VERSION_1_8
1618
targetCompatibility = JavaVersion.VERSION_1_8
1719

1820
dependencies {
19-
compile 'org.springframework.data:spring-data-jpa:1.10.2.RELEASE'
20-
compileOnly 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
21-
testCompile 'org.springframework.boot:spring-boot-starter-data-jpa:1.3.5.RELEASE'
21+
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61'
22+
compile 'org.jetbrains.kotlin:kotlin-reflect:1.3.61'
23+
compile 'org.springframework.data:spring-data-jpa:2.2.2.RELEASE'
24+
compileOnly 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final'
25+
testCompile 'org.springframework.boot:spring-boot-starter-data-jpa:2.2.2.RELEASE'
2226
testCompile 'com.h2database:h2:1.4.191'
23-
testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.5.RELEASE'
24-
testCompile 'junit:junit:4.12'
27+
testCompile 'org.springframework.boot:spring-boot-starter-test:2.2.2.RELEASE'
28+
testCompile 'org.junit.jupiter:junit-jupiter-api:5.5.2'
2529
}
2630

2731
tasks.bintrayUpload.dependsOn tasks.check
@@ -54,6 +58,14 @@ bintray {
5458
}
5559
}
5660

57-
task wrapper(type: Wrapper) {
58-
gradleVersion = "4.5.1"
61+
test {
62+
useJUnitPlatform()
63+
}
64+
65+
compileKotlin {
66+
jvmTarget = JavaVersion.VERSION_1_8
5967
}
68+
69+
compileTestKotlin {
70+
jvmTarget = JavaVersion.VERSION_1_8
71+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Feb 20 13:21:37 AEST 2018
1+
#Sat Jan 18 05:43:16 KST 2020
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
23
distributionBase=GRADLE_USER_HOME
34
distributionPath=wrapper/dists
4-
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip
6+
zipStoreBase=GRADLE_USER_HOME
Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package au.com.console.jpaspecificationdsl
22

33
import org.springframework.data.jpa.domain.Specification
4-
import org.springframework.data.jpa.domain.Specifications
54
import javax.persistence.criteria.*
65
import kotlin.reflect.KProperty1
76

@@ -11,22 +10,22 @@ fun <Z, T, R> From<Z, T>.join(prop: KProperty1<T, R?>): Join<T, R> = this.join<T
1110
// Helper to enable get by Property
1211
fun <R> Path<*>.get(prop: KProperty1<*, R?>): Path<R> = this.get<R>(prop.name)
1312

14-
// Version of Specifications.where that makes the CriteriaBuilder implicit
15-
fun <T> where(makePredicate: CriteriaBuilder.(Root<T>) -> Predicate): Specifications<T> =
16-
Specifications.where<T> { root, _, criteriaBuilder -> criteriaBuilder.makePredicate(root) }
13+
// Version of Specification.where that makes the CriteriaBuilder implicit
14+
fun <T> where(makePredicate: CriteriaBuilder.(Root<T>) -> Predicate): Specification<T> =
15+
Specification.where<T> { root, _, criteriaBuilder -> criteriaBuilder.makePredicate(root) }
1716

18-
// helper function for defining Specifications that take a Path to a property and send it to a CriteriaBuilder
19-
private fun <T, R> KProperty1<T, R?>.spec(makePredicate: CriteriaBuilder.(path: Path<R>) -> Predicate): Specifications<T> =
17+
// helper function for defining Specification that take a Path to a property and send it to a CriteriaBuilder
18+
private fun <T, R> KProperty1<T, R?>.spec(makePredicate: CriteriaBuilder.(path: Path<R>) -> Predicate): Specification<T> =
2019
this.let { property -> where { root -> makePredicate(root.get(property)) } }
2120

2221
// Equality
23-
fun <T, R> KProperty1<T, R?>.equal(x: R): Specifications<T> = spec { equal(it, x) }
24-
fun <T, R> KProperty1<T, R?>.notEqual(x: R): Specifications<T> = spec { notEqual(it, x) }
22+
fun <T, R> KProperty1<T, R?>.equal(x: R): Specification<T> = spec { equal(it, x) }
23+
fun <T, R> KProperty1<T, R?>.notEqual(x: R): Specification<T> = spec { notEqual(it, x) }
2524

2625
// Ignores empty collection otherwise an empty 'in' predicate will be generated which will never match any results
27-
fun <T, R: Any> KProperty1<T, R?>.`in`(values: Collection<R>): Specifications<T> = if (values.isNotEmpty()) spec { path ->
26+
fun <T, R: Any> KProperty1<T, R?>.`in`(values: Collection<R>): Specification<T> = if (values.isNotEmpty()) spec { path ->
2827
`in`(path).apply { values.forEach { this.value(it) } }
29-
} else Specifications.where<T>(null)
28+
} else Specification.where<T>(null)
3029

3130
// Comparison
3231
fun <T> KProperty1<T, Number?>.le(x: Number) = spec { le(it, x) }
@@ -54,36 +53,36 @@ fun <T, E, R : Collection<E>> KProperty1<T, R?>.isMember(elem: E) = spec { isMem
5453
fun <T, E, R : Collection<E>> KProperty1<T, R?>.isNotMember(elem: E) = spec { isNotMember(elem, it) }
5554

5655
// Strings
57-
fun <T> KProperty1<T, String?>.like(x: String): Specifications<T> = spec { like(it, x) }
58-
fun <T> KProperty1<T, String?>.like(x: String, escapeChar: Char): Specifications<T> = spec { like(it, x, escapeChar) }
59-
fun <T> KProperty1<T, String?>.notLike(x: String): Specifications<T> = spec { notLike(it, x) }
60-
fun <T> KProperty1<T, String?>.notLike(x: String, escapeChar: Char): Specifications<T> = spec { notLike(it, x, escapeChar) }
56+
fun <T> KProperty1<T, String?>.like(x: String): Specification<T> = spec { like(it, x) }
57+
fun <T> KProperty1<T, String?>.like(x: String, escapeChar: Char): Specification<T> = spec { like(it, x, escapeChar) }
58+
fun <T> KProperty1<T, String?>.notLike(x: String): Specification<T> = spec { notLike(it, x) }
59+
fun <T> KProperty1<T, String?>.notLike(x: String, escapeChar: Char): Specification<T> = spec { notLike(it, x, escapeChar) }
6160

6261
// And
63-
infix fun <T> Specifications<T>.and(other: Specification<T>): Specifications<T> = this.and(other)
64-
inline fun <reified T> and(vararg specs: Specifications<T>?): Specifications<T> {
62+
infix fun <T> Specification<T>.and(other: Specification<T>): Specification<T> = this.and(other)
63+
inline fun <reified T> and(vararg specs: Specification<T>?): Specification<T> {
6564
return and(specs.toList())
6665
}
67-
inline fun <reified T> and(specs: Iterable<Specifications<T>?>): Specifications<T> {
68-
return combineSpecifications(specs, Specifications<T>::and)
66+
inline fun <reified T> and(specs: Iterable<Specification<T>?>): Specification<T> {
67+
return combineSpecification(specs, Specification<T>::and)
6968
}
7069

7170
// Or
72-
infix fun <T> Specifications<T>.or(other: Specification<T>) : Specifications<T> = this.or(other)
73-
inline fun <reified T> or(vararg specs: Specifications<T>?): Specifications<T> {
71+
infix fun <T> Specification<T>.or(other: Specification<T>) : Specification<T> = this.or(other)
72+
inline fun <reified T> or(vararg specs: Specification<T>?): Specification<T> {
7473
return or(specs.toList())
7574
}
76-
inline fun <reified T> or(specs: Iterable<Specifications<T>?>): Specifications<T> {
77-
return combineSpecifications(specs, Specifications<T>::or)
75+
inline fun <reified T> or(specs: Iterable<Specification<T>?>): Specification<T> {
76+
return combineSpecification(specs, Specification<T>::or)
7877
}
7978

8079
// Not
81-
operator fun <T> Specifications<T>.not(): Specifications<T> = Specifications.not(this)
80+
operator fun <T> Specification<T>.not(): Specification<T> = Specification.not(this)
8281

83-
// Combines Specifications with an operation
84-
inline fun <reified T> combineSpecifications(specs: Iterable<Specification<T>?>, operation: Specifications<T>.(Specification<T>) -> Specifications<T>): Specifications<T> {
82+
// Combines Specification with an operation
83+
inline fun <reified T> combineSpecification(specs: Iterable<Specification<T>?>, operation: Specification<T>.(Specification<T>) -> Specification<T>): Specification<T> {
8584
return specs.filterNotNull().fold(emptySpecification()) { existing, new -> existing.operation(new) }
8685
}
8786

8887
// Empty Specification
89-
inline fun <reified T> emptySpecification(): Specifications<T> = Specifications.where<T>(null)
88+
inline fun <reified T> emptySpecification(): Specification<T> = Specification.where<T>(null)

src/test/kotlin/au/com/console/jpaspecificationdsl/JPASpecificationDSLTest.kt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package au.com.console.jpaspecificationdsl
22

33
import org.hamcrest.MatcherAssert.assertThat
4+
import org.hamcrest.Matchers
45
import org.hamcrest.Matchers.containsInAnyOrder
5-
import org.hamcrest.Matchers.equalTo
6-
import org.junit.After
7-
import org.junit.Before
8-
import org.junit.Test
9-
import org.junit.runner.RunWith
6+
import org.junit.jupiter.api.AfterEach
7+
import org.junit.jupiter.api.BeforeEach
108
import org.springframework.beans.factory.annotation.Autowired
119
import org.springframework.boot.autoconfigure.SpringBootApplication
12-
import org.springframework.boot.test.SpringApplicationConfiguration
13-
import org.springframework.data.jpa.domain.Specifications
14-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
10+
import org.springframework.data.jpa.domain.Specification
1511
import org.springframework.transaction.annotation.Transactional
12+
import org.junit.jupiter.api.Test
13+
import org.junit.jupiter.api.extension.ExtendWith
14+
import org.springframework.test.context.junit.jupiter.SpringExtension
1615

1716

18-
@RunWith(SpringJUnit4ClassRunner::class)
19-
@SpringApplicationConfiguration(classes = arrayOf(JPASpecificationDSLTest::class))
17+
@ExtendWith(SpringExtension::class)
2018
@SpringBootApplication
2119
@Transactional
2220
open class JPASpecificationDSLTest {
@@ -28,7 +26,7 @@ open class JPASpecificationDSLTest {
2826
lateinit var theWalkingDead: TvShow
2927
lateinit var betterCallSaul: TvShow
3028

31-
@Before
29+
@BeforeEach
3230
fun setup() {
3331
with(tvShowRepo) {
3432
hemlockGrove = save(
@@ -55,7 +53,7 @@ open class JPASpecificationDSLTest {
5553
}
5654
}
5755

58-
@After
56+
@AfterEach
5957
fun tearDown() {
6058
tvShowRepo.deleteAll()
6159
}
@@ -74,7 +72,7 @@ open class JPASpecificationDSLTest {
7472
* A single TvShowQuery is equivalent to an AND of all supplied criteria.
7573
* Note: any criteria that is null will be ignored (not included in the query).
7674
*/
77-
fun TvShowQuery.toSpecification(): Specifications<TvShow> = and(
75+
fun TvShowQuery.toSpecification(): Specification<TvShow> = and(
7876
hasName(name),
7977
availableOnNetflix(availableOnNetflix),
8078
hasKeywordIn(keywords),
@@ -84,20 +82,20 @@ open class JPASpecificationDSLTest {
8482
/**
8583
* A collection of TvShowQueries is equivalent to an OR of all the queries in the collection.
8684
*/
87-
fun Iterable<TvShowQuery>.toSpecification(): Specifications<TvShow> = or(
85+
fun Iterable<TvShowQuery>.toSpecification(): Specification<TvShow> = or(
8886
map { query -> query.toSpecification() }
8987
)
9088

9189
@Test
9290
fun `Get a tv show by id`() {
93-
val show = tvShowRepo.findOne(hemlockGrove.id)
94-
assertThat(show, equalTo(hemlockGrove))
91+
val show = tvShowRepo.findById(hemlockGrove.id)
92+
assertThat(show.get(), Matchers.equalTo(hemlockGrove))
9593
}
9694

9795
@Test
9896
fun `Get a tv show by id equality`() {
9997
val show = tvShowRepo.findOne(TvShow::id.equal(theWalkingDead.id))
100-
assertThat(show, equalTo(theWalkingDead))
98+
assertThat(show.get(), Matchers.equalTo(theWalkingDead))
10199
}
102100

103101
@Test

src/test/kotlin/au/com/console/jpaspecificationdsl/TvShowRepository.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package au.com.console.jpaspecificationdsl
22

3-
import org.springframework.data.jpa.domain.Specifications
3+
import org.springframework.data.jpa.domain.Specification
44
import org.springframework.data.jpa.repository.JpaSpecificationExecutor
55
import org.springframework.data.repository.CrudRepository
66
import org.springframework.stereotype.Repository
@@ -36,22 +36,22 @@ data class StarRating(
3636
// Note: these functions return null for a null input. This means that when included in
3737
// and() or or() they will be ignored as if they weren't supplied.
3838

39-
fun hasName(name: String?): Specifications<TvShow>? = name?.let {
39+
fun hasName(name: String?): Specification<TvShow>? = name?.let {
4040
TvShow::name.equal(it)
4141
}
4242

43-
fun availableOnNetflix(available: Boolean?): Specifications<TvShow>? = available?.let {
43+
fun availableOnNetflix(available: Boolean?): Specification<TvShow>? = available?.let {
4444
TvShow::availableOnNetflix.equal(it)
4545
}
4646

47-
fun hasReleaseDateIn(releaseDates: List<String>?): Specifications<TvShow>? = releaseDates?.let {
47+
fun hasReleaseDateIn(releaseDates: List<String>?): Specification<TvShow>? = releaseDates?.let {
4848
TvShow::releaseDate.`in`(releaseDates)
4949
}
5050

51-
fun hasKeywordIn(keywords: List<String>?): Specifications<TvShow>? = keywords?.let {
51+
fun hasKeywordIn(keywords: List<String>?): Specification<TvShow>? = keywords?.let {
5252
or(keywords.map(::hasKeyword))
5353
}
5454

55-
fun hasKeyword(keyword: String?): Specifications<TvShow>? = keyword?.let {
55+
fun hasKeyword(keyword: String?): Specification<TvShow>? = keyword?.let {
5656
TvShow::synopsis.like("%$keyword%")
5757
}

0 commit comments

Comments
 (0)