Skip to content

Commit be84272

Browse files
ErikPelligregturn
authored andcommitted
Change calls to deprecated methods in tests to their replacements.
* ClassTypeInformation is deprecated and will be removed. Use TypeInformation instead. * StringUtils.trimWhitespace can be replaced with the strip method called on the String object. * StandardAnnotationMetadata is deprecated in favor of the factory method AnnotationMetadata.introspect(Class). Resolves #2739.
1 parent b06e5ea commit be84272

File tree

9 files changed

+22
-17
lines changed

9 files changed

+22
-17
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
3333
import org.springframework.data.mapping.model.Property;
3434
import org.springframework.data.mapping.model.SimpleTypeHolder;
35-
import org.springframework.data.util.ClassTypeInformation;
3635
import org.springframework.data.util.Lazy;
3736
import org.springframework.data.util.TypeInformation;
3837
import org.springframework.lang.Nullable;
@@ -46,6 +45,7 @@
4645
* @author Greg Turnquist
4746
* @author Christoph Strobl
4847
* @author Mark Paluch
48+
* @author Erik Pellizzon
4949
* @since 1.3
5050
*/
5151
class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty<JpaPersistentProperty>
@@ -254,7 +254,7 @@ private TypeInformation<?> detectAssociationTargetType() {
254254
continue;
255255
}
256256

257-
return ClassTypeInformation.from((Class<?>) entityValue);
257+
return TypeInformation.of((Class<?>) entityValue);
258258
}
259259

260260
return null;

