Browse Source

Additional tests for IS query targeting plural paths.

Also needed to suppress a nullable probe false positive.

Original Pull Request: #4182
pull/4193/head
Christoph Strobl 1 month ago
parent
commit
7d5593d65e
No known key found for this signature in database
GPG Key ID: E6054036D0C37A4B
  1. 3
      spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaResultConverters.java
  2. 31
      spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java
  3. 9
      spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java

3
spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaResultConverters.java

@ -47,7 +47,8 @@ public final class JpaResultConverters { @@ -47,7 +47,8 @@ public final class JpaResultConverters {
*
* @author Thomas Darimont
*/
public enum BlobToByteArrayConverter implements Converter<Blob, byte[]> {
@SuppressWarnings("NullAway")
public enum BlobToByteArrayConverter implements Converter<Blob, byte @Nullable[]> {
INSTANCE;

31
spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java

@ -922,6 +922,8 @@ class UserRepositoryTests { @@ -922,6 +922,8 @@ class UserRepositoryTests {
assertThat(repository.existsById(secondUser.getId())).isTrue();
assertThat(repository.existsById(thirdUser.getId())).isTrue();
assertThat(repository.existsById(fourthUser.getId())).isTrue();
em.clear();
}
private static <T> void assertSameElements(Collection<T> first, Collection<T> second) {
@ -2914,10 +2916,8 @@ class UserRepositoryTests { @@ -2914,10 +2916,8 @@ class UserRepositoryTests {
@Test // GH-4172
void findByFluentSpecificationWithDtoProjectionJoins() {
flushTestUsers();
firstUser.setManager(secondUser);
em.persist(firstUser);
em.flush();
flushTestUsers();
record MyProjection(String name, int age, boolean active, String managerName, int managerAge) {
}
@ -3694,6 +3694,31 @@ class UserRepositoryTests { @@ -3694,6 +3694,31 @@ class UserRepositoryTests {
assertThat(result).containsOnly(firstUser, secondUser);
}
@Test // GH-4179
void countOnCollectionPropertyWithIs() {
firstUser.addColleague(secondUser);
thirdUser.addColleague(firstUser);
flushTestUsers();
assertThat(repository.countByColleagues(secondUser)).isOne();
assertThat(repository.countByColleaguesContaining(secondUser)).isOne();
}
@Test // GH-4179
void countOnNestedCollectionPropertyWithIs() {
firstUser.addColleague(secondUser);
firstUser.addColleague(thirdUser);
secondUser.addRole(adminRole);
flushTestUsers();
assertThat(repository.countByColleaguesRoles(adminRole)).isOne();
}
@Test // GH-2593
void insertStatementModifyingQueryWorks() {
flushTestUsers();

9
spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java

@ -561,6 +561,15 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi @@ -561,6 +561,15 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
// GH-4179
List<User> findByRoles(Role role);
// GH-4179
long countByColleagues(User user);
// GH-4179
long countByColleaguesContaining(User user);
// GH-4179
long countByColleaguesRoles(Role Role);
// DATAJPA-829
List<User> findByRolesContaining(Role role);

Loading…
Cancel
Save