DATACMNS-1718 - Migrate tests to JUnit 5.
This commit is contained in:
@@ -21,10 +21,11 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.data.mapping.Alias;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
@@ -35,23 +36,23 @@ import org.springframework.data.util.ClassTypeInformation;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ConfigurableTypeInformationMapperUnitTests<T extends PersistentProperty<T>> {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ConfigurableTypeInformationMapperUnitTests<T extends PersistentProperty<T>> {
|
||||
|
||||
ConfigurableTypeInformationMapper mapper;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mapper = new ConfigurableTypeInformationMapper(Collections.singletonMap(String.class, "1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNullTypeMap() {
|
||||
void rejectsNullTypeMap() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new ConfigurableTypeInformationMapper(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNonBijectionalMap() {
|
||||
void rejectsNonBijectionalMap() {
|
||||
|
||||
Map<Class<?>, String> map = new HashMap<>();
|
||||
map.put(String.class, "1");
|
||||
@@ -61,14 +62,14 @@ public class ConfigurableTypeInformationMapperUnitTests<T extends PersistentProp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writesMapKeyForType() {
|
||||
void writesMapKeyForType() {
|
||||
|
||||
assertThat(mapper.createAliasFor(ClassTypeInformation.from(String.class))).isEqualTo(Alias.of("1"));
|
||||
assertThat(mapper.createAliasFor(ClassTypeInformation.from(Object.class))).isEqualTo(Alias.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readsTypeForMapKey() {
|
||||
void readsTypeForMapKey() {
|
||||
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("1"))).isEqualTo(ClassTypeInformation.from(String.class));
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("unmapped"))).isNull();
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.convert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.internal.util.Supplier;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
@@ -33,10 +33,10 @@ import org.springframework.data.convert.ConverterBuilder.WritingConverterBuilder
|
||||
* @since 2.0
|
||||
* @soundtrack John Mayer - In the Blood (The Search for Everything)
|
||||
*/
|
||||
public class ConverterBuilderUnitTests {
|
||||
class ConverterBuilderUnitTests {
|
||||
|
||||
@Test // DATACMNS-1034
|
||||
public void setsUpBidirectionalConvertersFromReading() {
|
||||
void setsUpBidirectionalConvertersFromReading() {
|
||||
|
||||
ConverterAware builder = ConverterBuilder.reading(String.class, Long.class, it -> Long.valueOf(it))
|
||||
.andWriting(Object::toString);
|
||||
@@ -46,7 +46,7 @@ public class ConverterBuilderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1034
|
||||
public void setsUpBidirectionalConvertersFromWriting() {
|
||||
void setsUpBidirectionalConvertersFromWriting() {
|
||||
|
||||
ConverterAware builder = ConverterBuilder.writing(Long.class, String.class, Object::toString)
|
||||
.andReading(it -> Long.valueOf(it));
|
||||
@@ -56,7 +56,7 @@ public class ConverterBuilderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1034
|
||||
public void setsUpReadingConverter() {
|
||||
void setsUpReadingConverter() {
|
||||
|
||||
ReadingConverterBuilder<String, Long> builder = ConverterBuilder.reading(String.class, Long.class,
|
||||
string -> Long.valueOf(string));
|
||||
@@ -66,7 +66,7 @@ public class ConverterBuilderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1034
|
||||
public void setsUpWritingConverter() {
|
||||
void setsUpWritingConverter() {
|
||||
|
||||
WritingConverterBuilder<Long, String> builder = ConverterBuilder.writing(Long.class, String.class,
|
||||
Object::toString);
|
||||
|
||||
@@ -55,7 +55,7 @@ import org.threeten.bp.LocalDateTime;
|
||||
* @author Mark Paluch
|
||||
* @since 2.0
|
||||
*/
|
||||
public class CustomConversionsUnitTests {
|
||||
class CustomConversionsUnitTests {
|
||||
|
||||
static final SimpleTypeHolder DATE_EXCLUDING_SIMPLE_TYPE_HOLDER = new SimpleTypeHolder(
|
||||
Collections.singleton(Date.class), true) {
|
||||
@@ -67,7 +67,7 @@ public class CustomConversionsUnitTests {
|
||||
};
|
||||
|
||||
@Test // DATACMNS-1035
|
||||
public void findsBasicReadAndWriteConversions() {
|
||||
void findsBasicReadAndWriteConversions() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
|
||||
Arrays.asList(FormatToStringConverter.INSTANCE, StringToFormatConverter.INSTANCE));
|
||||
@@ -80,7 +80,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1035
|
||||
public void considersSubtypesCorrectly() {
|
||||
void considersSubtypesCorrectly() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
|
||||
Arrays.asList(NumberToStringConverter.INSTANCE, StringToNumberConverter.INSTANCE));
|
||||
@@ -90,7 +90,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1101
|
||||
public void considersSubtypeCachingCorrectly() {
|
||||
void considersSubtypeCachingCorrectly() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
|
||||
Arrays.asList(NumberToStringConverter.INSTANCE, StringToNumberConverter.INSTANCE));
|
||||
@@ -101,7 +101,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1035
|
||||
public void populatesConversionServiceCorrectly() {
|
||||
void populatesConversionServiceCorrectly() {
|
||||
|
||||
GenericConversionService conversionService = new DefaultConversionService();
|
||||
|
||||
@@ -113,7 +113,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-259, DATACMNS-1035
|
||||
public void doesNotConsiderTypeSimpleIfOnlyReadConverterIsRegistered() {
|
||||
void doesNotConsiderTypeSimpleIfOnlyReadConverterIsRegistered() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
|
||||
Arrays.asList(StringToFormatConverter.INSTANCE));
|
||||
@@ -121,7 +121,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-298, DATACMNS-1035
|
||||
public void discoversConvertersForSubtypesOfMongoTypes() {
|
||||
void discoversConvertersForSubtypesOfMongoTypes() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
|
||||
Arrays.asList(StringToIntegerConverter.INSTANCE));
|
||||
@@ -130,7 +130,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-795, DATACMNS-1035
|
||||
public void favorsCustomConverterForIndeterminedTargetType() {
|
||||
void favorsCustomConverterForIndeterminedTargetType() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
|
||||
Arrays.asList(DateTimeToStringConverter.INSTANCE));
|
||||
@@ -138,7 +138,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-881, DATACMNS-1035
|
||||
public void customConverterOverridesDefault() {
|
||||
void customConverterOverridesDefault() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
|
||||
Arrays.asList(CustomDateTimeConverter.INSTANCE));
|
||||
@@ -149,7 +149,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1001, DATACMNS-1035
|
||||
public void shouldSelectPropertCustomWriteTargetForCglibProxiedType() {
|
||||
void shouldSelectPropertCustomWriteTargetForCglibProxiedType() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
|
||||
Arrays.asList(FormatToStringConverter.INSTANCE));
|
||||
@@ -157,7 +157,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1001, DATACMNS-1035
|
||||
public void shouldSelectPropertCustomReadTargetForCglibProxiedType() {
|
||||
void shouldSelectPropertCustomReadTargetForCglibProxiedType() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
|
||||
Arrays.asList(CustomObjectToStringConverter.INSTANCE));
|
||||
@@ -165,7 +165,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1131, DATACMNS-1035
|
||||
public void registersConvertersForJsr310() {
|
||||
void registersConvertersForJsr310() {
|
||||
|
||||
CustomConversions customConversions = new CustomConversions(StoreConversions.NONE, Collections.emptyList());
|
||||
|
||||
@@ -173,7 +173,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1131, DATACMNS-1035
|
||||
public void registersConvertersForThreeTenBackPort() {
|
||||
void registersConvertersForThreeTenBackPort() {
|
||||
|
||||
CustomConversions customConversions = new CustomConversions(StoreConversions.NONE, Collections.emptyList());
|
||||
|
||||
@@ -181,7 +181,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1302, DATACMNS-1035
|
||||
public void registersConverterFactoryCorrectly() {
|
||||
void registersConverterFactoryCorrectly() {
|
||||
|
||||
StoreConversions conversions = StoreConversions.of(new SimpleTypeHolder(Collections.singleton(Format.class), true));
|
||||
|
||||
@@ -192,7 +192,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1034
|
||||
public void registersConverterFromConverterAware() {
|
||||
void registersConverterFromConverterAware() {
|
||||
|
||||
ConverterAware converters = ConverterBuilder //
|
||||
.reading(Locale.class, CustomType.class, left -> new CustomType()) //
|
||||
@@ -211,7 +211,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1615
|
||||
public void skipsUnsupportedDefaultWritingConverter() {
|
||||
void skipsUnsupportedDefaultWritingConverter() {
|
||||
|
||||
ConverterRegistry registry = mock(ConverterRegistry.class);
|
||||
|
||||
@@ -222,7 +222,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1665
|
||||
public void registersStoreConverter() {
|
||||
void registersStoreConverter() {
|
||||
|
||||
ConverterRegistry registry = mock(ConverterRegistry.class);
|
||||
|
||||
@@ -237,7 +237,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1615
|
||||
public void doesNotSkipUnsupportedUserConverter() {
|
||||
void doesNotSkipUnsupportedUserConverter() {
|
||||
|
||||
ConverterRegistry registry = mock(ConverterRegistry.class);
|
||||
|
||||
@@ -248,7 +248,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1615
|
||||
public void skipsConverterBasedOnConfiguration() {
|
||||
void skipsConverterBasedOnConfiguration() {
|
||||
|
||||
ConverterRegistry registry = mock(ConverterRegistry.class);
|
||||
|
||||
@@ -260,7 +260,7 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1615
|
||||
public void doesNotSkipUserConverterConverterEvenWhenConfigurationWouldNotAllowIt() {
|
||||
void doesNotSkipUserConverterConverterEvenWhenConfigurationWouldNotAllowIt() {
|
||||
|
||||
ConverterRegistry registry = mock(ConverterRegistry.class);
|
||||
|
||||
@@ -381,7 +381,7 @@ public class CustomConversionsUnitTests {
|
||||
|
||||
private final Class<T> targetType;
|
||||
|
||||
public StringToFormat(Class<T> targetType) {
|
||||
StringToFormat(Class<T> targetType) {
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,14 @@ import static org.mockito.Mockito.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.data.mapping.Alias;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
@@ -36,8 +39,9 @@ import org.springframework.data.util.TypeInformation;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultTypeMapperUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class DefaultTypeMapperUnitTests {
|
||||
|
||||
static final TypeInformation<String> STRING_TYPE_INFO = ClassTypeInformation.from(String.class);
|
||||
static final Alias ALIAS = Alias.of(String.class.getName());
|
||||
@@ -48,8 +52,8 @@ public class DefaultTypeMapperUnitTests {
|
||||
DefaultTypeMapper<Map<String, String>> typeMapper;
|
||||
Map<String, String> source;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.typeMapper = new DefaultTypeMapper<>(accessor, Collections.singletonList(mapper));
|
||||
this.source = Collections.singletonMap("key", ALIAS.toString());
|
||||
@@ -59,7 +63,7 @@ public class DefaultTypeMapperUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cachesResolvedTypeInformation() {
|
||||
void cachesResolvedTypeInformation() {
|
||||
|
||||
TypeInformation<?> information = typeMapper.readType(source);
|
||||
assertThat(information).isEqualTo(STRING_TYPE_INFO);
|
||||
@@ -70,7 +74,7 @@ public class DefaultTypeMapperUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-349
|
||||
public void returnsTypeAliasForInformation() {
|
||||
void returnsTypeAliasForInformation() {
|
||||
|
||||
Alias alias = Alias.of("alias");
|
||||
doReturn(alias).when(mapper).createAliasFor(STRING_TYPE_INFO);
|
||||
@@ -79,7 +83,7 @@ public class DefaultTypeMapperUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-783
|
||||
public void specializesRawSourceTypeUsingGenericContext() {
|
||||
void specializesRawSourceTypeUsingGenericContext() {
|
||||
|
||||
ClassTypeInformation<Foo> root = ClassTypeInformation.from(Foo.class);
|
||||
TypeInformation<?> propertyType = root.getProperty("abstractBar");
|
||||
|
||||
@@ -28,27 +28,21 @@ import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.data.convert.Jsr310ConvertersUnitTests.CommonTests;
|
||||
import org.springframework.data.convert.Jsr310ConvertersUnitTests.DurationConversionTests;
|
||||
import org.springframework.data.convert.Jsr310ConvertersUnitTests.PeriodConversionTests;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Jsr310Converters}.
|
||||
@@ -58,9 +52,7 @@ import org.springframework.data.convert.Jsr310ConvertersUnitTests.PeriodConversi
|
||||
* @author Jens Schauder
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ CommonTests.class, DurationConversionTests.class, PeriodConversionTests.class })
|
||||
public class Jsr310ConvertersUnitTests {
|
||||
class Jsr310ConvertersUnitTests {
|
||||
|
||||
static final Date NOW = new Date();
|
||||
static final ConversionService CONVERSION_SERVICE;
|
||||
@@ -76,171 +68,162 @@ public class Jsr310ConvertersUnitTests {
|
||||
CONVERSION_SERVICE = conversionService;
|
||||
}
|
||||
|
||||
public static class CommonTests {
|
||||
static final String FORMAT_DATE = "yyyy-MM-dd";
|
||||
static final String FORMAT_TIME = "HH:mm:ss.SSS";
|
||||
static final String FORMAT_FULL = String.format("%s'T'%s", FORMAT_DATE, FORMAT_TIME);
|
||||
|
||||
static final String FORMAT_DATE = "yyyy-MM-dd";
|
||||
static final String FORMAT_TIME = "HH:mm:ss.SSS";
|
||||
static final String FORMAT_FULL = String.format("%s'T'%s", FORMAT_DATE, FORMAT_TIME);
|
||||
@Test
|
||||
// DATACMNS-606, DATACMNS-1091
|
||||
void convertsDateToLocalDateTime() {
|
||||
assertThat(CONVERSION_SERVICE.convert(NOW, LocalDateTime.class)).matches(formatted(NOW, FORMAT_FULL));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-606, DATACMNS-1091
|
||||
public void convertsDateToLocalDateTime() {
|
||||
assertThat(CONVERSION_SERVICE.convert(NOW, LocalDateTime.class)).matches(formatted(NOW, FORMAT_FULL));
|
||||
}
|
||||
@Test
|
||||
// DATACMNS-606, DATACMNS-1091
|
||||
void convertsLocalDateTimeToDate() {
|
||||
|
||||
@Test // DATACMNS-606, DATACMNS-1091
|
||||
public void convertsLocalDateTimeToDate() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
assertThat(CONVERSION_SERVICE.convert(now, Date.class)).matches(formatted(now, FORMAT_FULL));
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
assertThat(CONVERSION_SERVICE.convert(now, Date.class)).matches(formatted(now, FORMAT_FULL));
|
||||
}
|
||||
@Test
|
||||
// DATACMNS-606, DATACMNS-1091
|
||||
void convertsDateToLocalDate() {
|
||||
assertThat(CONVERSION_SERVICE.convert(NOW, LocalDate.class)).matches(formatted(NOW, FORMAT_DATE));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-606, DATACMNS-1091
|
||||
public void convertsDateToLocalDate() {
|
||||
assertThat(CONVERSION_SERVICE.convert(NOW, LocalDate.class)).matches(formatted(NOW, FORMAT_DATE));
|
||||
}
|
||||
@Test
|
||||
// DATACMNS-606, DATACMNS-1091
|
||||
void convertsLocalDateToDate() {
|
||||
|
||||
@Test // DATACMNS-606, DATACMNS-1091
|
||||
public void convertsLocalDateToDate() {
|
||||
LocalDate now = LocalDate.now();
|
||||
assertThat(CONVERSION_SERVICE.convert(now, Date.class)).matches(formatted(now, FORMAT_DATE));
|
||||
}
|
||||
|
||||
LocalDate now = LocalDate.now();
|
||||
assertThat(CONVERSION_SERVICE.convert(now, Date.class)).matches(formatted(now, FORMAT_DATE));
|
||||
}
|
||||
@Test
|
||||
// DATACMNS-606, DATACMNS-1091
|
||||
void convertsDateToLocalTime() {
|
||||
assertThat(CONVERSION_SERVICE.convert(NOW, LocalTime.class)).matches(formatted(NOW, FORMAT_TIME));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-606, DATACMNS-1091
|
||||
public void convertsDateToLocalTime() {
|
||||
assertThat(CONVERSION_SERVICE.convert(NOW, LocalTime.class)).matches(formatted(NOW, FORMAT_TIME));
|
||||
}
|
||||
@Test
|
||||
// DATACMNS-606, DATACMNS-1091
|
||||
void convertsLocalTimeToDate() {
|
||||
|
||||
@Test // DATACMNS-606, DATACMNS-1091
|
||||
public void convertsLocalTimeToDate() {
|
||||
LocalTime now = LocalTime.now();
|
||||
assertThat(CONVERSION_SERVICE.convert(now, Date.class)).matches(formatted(now, FORMAT_TIME));
|
||||
}
|
||||
|
||||
LocalTime now = LocalTime.now();
|
||||
assertThat(CONVERSION_SERVICE.convert(now, Date.class)).matches(formatted(now, FORMAT_TIME));
|
||||
}
|
||||
@Test
|
||||
// DATACMNS-623
|
||||
void convertsDateToInstant() {
|
||||
|
||||
@Test // DATACMNS-623
|
||||
public void convertsDateToInstant() {
|
||||
Date now = new Date();
|
||||
assertThat(CONVERSION_SERVICE.convert(now, Instant.class)).isEqualTo(now.toInstant());
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
assertThat(CONVERSION_SERVICE.convert(now, Instant.class)).isEqualTo(now.toInstant());
|
||||
}
|
||||
@Test
|
||||
// DATACMNS-623
|
||||
void convertsInstantToDate() {
|
||||
|
||||
@Test // DATACMNS-623
|
||||
public void convertsInstantToDate() {
|
||||
Date now = new Date();
|
||||
assertThat(CONVERSION_SERVICE.convert(now.toInstant(), Date.class)).isEqualTo(now);
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
assertThat(CONVERSION_SERVICE.convert(now.toInstant(), Date.class)).isEqualTo(now);
|
||||
}
|
||||
@Test
|
||||
void convertsZoneIdToStringAndBack() {
|
||||
|
||||
@Test
|
||||
public void convertsZoneIdToStringAndBack() {
|
||||
Map<String, ZoneId> ids = new HashMap<>();
|
||||
ids.put("Europe/Berlin", ZoneId.of("Europe/Berlin"));
|
||||
ids.put("+06:00", ZoneId.of("+06:00"));
|
||||
|
||||
Map<String, ZoneId> ids = new HashMap<>();
|
||||
ids.put("Europe/Berlin", ZoneId.of("Europe/Berlin"));
|
||||
ids.put("+06:00", ZoneId.of("+06:00"));
|
||||
|
||||
for (Entry<String, ZoneId> entry : ids.entrySet()) {
|
||||
assertThat(CONVERSION_SERVICE.convert(entry.getValue(), String.class)).isEqualTo(entry.getKey());
|
||||
assertThat(CONVERSION_SERVICE.convert(entry.getKey(), ZoneId.class)).isEqualTo(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1243
|
||||
public void convertsLocalDateTimeToInstantAndBack() {
|
||||
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
|
||||
Instant instant = CONVERSION_SERVICE.convert(dateTime, Instant.class);
|
||||
LocalDateTime convertedDateTime = CONVERSION_SERVICE.convert(dateTime, LocalDateTime.class);
|
||||
|
||||
assertThat(convertedDateTime).isEqualTo(dateTime);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1440
|
||||
public void convertsIsoFormattedStringToLocalDate() {
|
||||
|
||||
LocalDate date = LocalDate.now();
|
||||
|
||||
assertThat(CONVERSION_SERVICE.convert(date.toString(), LocalDate.class)).isEqualTo(date);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1440
|
||||
public void convertsIsoFormattedStringToLocalDateTime() {
|
||||
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
|
||||
assertThat(CONVERSION_SERVICE.convert(date.toString(), LocalDateTime.class)).isEqualTo(date);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1440
|
||||
public void convertsIsoFormattedStringToInstant() {
|
||||
|
||||
Instant date = Instant.now();
|
||||
|
||||
assertThat(CONVERSION_SERVICE.convert(date.toString(), Instant.class)).isEqualTo(date);
|
||||
}
|
||||
|
||||
private static Predicate<Date> formatted(Temporal expected, String format) {
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
||||
return d -> format(d, format).equals(formatter.format(expected));
|
||||
}
|
||||
|
||||
private static Predicate<Temporal> formatted(Date expected, String format) {
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
||||
return d -> formatter.format(d).equals(format(expected, format));
|
||||
}
|
||||
|
||||
private static String format(Date date, String format) {
|
||||
return new SimpleDateFormat(format).format(date);
|
||||
for (Entry<String, ZoneId> entry : ids.entrySet()) {
|
||||
assertThat(CONVERSION_SERVICE.convert(entry.getValue(), String.class)).isEqualTo(entry.getKey());
|
||||
assertThat(CONVERSION_SERVICE.convert(entry.getKey(), ZoneId.class)).isEqualTo(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static class DurationConversionTests extends ConversionTest<Duration> {
|
||||
@Test
|
||||
// DATACMNS-1243
|
||||
void convertsLocalDateTimeToInstantAndBack() {
|
||||
|
||||
// DATACMNS-951
|
||||
@Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
|
||||
return Arrays.asList(new Object[][] { //
|
||||
{ "PT240H", Duration.ofDays(10) }, //
|
||||
{ "PT2H", Duration.ofHours(2) }, //
|
||||
{ "PT3M", Duration.ofMinutes(3) }, //
|
||||
{ "PT4S", Duration.ofSeconds(4) }, //
|
||||
{ "PT0.005S", Duration.ofMillis(5) }, //
|
||||
{ "PT0.000000006S", Duration.ofNanos(6) } //
|
||||
});
|
||||
}
|
||||
Instant instant = CONVERSION_SERVICE.convert(dateTime, Instant.class);
|
||||
LocalDateTime convertedDateTime = CONVERSION_SERVICE.convert(dateTime, LocalDateTime.class);
|
||||
|
||||
assertThat(convertedDateTime).isEqualTo(dateTime);
|
||||
}
|
||||
|
||||
public static class PeriodConversionTests extends ConversionTest<Period> {
|
||||
@Test
|
||||
// DATACMNS-1440
|
||||
void convertsIsoFormattedStringToLocalDate() {
|
||||
|
||||
// DATACMNS-951
|
||||
@Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
LocalDate date = LocalDate.now();
|
||||
|
||||
return Arrays.asList(new Object[][] { //
|
||||
{ "P2D", Period.ofDays(2) }, //
|
||||
{ "P21D", Period.ofWeeks(3) }, //
|
||||
{ "P4M", Period.ofMonths(4) }, //
|
||||
{ "P5Y", Period.ofYears(5) }, //
|
||||
});
|
||||
}
|
||||
assertThat(CONVERSION_SERVICE.convert(date.toString(), LocalDate.class)).isEqualTo(date);
|
||||
}
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public static abstract class ConversionTest<T> {
|
||||
@Test
|
||||
// DATACMNS-1440
|
||||
void convertsIsoFormattedStringToLocalDateTime() {
|
||||
|
||||
public @Parameter(0) String string;
|
||||
public @Parameter(1) T target;
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
|
||||
@Test
|
||||
public void convertsPeriodToStringAndBack() {
|
||||
assertThat(CONVERSION_SERVICE.convert(date.toString(), LocalDateTime.class)).isEqualTo(date);
|
||||
}
|
||||
|
||||
ResolvableType type = ResolvableType.forClass(ConversionTest.class, this.getClass());
|
||||
assertThat(CONVERSION_SERVICE.convert(target, String.class)).isEqualTo(string);
|
||||
assertThat(CONVERSION_SERVICE.convert(string, type.getGeneric(0).getRawClass())).isEqualTo(target);
|
||||
}
|
||||
@Test
|
||||
// DATACMNS-1440
|
||||
void convertsIsoFormattedStringToInstant() {
|
||||
|
||||
Instant date = Instant.now();
|
||||
|
||||
assertThat(CONVERSION_SERVICE.convert(date.toString(), Instant.class)).isEqualTo(date);
|
||||
}
|
||||
|
||||
private static Predicate<Date> formatted(Temporal expected, String format) {
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
||||
return d -> format(d, format).equals(formatter.format(expected));
|
||||
}
|
||||
|
||||
private static Predicate<Temporal> formatted(Date expected, String format) {
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
||||
return d -> formatter.format(d).equals(format(expected, format));
|
||||
}
|
||||
|
||||
private static String format(Date date, String format) {
|
||||
return new SimpleDateFormat(format).format(date);
|
||||
}
|
||||
|
||||
static Stream<Object[]> parameters() {
|
||||
|
||||
List<Object[]> duration = Arrays.asList(new Object[][] { //
|
||||
{ "PT240H", Duration.ofDays(10) }, //
|
||||
{ "PT2H", Duration.ofHours(2) }, //
|
||||
{ "PT3M", Duration.ofMinutes(3) }, //
|
||||
{ "PT4S", Duration.ofSeconds(4) }, //
|
||||
{ "PT0.005S", Duration.ofMillis(5) }, //
|
||||
{ "PT0.000000006S", Duration.ofNanos(6) } //
|
||||
});
|
||||
|
||||
List<Object[]> period = Arrays.asList(new Object[][] { //
|
||||
{ "P2D", Period.ofDays(2) }, //
|
||||
{ "P21D", Period.ofWeeks(3) }, //
|
||||
{ "P4M", Period.ofMonths(4) }, //
|
||||
{ "P5Y", Period.ofYears(5) }, //
|
||||
});
|
||||
|
||||
return Stream.concat(duration.stream(), period.stream());
|
||||
}
|
||||
|
||||
@ParameterizedTest // DATACMNS-951
|
||||
@MethodSource("parameters")
|
||||
void convertsPeriodToStringAndBack(String string, Object target) {
|
||||
|
||||
assertThat(CONVERSION_SERVICE.convert(target, String.class)).isEqualTo(string);
|
||||
assertThat(CONVERSION_SERVICE.convert(string, target.getClass())).isEqualTo(target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import static org.springframework.data.util.ClassTypeInformation.from;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.TypeAlias;
|
||||
import org.springframework.data.mapping.Alias;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
@@ -35,23 +35,23 @@ import org.springframework.data.util.ClassTypeInformation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class MappingContextTypeInformationMapperUnitTests {
|
||||
class MappingContextTypeInformationMapperUnitTests {
|
||||
|
||||
SampleMappingContext mappingContext;
|
||||
TypeInformationMapper mapper;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mappingContext = new SampleMappingContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNullMappingContext() {
|
||||
void rejectsNullMappingContext() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new MappingContextTypeInformationMapper(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractsAliasInfoFromMappingContext() {
|
||||
void extractsAliasInfoFromMappingContext() {
|
||||
|
||||
mappingContext.setInitialEntitySet(Collections.singleton(Entity.class));
|
||||
mappingContext.initialize();
|
||||
@@ -62,7 +62,7 @@ public class MappingContextTypeInformationMapperUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractsAliasForUnknownType() {
|
||||
void extractsAliasForUnknownType() {
|
||||
|
||||
SampleMappingContext mappingContext = new SampleMappingContext();
|
||||
mappingContext.initialize();
|
||||
@@ -73,7 +73,7 @@ public class MappingContextTypeInformationMapperUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotReturnTypeAliasForSimpleType() {
|
||||
void doesNotReturnTypeAliasForSimpleType() {
|
||||
|
||||
SampleMappingContext mappingContext = new SampleMappingContext();
|
||||
mappingContext.initialize();
|
||||
@@ -83,7 +83,7 @@ public class MappingContextTypeInformationMapperUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detectsTypeForUnknownEntity() {
|
||||
void detectsTypeForUnknownEntity() {
|
||||
|
||||
SampleMappingContext mappingContext = new SampleMappingContext();
|
||||
mappingContext.initialize();
|
||||
@@ -99,7 +99,7 @@ public class MappingContextTypeInformationMapperUnitTests {
|
||||
|
||||
@Test // DATACMNS-485
|
||||
@SuppressWarnings("unchecked")
|
||||
public void createsTypeMapperForGenericTypesWithDifferentBindings() {
|
||||
void createsTypeMapperForGenericTypesWithDifferentBindings() {
|
||||
|
||||
AnnotatedTypeScanner scanner = new AnnotatedTypeScanner(TypeAlias.class);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.convert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.mapping.Alias;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
@@ -27,12 +27,12 @@ import org.springframework.data.util.TypeInformation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimpleTypeInformationMapperUnitTests {
|
||||
class SimpleTypeInformationMapperUnitTests {
|
||||
|
||||
TypeInformationMapper mapper = new SimpleTypeInformationMapper();
|
||||
|
||||
@Test
|
||||
public void resolvesTypeByLoadingClass() {
|
||||
void resolvesTypeByLoadingClass() {
|
||||
|
||||
TypeInformation<?> type = mapper.resolveTypeFrom(Alias.of("java.lang.String"));
|
||||
|
||||
@@ -42,23 +42,23 @@ public class SimpleTypeInformationMapperUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullForNonStringKey() {
|
||||
void returnsNullForNonStringKey() {
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of(new Object()))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullForEmptyTypeKey() {
|
||||
void returnsNullForEmptyTypeKey() {
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of(""))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullForUnloadableClass() {
|
||||
void returnsNullForUnloadableClass() {
|
||||
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("Foo"))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesFullyQualifiedClassNameAsTypeKey() {
|
||||
void usesFullyQualifiedClassNameAsTypeKey() {
|
||||
|
||||
assertThat(mapper.createAliasFor(ClassTypeInformation.from(String.class)))
|
||||
.isEqualTo(Alias.of(String.class.getName()));
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
@@ -40,7 +40,7 @@ import org.threeten.bp.ZoneId;
|
||||
* @author Oliver Gierke
|
||||
* @since 1.10
|
||||
*/
|
||||
public class ThreeTenBackPortConvertersUnitTests {
|
||||
class ThreeTenBackPortConvertersUnitTests {
|
||||
|
||||
static final Date NOW = new Date();
|
||||
static final ConversionService CONVERSION_SERVICE;
|
||||
@@ -57,13 +57,13 @@ public class ThreeTenBackPortConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-606
|
||||
public void convertsDateToLocalDateTime() {
|
||||
void convertsDateToLocalDateTime() {
|
||||
assertThat(CONVERSION_SERVICE.convert(NOW, LocalDateTime.class).toString())
|
||||
.isEqualTo(format(NOW, "yyyy-MM-dd'T'HH:mm:ss.SSS"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-606
|
||||
public void convertsLocalDateTimeToDate() {
|
||||
void convertsLocalDateTimeToDate() {
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
assertThat(format(CONVERSION_SERVICE.convert(now, Date.class), "yyyy-MM-dd'T'HH:mm:ss.SSS"))
|
||||
@@ -71,45 +71,45 @@ public class ThreeTenBackPortConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-606
|
||||
public void convertsDateToLocalDate() {
|
||||
void convertsDateToLocalDate() {
|
||||
assertThat(CONVERSION_SERVICE.convert(NOW, LocalDate.class).toString()).isEqualTo(format(NOW, "yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-606
|
||||
public void convertsLocalDateToDate() {
|
||||
void convertsLocalDateToDate() {
|
||||
|
||||
LocalDate now = LocalDate.now();
|
||||
assertThat(format(CONVERSION_SERVICE.convert(now, Date.class), "yyyy-MM-dd")).isEqualTo(now.toString());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-606
|
||||
public void convertsDateToLocalTime() {
|
||||
void convertsDateToLocalTime() {
|
||||
assertThat(CONVERSION_SERVICE.convert(NOW, LocalTime.class).toString()).isEqualTo(format(NOW, "HH:mm:ss.SSS"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-606
|
||||
public void convertsLocalTimeToDate() {
|
||||
void convertsLocalTimeToDate() {
|
||||
|
||||
LocalTime now = LocalTime.now();
|
||||
assertThat(format(CONVERSION_SERVICE.convert(now, Date.class), "HH:mm:ss.SSS")).isEqualTo(now.toString());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-623
|
||||
public void convertsDateToInstant() {
|
||||
void convertsDateToInstant() {
|
||||
|
||||
Date now = new Date();
|
||||
assertThat(CONVERSION_SERVICE.convert(now, Instant.class)).isEqualTo(toInstant(now));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-623
|
||||
public void convertsInstantToDate() {
|
||||
void convertsInstantToDate() {
|
||||
|
||||
Date now = new Date();
|
||||
assertThat(CONVERSION_SERVICE.convert(toInstant(now), Date.class)).isEqualTo(now);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertsZoneIdToStringAndBack() {
|
||||
void convertsZoneIdToStringAndBack() {
|
||||
|
||||
Map<String, ZoneId> ids = new HashMap<>();
|
||||
ids.put("Europe/Berlin", ZoneId.of("Europe/Berlin"));
|
||||
|
||||
Reference in New Issue
Block a user