1
+ /*
2
+ * Copyright 2020-2024 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org.springframework.data.jdbc.core
17
+
18
+ import io.mockk.mockk
19
+ import io.mockk.verify
20
+ import org.junit.Test
21
+ import org.springframework.data.domain.Pageable
22
+ import org.springframework.data.domain.Sort
23
+ import org.springframework.data.jdbc.testing.TestClass
24
+ import org.springframework.data.relational.core.query.Query
25
+
26
+ /* *
27
+ * Unit tests for [JdbcAggregateOperations].
28
+ *
29
+ * @author Felix Desyatirikov
30
+ */
31
+
32
+ class JdbcAggregateOperationsExtensionsTests {
33
+
34
+ val operations = mockk<JdbcAggregateOperations >(relaxed = true )
35
+
36
+ @Test // gh-1961
37
+ fun `count with reified type parameter extension should call its Java counterpart` () {
38
+ operations.count<TestClass >()
39
+ verify { operations.count(TestClass ::class .java) }
40
+ }
41
+
42
+ @Test // gh-1961
43
+ fun `count(Query) with reified type parameter extension should call its Java counterpart` () {
44
+ val query = mockk<Query >(relaxed = true )
45
+ operations.count<TestClass >(query)
46
+ verify {
47
+ operations.count(query, TestClass ::class .java)
48
+ }
49
+ }
50
+
51
+ @Test // gh-1961
52
+ fun `exists(Query) with reified type parameter extension should call its Java counterpart` () {
53
+ val query = mockk<Query >(relaxed = true )
54
+ operations.exists<TestClass >(query)
55
+ verify {
56
+ operations.exists(query, TestClass ::class .java)
57
+ }
58
+ }
59
+
60
+ @Test // gh-1961
61
+ fun `existsById(id) with reified type parameter extension should call its Java counterpart` () {
62
+ val id = 1L
63
+ operations.existsById<TestClass >(id)
64
+ verify {
65
+ operations.existsById(id, TestClass ::class .java)
66
+ }
67
+ }
68
+
69
+ @Test // gh-1961
70
+ fun `findById(id) with reified type parameter extension should call its Java counterpart` () {
71
+ val id = 1L
72
+ operations.findById<TestClass >(id)
73
+ verify {
74
+ operations.findById(id, TestClass ::class .java)
75
+ }
76
+ }
77
+
78
+ @Test // gh-1961
79
+ fun `findAllById(ids) with reified type parameter extension should call its Java counterpart` () {
80
+ val ids = listOf (1L , 2L )
81
+ operations.findAllById<TestClass >(ids)
82
+ verify {
83
+ operations.findAllById(ids, TestClass ::class .java)
84
+ }
85
+ }
86
+
87
+ @Test // gh-1961
88
+ fun `findAll() with reified type parameter extension should call its Java counterpart` () {
89
+ operations.findAll<TestClass >()
90
+ verify {
91
+ operations.findAll(TestClass ::class .java)
92
+ }
93
+ }
94
+
95
+ @Test // gh-1961
96
+ fun `findAll(Sort) with reified type parameter extension should call its Java counterpart` () {
97
+ val sort = mockk<Sort >(relaxed = true )
98
+ operations.findAll<TestClass >(sort)
99
+ verify {
100
+ operations.findAll(TestClass ::class .java, sort)
101
+ }
102
+ }
103
+
104
+ @Test // gh-1961
105
+ fun `findAll(Pageable) with reified type parameter extension should call its Java counterpart` () {
106
+ val pageable = mockk<Pageable >(relaxed = true )
107
+ operations.findAll<TestClass >(pageable)
108
+ verify {
109
+ operations.findAll(TestClass ::class .java, pageable)
110
+ }
111
+ }
112
+
113
+ @Test // gh-1961
114
+ fun `findOne(Query) with reified type parameter extension should call its Java counterpart` () {
115
+ val query = mockk<Query >(relaxed = true )
116
+ operations.findOne<TestClass >(query)
117
+ verify {
118
+ operations.findOne(query, TestClass ::class .java)
119
+ }
120
+ }
121
+
122
+ @Test // gh-1961
123
+ fun `findAll(Query) with reified type parameter extension should call its Java counterpart` () {
124
+ val query = mockk<Query >(relaxed = true )
125
+ operations.findAll<TestClass >(query)
126
+ verify {
127
+ operations.findAll(query, TestClass ::class .java)
128
+ }
129
+ }
130
+
131
+
132
+ @Test // gh-1961
133
+ fun `findAll(Query, Pageable) with reified type parameter extension should call its Java counterpart` () {
134
+ val query = mockk<Query >(relaxed = true )
135
+ val pageable = mockk<Pageable >(relaxed = true )
136
+ operations.findAll<TestClass >(query, pageable)
137
+ verify {
138
+ operations.findAll(query, TestClass ::class .java, pageable)
139
+ }
140
+ }
141
+
142
+ @Test // gh-1961
143
+ fun `deleteById(id) with reified type parameter extension should call its Java counterpart` () {
144
+ val id = 1L
145
+ operations.deleteById<TestClass >(id)
146
+ verify {
147
+ operations.deleteById(id, TestClass ::class .java)
148
+ }
149
+ }
150
+
151
+ @Test // gh-1961
152
+ fun `deleteAllById(ids) with reified type parameter extension should call its Java counterpart` () {
153
+ val ids = listOf (1L , 2L )
154
+ operations.deleteAllById<TestClass >(ids)
155
+ verify {
156
+ operations.deleteAllById(ids, TestClass ::class .java)
157
+ }
158
+ }
159
+
160
+ @Test // gh-1961
161
+ fun `deleteAll(ids) with reified type parameter extension should call its Java counterpart` () {
162
+ operations.deleteAll<TestClass >()
163
+ verify {
164
+ operations.deleteAll(TestClass ::class .java)
165
+ }
166
+ }
167
+ }
0 commit comments