|
15 | 15 | */
|
16 | 16 | package org.springframework.data.jpa.repository.support;
|
17 | 17 |
|
18 |
| -import static java.util.Collections.singletonMap; |
19 |
| -import static org.assertj.core.api.Assertions.assertThat; |
20 |
| -import static org.assertj.core.api.Assertions.assertThatNoException; |
21 |
| -import static org.mockito.Mockito.any; |
22 |
| -import static org.mockito.Mockito.never; |
23 |
| -import static org.mockito.Mockito.verify; |
24 |
| -import static org.mockito.Mockito.when; |
25 |
| -import static org.springframework.data.jpa.domain.Specification.where; |
| 18 | +import static java.util.Collections.*; |
| 19 | +import static org.assertj.core.api.Assertions.*; |
| 20 | +import static org.mockito.Mockito.*; |
| 21 | +import static org.springframework.data.jpa.domain.Specification.*; |
26 | 22 |
|
27 | 23 | import jakarta.persistence.EntityGraph;
|
28 | 24 | import jakarta.persistence.EntityManager;
|
|
35 | 31 | import java.lang.reflect.Method;
|
36 | 32 | import java.lang.reflect.Modifier;
|
37 | 33 | import java.util.Arrays;
|
38 |
| -import java.util.List; |
39 | 34 | import java.util.Optional;
|
40 | 35 | import java.util.stream.Stream;
|
41 | 36 |
|
42 | 37 | import org.junit.jupiter.api.BeforeEach;
|
43 | 38 | import org.junit.jupiter.api.Test;
|
44 | 39 | import org.junit.jupiter.api.extension.ExtendWith;
|
45 | 40 | import org.junit.jupiter.params.ParameterizedTest;
|
| 41 | +import org.junit.jupiter.params.provider.Arguments; |
46 | 42 | import org.junit.jupiter.params.provider.MethodSource;
|
47 | 43 | import org.mockito.Mock;
|
48 | 44 | import org.mockito.junit.jupiter.MockitoExtension;
|
49 | 45 | import org.mockito.junit.jupiter.MockitoSettings;
|
50 | 46 | import org.mockito.quality.Strictness;
|
| 47 | + |
51 | 48 | import org.springframework.data.domain.PageRequest;
|
52 | 49 | import org.springframework.data.jpa.domain.sample.User;
|
53 | 50 | import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType;
|
@@ -229,13 +226,26 @@ void applyQueryHintsToCountQueriesForSpecificationPageables() {
|
229 | 226 | @ParameterizedTest // GH-3188
|
230 | 227 | @MethodSource("modifyingMethods")
|
231 | 228 | void checkTransactionalAnnotation(Method method) {
|
| 229 | + |
232 | 230 | Transactional transactional = method.getAnnotation(Transactional.class);
|
233 |
| - assertThat(transactional).as("Method [%s] should be annotated with @Transactional", method).isNotNull(); |
234 |
| - assertThat(transactional.readOnly()).as("Method [%s] should not be annotated with @Transactional(readOnly = true)", method).isFalse(); |
| 231 | + if (transactional == null) { |
| 232 | + transactional = method.getDeclaringClass().getAnnotation(Transactional.class); |
| 233 | + } |
| 234 | + |
| 235 | + assertThat(transactional).isNotNull(); |
| 236 | + assertThat(transactional.readOnly()).isFalse(); |
| 237 | + } |
| 238 | + |
| 239 | + static Stream<Arguments> modifyingMethods() { |
| 240 | + |
| 241 | + return Stream.of(SimpleJpaRepository.class.getDeclaredMethods()) |
| 242 | + .filter(method -> Modifier.isPublic(method.getModifiers())) // |
| 243 | + .filter(method -> !method.isBridge()) // |
| 244 | + .filter(method -> method.getName().startsWith("delete") || method.getName().startsWith("save")) |
| 245 | + .map(method -> Arguments.argumentSet(formatName(method), method)); |
235 | 246 | }
|
236 | 247 |
|
237 |
| - static List<Method> modifyingMethods() { |
238 |
| - return Stream.of(SimpleJpaRepository.class.getDeclaredMethods()).filter(method -> Modifier.isPublic(method.getModifiers()) && |
239 |
| - !method.isBridge() && (method.getName().startsWith("delete") || method.getName().startsWith("save"))).toList(); |
| 248 | + private static String formatName(Method method) { |
| 249 | + return method.toString().replaceAll("public ", "").replaceAll(SimpleJpaRepository.class.getName() + ".", ""); |
240 | 250 | }
|
241 | 251 | }
|
0 commit comments