From bce51f44ba48c9e85ce6469768613c696a44d8ed Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Wed, 18 Dec 2024 14:16:42 +0100 Subject: [PATCH] Polishing. Moved Kotlin files to kotlin source directory. Minor formatting. See #1961 Original pull request #1962 --- spring-data-jdbc/pom.xml | 25 +-- .../core/JdbcAggregateOperationsExtensions.kt | 6 +- .../JdbcAggregateOperationsExtensionsTests.kt | 167 -------------- .../JdbcAggregateOperationsExtensionsTests.kt | 210 ++++++++++++++++++ 4 files changed, 225 insertions(+), 183 deletions(-) rename spring-data-jdbc/src/main/{java => kotlin}/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensions.kt (96%) delete mode 100644 spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensionsTests.kt create mode 100644 spring-data-jdbc/src/test/kotlin/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensionsTests.kt diff --git a/spring-data-jdbc/pom.xml b/spring-data-jdbc/pom.xml index 78fcf41cd..aba16d9e3 100644 --- a/spring-data-jdbc/pom.xml +++ b/spring-data-jdbc/pom.xml @@ -74,6 +74,18 @@ spring-core + + org.jetbrains.kotlin + kotlin-stdlib + true + + + + org.jetbrains.kotlin + kotlin-reflect + true + + org.mybatis mybatis-spring @@ -246,19 +258,6 @@ ${hikari.version} test - - - - org.jetbrains.kotlin - kotlin-stdlib - true - - - - org.jetbrains.kotlin - kotlin-reflect - true - diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensions.kt b/spring-data-jdbc/src/main/kotlin/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensions.kt similarity index 96% rename from spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensions.kt rename to spring-data-jdbc/src/main/kotlin/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensions.kt index 4ac6033f4..26ad9e429 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensions.kt +++ b/spring-data-jdbc/src/main/kotlin/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2017-2024 the original author or authors. + * Copyright 2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,17 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.data.jdbc.core import org.springframework.data.domain.Page import org.springframework.data.domain.Pageable import org.springframework.data.domain.Sort import org.springframework.data.relational.core.query.Query - import java.util.Optional /** - * Extensions for [JdbcAggregateOperations]. + * Kotlin extensions for [JdbcAggregateOperations]. * * @author Felix Desyatirikov * @since 3.5 diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensionsTests.kt b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensionsTests.kt deleted file mode 100644 index 5acb2faea..000000000 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensionsTests.kt +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2020-2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.jdbc.core - -import io.mockk.mockk -import io.mockk.verify -import org.junit.Test -import org.springframework.data.domain.Pageable -import org.springframework.data.domain.Sort -import org.springframework.data.jdbc.testing.TestClass -import org.springframework.data.relational.core.query.Query - -/** - * Unit tests for [JdbcAggregateOperations]. - * - * @author Felix Desyatirikov - */ - -class JdbcAggregateOperationsExtensionsTests { - - val operations = mockk(relaxed = true) - - @Test // gh-1961 - fun `count with reified type parameter extension should call its Java counterpart`() { - operations.count() - verify { operations.count(TestClass::class.java) } - } - - @Test // gh-1961 - fun `count(Query) with reified type parameter extension should call its Java counterpart`() { - val query = mockk(relaxed = true) - operations.count(query) - verify { - operations.count(query, TestClass::class.java) - } - } - - @Test // gh-1961 - fun `exists(Query) with reified type parameter extension should call its Java counterpart`() { - val query = mockk(relaxed = true) - operations.exists(query) - verify { - operations.exists(query, TestClass::class.java) - } - } - - @Test // gh-1961 - fun `existsById(id) with reified type parameter extension should call its Java counterpart`() { - val id = 1L - operations.existsById(id) - verify { - operations.existsById(id, TestClass::class.java) - } - } - - @Test // gh-1961 - fun `findById(id) with reified type parameter extension should call its Java counterpart`() { - val id = 1L - operations.findById(id) - verify { - operations.findById(id, TestClass::class.java) - } - } - - @Test // gh-1961 - fun `findAllById(ids) with reified type parameter extension should call its Java counterpart`() { - val ids = listOf(1L, 2L) - operations.findAllById(ids) - verify { - operations.findAllById(ids, TestClass::class.java) - } - } - - @Test // gh-1961 - fun `findAll() with reified type parameter extension should call its Java counterpart`() { - operations.findAll() - verify { - operations.findAll(TestClass::class.java) - } - } - - @Test // gh-1961 - fun `findAll(Sort) with reified type parameter extension should call its Java counterpart`() { - val sort = mockk(relaxed = true) - operations.findAll(sort) - verify { - operations.findAll(TestClass::class.java, sort) - } - } - - @Test // gh-1961 - fun `findAll(Pageable) with reified type parameter extension should call its Java counterpart`() { - val pageable = mockk(relaxed = true) - operations.findAll(pageable) - verify { - operations.findAll(TestClass::class.java, pageable) - } - } - - @Test // gh-1961 - fun `findOne(Query) with reified type parameter extension should call its Java counterpart`() { - val query = mockk(relaxed = true) - operations.findOne(query) - verify { - operations.findOne(query, TestClass::class.java) - } - } - - @Test // gh-1961 - fun `findAll(Query) with reified type parameter extension should call its Java counterpart`() { - val query = mockk(relaxed = true) - operations.findAll(query) - verify { - operations.findAll(query, TestClass::class.java) - } - } - - - @Test // gh-1961 - fun `findAll(Query, Pageable) with reified type parameter extension should call its Java counterpart`() { - val query = mockk(relaxed = true) - val pageable = mockk(relaxed = true) - operations.findAll(query, pageable) - verify { - operations.findAll(query, TestClass::class.java, pageable) - } - } - - @Test // gh-1961 - fun `deleteById(id) with reified type parameter extension should call its Java counterpart`() { - val id = 1L - operations.deleteById(id) - verify { - operations.deleteById(id, TestClass::class.java) - } - } - - @Test // gh-1961 - fun `deleteAllById(ids) with reified type parameter extension should call its Java counterpart`() { - val ids = listOf(1L, 2L) - operations.deleteAllById(ids) - verify { - operations.deleteAllById(ids, TestClass::class.java) - } - } - - @Test // gh-1961 - fun `deleteAll(ids) with reified type parameter extension should call its Java counterpart`() { - operations.deleteAll() - verify { - operations.deleteAll(TestClass::class.java) - } - } -} \ No newline at end of file diff --git a/spring-data-jdbc/src/test/kotlin/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensionsTests.kt b/spring-data-jdbc/src/test/kotlin/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensionsTests.kt new file mode 100644 index 000000000..0f3cff0cc --- /dev/null +++ b/spring-data-jdbc/src/test/kotlin/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensionsTests.kt @@ -0,0 +1,210 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.jdbc.core + +import io.mockk.mockk +import io.mockk.verify +import org.junit.Test +import org.springframework.data.domain.Pageable +import org.springframework.data.domain.Sort +import org.springframework.data.jdbc.testing.TestClass +import org.springframework.data.relational.core.query.Query + +/** + * Unit tests for [JdbcAggregateOperations]. + * + * @author Felix Desyatirikov + */ + +class JdbcAggregateOperationsExtensionsTests { + + val operations = mockk(relaxed = true) + + @Test // GH-1961 + fun `count with reified type parameter extension should call its Java counterpart`() { + + operations.count() + + verify { operations.count(TestClass::class.java) } + } + + @Test // GH-1961 + fun `count(Query) with reified type parameter extension should call its Java counterpart`() { + + val query = mockk(relaxed = true) + + operations.count(query) + + verify { + operations.count(query, TestClass::class.java) + } + } + + @Test // GH-1961 + fun `exists(Query) with reified type parameter extension should call its Java counterpart`() { + + val query = mockk(relaxed = true) + + operations.exists(query) + + verify { + operations.exists(query, TestClass::class.java) + } + } + + @Test // GH-1961 + fun `existsById(id) with reified type parameter extension should call its Java counterpart`() { + + val id = 1L + + operations.existsById(id) + + verify { + operations.existsById(id, TestClass::class.java) + } + } + + @Test // GH-1961 + fun `findById(id) with reified type parameter extension should call its Java counterpart`() { + + val id = 1L + + operations.findById(id) + + verify { + operations.findById(id, TestClass::class.java) + } + } + + @Test // GH-1961 + fun `findAllById(ids) with reified type parameter extension should call its Java counterpart`() { + + val ids = listOf(1L, 2L) + + operations.findAllById(ids) + + verify { + operations.findAllById(ids, TestClass::class.java) + } + } + + @Test // GH-1961 + fun `findAll() with reified type parameter extension should call its Java counterpart`() { + + operations.findAll() + + verify { + operations.findAll(TestClass::class.java) + } + } + + @Test // GH-1961 + fun `findAll(Sort) with reified type parameter extension should call its Java counterpart`() { + + val sort = mockk(relaxed = true) + + operations.findAll(sort) + + verify { + operations.findAll(TestClass::class.java, sort) + } + } + + @Test // GH-1961 + fun `findAll(Pageable) with reified type parameter extension should call its Java counterpart`() { + + val pageable = mockk(relaxed = true) + + operations.findAll(pageable) + + verify { + operations.findAll(TestClass::class.java, pageable) + } + } + + @Test // GH-1961 + fun `findOne(Query) with reified type parameter extension should call its Java counterpart`() { + + val query = mockk(relaxed = true) + + operations.findOne(query) + + verify { + operations.findOne(query, TestClass::class.java) + } + } + + @Test // GH-1961 + fun `findAll(Query) with reified type parameter extension should call its Java counterpart`() { + + val query = mockk(relaxed = true) + + operations.findAll(query) + + verify { + operations.findAll(query, TestClass::class.java) + } + } + + + @Test // GH-1961 + fun `findAll(Query, Pageable) with reified type parameter extension should call its Java counterpart`() { + + val query = mockk(relaxed = true) + val pageable = mockk(relaxed = true) + + operations.findAll(query, pageable) + + verify { + operations.findAll(query, TestClass::class.java, pageable) + } + } + + @Test // GH-1961 + fun `deleteById(id) with reified type parameter extension should call its Java counterpart`() { + + val id = 1L + + operations.deleteById(id) + + verify { + operations.deleteById(id, TestClass::class.java) + } + } + + @Test // GH-1961 + fun `deleteAllById(ids) with reified type parameter extension should call its Java counterpart`() { + + val ids = listOf(1L, 2L) + + operations.deleteAllById(ids) + + verify { + operations.deleteAllById(ids, TestClass::class.java) + } + } + + @Test // GH-1961 + fun `deleteAll(ids) with reified type parameter extension should call its Java counterpart`() { + + operations.deleteAll() + + verify { + operations.deleteAll(TestClass::class.java) + } + } +} \ No newline at end of file