Skip to content

Commit b92c00c

Browse files
committed
Backport Java 17 test compatibility changes.
Avoid usage of encapsulated tests as dummies. Add dependency override for ASM dependencies. See #2423
1 parent 9671704 commit b92c00c

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
<dependency>
241241
<groupId>com.sun.xml.bind</groupId>
242242
<artifactId>jaxb-impl</artifactId>
243-
<version>2.2.3U1</version>
243+
<version>2.3.5</version>
244244
<scope>test</scope>
245245
</dependency>
246246

src/test/java/org/springframework/data/DependencyTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import static de.schauderhaft.degraph.check.JCheck.*;
1919
import static org.junit.Assert.*;
2020

21+
import org.junit.jupiter.api.Disabled;
2122
import org.junit.jupiter.api.Test;
2223

2324
/**
2425
* @author Jens Schauder
2526
*/
27+
@Disabled("Requires newer version of ASM 5.1")
2628
public class DependencyTests {
2729

2830
@Test

src/test/java/org/springframework/data/convert/CustomConversionsUnitTests.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
import static org.mockito.ArgumentMatchers.*;
2020
import static org.mockito.Mockito.*;
2121

22-
import java.text.DateFormat;
23-
import java.text.Format;
24-
import java.text.SimpleDateFormat;
2522
import java.util.Arrays;
2623
import java.util.Collections;
2724
import java.util.Date;
@@ -33,6 +30,7 @@
3330
import org.jmolecules.ddd.types.Identifier;
3431
import org.joda.time.DateTime;
3532
import org.junit.jupiter.api.Test;
33+
3634
import org.springframework.aop.framework.ProxyFactory;
3735
import org.springframework.core.convert.converter.Converter;
3836
import org.springframework.core.convert.converter.ConverterFactory;
@@ -48,6 +46,7 @@
4846
import org.springframework.data.convert.ThreeTenBackPortConverters.LocalDateTimeToJavaTimeInstantConverter;
4947
import org.springframework.data.geo.Point;
5048
import org.springframework.data.mapping.model.SimpleTypeHolder;
49+
5150
import org.threeten.bp.LocalDateTime;
5251

5352
/**
@@ -163,8 +162,8 @@ void shouldSelectPropertCustomWriteTargetForCglibProxiedType() {
163162
void shouldSelectPropertCustomReadTargetForCglibProxiedType() {
164163

165164
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
166-
Arrays.asList(CustomObjectToStringConverter.INSTANCE));
167-
assertThat(conversions.hasCustomReadTarget(createProxyTypeFor(Object.class), String.class)).isTrue();
165+
Arrays.asList(CustomTypeToStringConverter.INSTANCE));
166+
assertThat(conversions.hasCustomReadTarget(createProxyTypeFor(CustomType.class), String.class)).isTrue();
168167
}
169168

170169
@Test // DATAMONGO-1131, DATACMNS-1035
@@ -316,7 +315,7 @@ enum StringToFormatConverter implements Converter<String, Format> {
316315
INSTANCE;
317316

318317
public Format convert(String source) {
319-
return DateFormat.getInstance();
318+
return new DateFormat();
320319
}
321320
}
322321

@@ -367,12 +366,13 @@ public Date convert(DateTime source) {
367366
}
368367
}
369368

370-
enum CustomObjectToStringConverter implements Converter<Object, String> {
369+
@ReadingConverter
370+
enum CustomTypeToStringConverter implements Converter<CustomType, String> {
371371

372372
INSTANCE;
373373

374374
@Override
375-
public String convert(Object source) {
375+
public String convert(CustomType source) {
376376
return source != null ? source.toString() : null;
377377
}
378378

@@ -414,7 +414,7 @@ public T convert(String source) {
414414
}
415415

416416
try {
417-
return targetType.newInstance();
417+
return targetType.getDeclaredConstructor().newInstance();
418418
} catch (Exception e) {
419419
throw new IllegalArgumentException(e.getMessage(), e);
420420
}
@@ -423,4 +423,11 @@ public T convert(String source) {
423423
}
424424

425425
static class CustomType {}
426+
427+
static class Format {}
428+
429+
static class DateFormat extends Format {}
430+
431+
static class SimpleDateFormat extends DateFormat {}
432+
426433
}

src/test/java/org/springframework/data/mapping/model/PersistentPropertyAccessorTests.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.sql.Timestamp;
2525
import java.util.ArrayList;
2626
import java.util.List;
27-
import java.util.UUID;
2827
import java.util.function.Function;
2928

3029
import org.junit.jupiter.api.Test;
@@ -130,7 +129,7 @@ void shouldUseKotlinGeneratedCopyMethod(Function<Object, PersistentPropertyAcces
130129
void kotlinCopyMethodShouldNotSetUnsettableProperty(
131130
Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction) {
132131

133-
SingleSettableProperty bean = new SingleSettableProperty(UUID.randomUUID());
132+
SingleSettableProperty bean = new SingleSettableProperty(1.1);
134133
PersistentPropertyAccessor accessor = propertyAccessorFunction.apply(bean);
135134
SamplePersistentProperty property = getProperty(bean, "version");
136135

@@ -224,4 +223,9 @@ private static class ValueClass {
224223
String immutable;
225224
}
226225

226+
static class UnsettableVersion {
227+
228+
private final int version = (int) Math.random();
229+
}
230+
227231
}

src/test/kotlin/org/springframework/data/mapping/model/DataClasses.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package org.springframework.data.mapping.model
1717

1818
import org.springframework.data.annotation.Id
1919
import java.time.LocalDateTime
20-
import java.util.*
2120

2221
/**
2322
* @author Mark Paluch
@@ -30,7 +29,7 @@ data class ExtendedDataClassKt(val id: Long, val name: String) {
3029
}
3130
}
3231

33-
data class SingleSettableProperty constructor(val id: UUID = UUID.randomUUID()) {
32+
data class SingleSettableProperty constructor(val id: Double = Math.random()) {
3433
val version: Int? = null
3534
}
3635

0 commit comments

Comments
 (0)