spring-data-jpa/src/test/java/org/springframework/data/jpa/infrastructure/HibernateTestUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Testing utilities for Hibernate.
2727
*
2828
* @author Oliver Gierke
29+
* @author Erik Pellizzon
2930
* @soundtrack Ron Spielman - Africa's Napoleon (Swimming In The Dark)
3031
* @since 1.10.2
3132
*/
@@ -48,7 +49,7 @@ public static PersistenceProvider getPersistenceProvider() {
4849
if (ClassUtils.isPresent(provider, classLoader)) {
4950

5051
try {
51-
return (PersistenceProvider) ClassUtils.forName(provider, classLoader).newInstance();
52+
return (PersistenceProvider) ClassUtils.forName(provider, classLoader).getDeclaredConstructor().newInstance();
5253
} catch (Exception o_O) {
5354
throw new RuntimeException(o_O);
5455
}

spring-data-jpa/src/test/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImplUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.mockito.quality.Strictness;
4444
import org.springframework.data.annotation.AccessType.Type;
4545
import org.springframework.data.annotation.Version;
46-
import org.springframework.data.util.ClassTypeInformation;
4746
import org.springframework.data.util.TypeInformation;
4847

4948
/**
@@ -52,6 +51,7 @@
5251
* @author Oliver Gierke
5352
* @author Greg Turnquist
5453
* @author Jens Schauder
54+
* @author Erik Pellizzon
5555
*/
5656
@ExtendWith(MockitoExtension.class)
5757
@MockitoSettings(strictness = Strictness.LENIENT)
@@ -147,7 +147,7 @@ void considersTargetEntityTypeForPropertyType() {
147147
Iterable<? extends TypeInformation<?>> entityType = property.getPersistentEntityTypeInformation();
148148
assertThat(entityType.iterator().hasNext()).isTrue();
149149
assertThat(entityType.iterator().next())
150-
.isEqualTo(ClassTypeInformation.from(Implementation.class));
150+
.isEqualTo(TypeInformation.of(Implementation.class));
151151
}
152152

153153
@Test // DATAJPA-716

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/config/JpaRepositoriesRegistrarIntegrationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.aop.Advisor;
3030
import org.springframework.aop.framework.Advised;
31+
import org.springframework.aop.support.AopUtils;
3132
import org.springframework.beans.factory.annotation.Autowired;
3233
import org.springframework.context.annotation.Bean;
3334
import org.springframework.context.annotation.Configuration;
@@ -43,13 +44,13 @@
4344
import org.springframework.test.context.ContextConfiguration;
4445
import org.springframework.test.context.junit.jupiter.SpringExtension;
4546
import org.springframework.transaction.PlatformTransactionManager;
46-
import org.springframework.util.ClassUtils;
4747

4848
/**
4949
* Integration test for {@link JpaRepositoriesRegistrar}.
5050
*
5151
* @author Oliver Gierke
5252
* @author Jens Schauder
53+
* @author Erik Pellizzon
5354
*/
5455
@ExtendWith(SpringExtension.class)
5556
@ContextConfiguration
@@ -103,7 +104,7 @@ void foo() {
103104
void doesNotProxyPlainAtRepositoryBeans() {
104105

105106
assertThat(sampleRepository).isNotNull();
106-
assertThat(ClassUtils.isCglibProxy(sampleRepository)).isFalse();
107+
assertThat(AopUtils.isCglibProxy(sampleRepository)).isFalse();
107108

108109
assertExceptionTranslationActive(repository);
109110
}

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/config/JpaRepositoriesRegistrarUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
import org.springframework.core.env.StandardEnvironment;
2727
import org.springframework.core.io.DefaultResourceLoader;
2828
import org.springframework.core.type.AnnotationMetadata;
29-
import org.springframework.core.type.StandardAnnotationMetadata;
3029
import org.springframework.data.jpa.repository.sample.UserRepository;
3130

3231
/**
3332
* Unit test for {@link JpaRepositoriesRegistrar}.
3433
*
3534
* @author Oliver Gierke
3635
* @author Jens Schauder
36+
* @author Erik Pellizzon
3737
*/
3838
class JpaRepositoriesRegistrarUnitTests {
3939

@@ -43,7 +43,7 @@ class JpaRepositoriesRegistrarUnitTests {
4343
@BeforeEach
4444
void setUp() {
4545

46-
metadata = new StandardAnnotationMetadata(Config.class, true);
46+
metadata = AnnotationMetadata.introspect(Config.class);
4747
registry = new DefaultListableBeanFactory();
4848
}
4949

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpaQueryMethodUnitTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
5757
import org.springframework.data.repository.query.Param;
5858
import org.springframework.data.repository.query.QueryMethod;
59-
import org.springframework.data.util.ClassTypeInformation;
59+
import org.springframework.data.util.TypeInformation;
6060

6161
/**
6262
* Unit test for {@link QueryMethod}.
@@ -66,6 +66,7 @@
6666
* @author Christoph Strobl
6767
* @author Jens Schauder
6868
* @author Mark Paluch
69+
* @author Erik Pellizzon
6970
*/
7071
@ExtendWith(MockitoExtension.class)
7172
@MockitoSettings(strictness = Strictness.LENIENT)
@@ -107,7 +108,7 @@ void setUp() throws Exception {
107108
Integer.class);
108109

109110
when(metadata.getReturnType(any(Method.class)))
110-
.thenAnswer(invocation -> ClassTypeInformation.fromReturnTypeOf(invocation.getArgument(0)));
111+
.thenAnswer(invocation -> TypeInformation.fromReturnTypeOf(invocation.getArgument(0)));
111112
}
112113

113114
@Test

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/NamedQueryUnitTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@
4141
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
4242
import org.springframework.data.repository.core.RepositoryMetadata;
4343
import org.springframework.data.repository.query.QueryCreationException;
44-
import org.springframework.data.util.ClassTypeInformation;
44+
import org.springframework.data.util.TypeInformation;
4545

4646
/**
4747
* Unit tests for {@link NamedQuery}.
4848
*
4949
* @author Oliver Gierke
5050
* @author Thomas Darimont
5151
* @author Mark Paluch
52+
* @author Erik Pellizzon
5253
*/
5354
@ExtendWith(MockitoExtension.class)
5455
@MockitoSettings(strictness = Strictness.LENIENT)
@@ -72,7 +73,7 @@ void setUp() throws SecurityException, NoSuchMethodException {
7273
when(metadata.getDomainType()).thenReturn((Class) String.class);
7374
when(metadata.getReturnedDomainClass(method)).thenReturn((Class) String.class);
7475
when(metadata.getReturnType(any(Method.class)))
75-
.thenAnswer(invocation -> ClassTypeInformation.fromReturnTypeOf(invocation.getArgument(0)));
76+
.thenAnswer(invocation -> TypeInformation.fromReturnTypeOf(invocation.getArgument(0)));
7677

7778
when(em.getMetamodel()).thenReturn(metamodel);
7879
when(em.getEntityManagerFactory()).thenReturn(emf);

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.springframework.data.domain.Sort;
3131
import org.springframework.data.domain.Sort.Order;
3232
import org.springframework.data.jpa.domain.JpaSort;
33-
import org.springframework.util.StringUtils;
3433

3534
/**
3635
* Unit test for {@link QueryUtils}.
@@ -48,6 +47,7 @@
4847
* @author Darin Manica
4948
* @author Chris Fraser
5049
* @author Michał Pachucki
50+
* @author Erik Pellizzon
5151
*/
5252
class QueryUtilsUnitTests {
5353

@@ -264,7 +264,7 @@ private String normalizeWhitespace(String s) {
264264
return matcher.replaceAll(" ").trim();
265265
}
266266

267-
return StringUtils.trimWhitespace(s);
267+
return s.strip();
268268
}
269269

270270
@Test

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/SimpleJpaQueryUnitTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
import org.springframework.data.repository.core.RepositoryMetadata;
5858
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
5959
import org.springframework.data.repository.query.RepositoryQuery;
60-
import org.springframework.data.util.ClassTypeInformation;
60+
import org.springframework.data.util.TypeInformation;
6161
import org.springframework.expression.spel.standard.SpelExpressionParser;
6262

6363
/**
@@ -70,6 +70,7 @@
7070
* @author Mark Paluch
7171
* @author Greg Turnquist
7272
* @author Krzysztof Krason
73+
* @author Erik Pellizzon
7374
*/
7475
@ExtendWith(MockitoExtension.class)
7576
@MockitoSettings(strictness = Strictness.LENIENT)
@@ -105,7 +106,7 @@ void setUp() throws SecurityException, NoSuchMethodException {
105106
when(metadata.getDomainType()).thenReturn((Class) User.class);
106107
when(metadata.getReturnedDomainClass(Mockito.any(Method.class))).thenReturn((Class) User.class);
107108
when(metadata.getReturnType(Mockito.any(Method.class)))
108-
.thenAnswer(invocation -> ClassTypeInformation.fromReturnTypeOf(invocation.getArgument(0)));
109+
.thenAnswer(invocation -> TypeInformation.fromReturnTypeOf(invocation.getArgument(0)));
109110

110111
Method setUp = UserRepository.class.getMethod("findByLastname", String.class);
111112
method = new JpaQueryMethod(setUp, metadata, factory, extractor);

0 commit comments

Comments
 (0)