DATACMNS-1718 - Migrate tests to JUnit 5.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import org.springframework.data.web.ProxyingHandlerMethodArgumentResolverUnitTests;
|
||||
|
||||
/*
|
||||
* Copyright 2017-2020 the original author or authors.
|
||||
*
|
||||
@@ -18,6 +16,6 @@ import org.springframework.data.web.ProxyingHandlerMethodArgumentResolverUnitTes
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
* @see ProxyingHandlerMethodArgumentResolverUnitTests
|
||||
* @see org.springframework.data.web.ProxyingHandlerMethodArgumentResolverUnitTests
|
||||
*/
|
||||
public interface SampleInterface {}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data;
|
||||
import static de.schauderhaft.degraph.check.JCheck.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Jens Schauder
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.util.AnnotatedTypeScanner;
|
||||
|
||||
/**
|
||||
@@ -27,11 +27,11 @@ import org.springframework.data.util.AnnotatedTypeScanner;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class TypeAliasUnitTests {
|
||||
class TypeAliasUnitTests {
|
||||
|
||||
@Test // DATACMNS-547
|
||||
@SuppressWarnings("unchecked")
|
||||
public void scanningforAtPersistentFindsTypeAliasAnnotatedTypes() {
|
||||
void scanningforAtPersistentFindsTypeAliasAnnotatedTypes() {
|
||||
|
||||
AnnotatedTypeScanner scanner = new AnnotatedTypeScanner(Persistent.class);
|
||||
Set<Class<?>> types = scanner.findTypes(getClass().getPackage().getName());
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -31,7 +31,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Oliver Gierke
|
||||
* @since 1.5
|
||||
*/
|
||||
public class AnnotationAuditingMetadataUnitTests {
|
||||
class AnnotationAuditingMetadataUnitTests {
|
||||
|
||||
static final Field createdByField = ReflectionUtils.findField(AnnotatedUser.class, "createdBy");
|
||||
static final Field createdDateField = ReflectionUtils.findField(AnnotatedUser.class, "createdDate");
|
||||
@@ -39,7 +39,7 @@ public class AnnotationAuditingMetadataUnitTests {
|
||||
static final Field lastModifiedDateField = ReflectionUtils.findField(AnnotatedUser.class, "lastModifiedDate");
|
||||
|
||||
@Test
|
||||
public void checkAnnotationDiscovery() {
|
||||
void checkAnnotationDiscovery() {
|
||||
|
||||
AnnotationAuditingMetadata metadata = AnnotationAuditingMetadata.getMetadata(AnnotatedUser.class);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class AnnotationAuditingMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkCaching() {
|
||||
void checkCaching() {
|
||||
|
||||
AnnotationAuditingMetadata firstCall = AnnotationAuditingMetadata.getMetadata(AnnotatedUser.class);
|
||||
assertThat(firstCall).isNotNull();
|
||||
@@ -61,7 +61,7 @@ public class AnnotationAuditingMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkIsAuditable() {
|
||||
void checkIsAuditable() {
|
||||
|
||||
AnnotationAuditingMetadata metadata = AnnotationAuditingMetadata.getMetadata(AnnotatedUser.class);
|
||||
assertThat(metadata).isNotNull();
|
||||
@@ -73,7 +73,7 @@ public class AnnotationAuditingMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsInvalidDateTypeField() {
|
||||
void rejectsInvalidDateTypeField() {
|
||||
|
||||
class Sample {
|
||||
@CreatedDate String field;
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
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.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
@@ -39,15 +39,15 @@ import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class AuditingHandlerUnitTests {
|
||||
class AuditingHandlerUnitTests {
|
||||
|
||||
AuditingHandler handler;
|
||||
AuditorAware<AuditedUser> auditorAware;
|
||||
|
||||
AuditedUser user;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
handler = getHandler();
|
||||
user = new AuditedUser();
|
||||
@@ -64,7 +64,7 @@ public class AuditingHandlerUnitTests {
|
||||
* Checks that the advice does not set auditor on the target entity if no {@code AuditorAware} was configured.
|
||||
*/
|
||||
@Test
|
||||
public void doesNotSetAuditorIfNotConfigured() {
|
||||
void doesNotSetAuditorIfNotConfigured() {
|
||||
|
||||
handler.markCreated(user);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class AuditingHandlerUnitTests {
|
||||
* Checks that the advice sets the auditor on the target entity if an {@code AuditorAware} was configured.
|
||||
*/
|
||||
@Test
|
||||
public void setsAuditorIfConfigured() {
|
||||
void setsAuditorIfConfigured() {
|
||||
|
||||
handler.setAuditorAware(auditorAware);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class AuditingHandlerUnitTests {
|
||||
* Checks that the advice does not set modification information on creation if the falg is set to {@code false}.
|
||||
*/
|
||||
@Test
|
||||
public void honoursModifiedOnCreationFlag() {
|
||||
void honoursModifiedOnCreationFlag() {
|
||||
|
||||
handler.setAuditorAware(auditorAware);
|
||||
handler.setModifyOnCreation(false);
|
||||
@@ -117,7 +117,7 @@ public class AuditingHandlerUnitTests {
|
||||
* Tests that the advice only sets modification data if a not-new entity is handled.
|
||||
*/
|
||||
@Test
|
||||
public void onlySetsModificationDataOnNotNewEntities() {
|
||||
void onlySetsModificationDataOnNotNewEntities() {
|
||||
|
||||
AuditedUser audited = new AuditedUser();
|
||||
audited.id = 1L;
|
||||
@@ -135,7 +135,7 @@ public class AuditingHandlerUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotSetTimeIfConfigured() {
|
||||
void doesNotSetTimeIfConfigured() {
|
||||
|
||||
handler.setDateTimeForNow(false);
|
||||
handler.setAuditorAware(auditorAware);
|
||||
@@ -149,7 +149,7 @@ public class AuditingHandlerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAJPA-9
|
||||
public void usesDateTimeProviderIfConfigured() {
|
||||
void usesDateTimeProviderIfConfigured() {
|
||||
|
||||
DateTimeProvider provider = mock(DateTimeProvider.class);
|
||||
doReturn(Optional.empty()).when(provider).getNow();
|
||||
@@ -161,7 +161,7 @@ public class AuditingHandlerUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setsAuditingInfoOnEntityUsingInheritance() {
|
||||
void setsAuditingInfoOnEntityUsingInheritance() {
|
||||
|
||||
AuditingHandler handler = new AuditingHandler(PersistentEntities.of(new SampleMappingContext()));
|
||||
handler.setModifyOnCreation(false);
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
@@ -40,36 +40,36 @@ import org.springframework.data.auditing.DefaultAuditableBeanWrapperFactory.Refl
|
||||
* @author Jens Schauder
|
||||
* @since 1.5
|
||||
*/
|
||||
public class DefaultAuditableBeanWrapperFactoryUnitTests {
|
||||
class DefaultAuditableBeanWrapperFactoryUnitTests {
|
||||
|
||||
DefaultAuditableBeanWrapperFactory factory = new DefaultAuditableBeanWrapperFactory();
|
||||
|
||||
@Test
|
||||
public void rejectsNullSource() {
|
||||
void rejectsNullSource() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factory.getBeanWrapperFor(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsAuditableInterfaceBeanWrapperForAuditable() {
|
||||
void returnsAuditableInterfaceBeanWrapperForAuditable() {
|
||||
|
||||
assertThat(factory.getBeanWrapperFor(new AuditedUser()))
|
||||
.hasValueSatisfying(it -> assertThat(it).isInstanceOf(AuditableInterfaceBeanWrapper.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsReflectionAuditingBeanWrapperForNonAuditableButAnnotated() {
|
||||
void returnsReflectionAuditingBeanWrapperForNonAuditableButAnnotated() {
|
||||
|
||||
assertThat(factory.getBeanWrapperFor(new AnnotatedUser()))
|
||||
.hasValueSatisfying(it -> assertThat(it).isInstanceOf(ReflectionAuditingBeanWrapper.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsEmptyForNonAuditableType() {
|
||||
void returnsEmptyForNonAuditableType() {
|
||||
assertThat(factory.getBeanWrapperFor(new Object())).isNotPresent();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-643
|
||||
public void setsJsr310AndThreeTenBpTypes() {
|
||||
void setsJsr310AndThreeTenBpTypes() {
|
||||
|
||||
Jsr310ThreeTenBpAuditedUser user = new Jsr310ThreeTenBpAuditedUser();
|
||||
Instant instant = Instant.now();
|
||||
@@ -87,7 +87,7 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-867
|
||||
public void errorsWhenUnableToConvertDateViaIntermediateJavaUtilDateConversion() {
|
||||
void errorsWhenUnableToConvertDateViaIntermediateJavaUtilDateConversion() {
|
||||
|
||||
Jsr310ThreeTenBpAuditedUser user = new Jsr310ThreeTenBpAuditedUser();
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.now();
|
||||
@@ -101,7 +101,7 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1259
|
||||
public void lastModifiedDateAsLongIsAvailableViaWrapper() {
|
||||
void lastModifiedDateAsLongIsAvailableViaWrapper() {
|
||||
|
||||
LongBasedAuditable source = new LongBasedAuditable();
|
||||
source.dateModified = 42000L;
|
||||
@@ -114,7 +114,7 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1259
|
||||
public void canSetLastModifiedDateAsInstantViaWrapperOnLongField() {
|
||||
void canSetLastModifiedDateAsInstantViaWrapperOnLongField() {
|
||||
|
||||
LongBasedAuditable source = new LongBasedAuditable();
|
||||
|
||||
@@ -127,7 +127,7 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1259
|
||||
public void canSetLastModifiedDateAsLocalDateTimeViaWrapperOnLongField() {
|
||||
void canSetLastModifiedDateAsLocalDateTimeViaWrapperOnLongField() {
|
||||
|
||||
LongBasedAuditable source = new LongBasedAuditable();
|
||||
|
||||
@@ -140,7 +140,7 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1259
|
||||
public void lastModifiedAsLocalDateTimeDateIsAvailableViaWrapperAsLocalDateTime() {
|
||||
void lastModifiedAsLocalDateTimeDateIsAvailableViaWrapperAsLocalDateTime() {
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
|
||||
@@ -19,10 +19,12 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
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.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
@@ -34,13 +36,14 @@ import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
* @author Oliver Gierke
|
||||
* @since 1.5
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class IsNewAwareAuditingHandlerUnitTests extends AuditingHandlerUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class IsNewAwareAuditingHandlerUnitTests extends AuditingHandlerUnitTests {
|
||||
|
||||
SampleMappingContext mappingContext;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
@BeforeEach
|
||||
void init() {
|
||||
|
||||
this.mappingContext = new SampleMappingContext();
|
||||
this.mappingContext.getPersistentEntity(AuditedUser.class);
|
||||
@@ -53,7 +56,7 @@ public class IsNewAwareAuditingHandlerUnitTests extends AuditingHandlerUnitTests
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delegatesToMarkCreatedForNewEntity() {
|
||||
void delegatesToMarkCreatedForNewEntity() {
|
||||
|
||||
AuditedUser user = new AuditedUser();
|
||||
|
||||
@@ -64,7 +67,7 @@ public class IsNewAwareAuditingHandlerUnitTests extends AuditingHandlerUnitTests
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delegatesToMarkModifiedForNonNewEntity() {
|
||||
void delegatesToMarkModifiedForNonNewEntity() {
|
||||
|
||||
AuditedUser user = new AuditedUser();
|
||||
user.id = 1L;
|
||||
@@ -76,17 +79,17 @@ public class IsNewAwareAuditingHandlerUnitTests extends AuditingHandlerUnitTests
|
||||
}
|
||||
|
||||
@Test // DATACMNS-365
|
||||
public void rejectsNullMappingContext() {
|
||||
void rejectsNullMappingContext() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new IsNewAwareAuditingHandler((PersistentEntities) null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-365
|
||||
public void setsUpHandlerWithMappingContext() {
|
||||
void setsUpHandlerWithMappingContext() {
|
||||
new IsNewAwareAuditingHandler(PersistentEntities.of());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-638
|
||||
public void handlingOptionalIsANoOp() {
|
||||
void handlingOptionalIsANoOp() {
|
||||
|
||||
IsNewAwareAuditingHandler handler = getHandler();
|
||||
|
||||
@@ -96,7 +99,7 @@ public class IsNewAwareAuditingHandlerUnitTests extends AuditingHandlerUnitTests
|
||||
}
|
||||
|
||||
@Test // DATACMNS-957
|
||||
public void skipsEntityWithoutIdentifier() {
|
||||
void skipsEntityWithoutIdentifier() {
|
||||
getHandler().markAudited(Optional.of(new EntityWithoutId()));
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.data.annotation.LastModifiedDate;
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class Jsr310ThreeTenBpAuditedUser {
|
||||
class Jsr310ThreeTenBpAuditedUser {
|
||||
|
||||
@CreatedDate LocalDateTime createdDate;
|
||||
@LastModifiedDate org.threeten.bp.LocalDateTime lastModifiedDate;
|
||||
|
||||
@@ -33,8 +33,8 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.assertj.core.api.AbstractLongAssert;
|
||||
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.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
@@ -54,12 +54,12 @@ import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
* @author Jens Schauder
|
||||
* @since 1.8
|
||||
*/
|
||||
public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
|
||||
DefaultAuditableBeanWrapperFactory factory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
context.getPersistentEntity(Sample.class);
|
||||
@@ -71,7 +71,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-365
|
||||
public void discoversAuditingPropertyOnField() {
|
||||
void discoversAuditingPropertyOnField() {
|
||||
|
||||
Sample sample = new Sample();
|
||||
|
||||
@@ -85,7 +85,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-365
|
||||
public void discoversAuditingPropertyOnAccessor() {
|
||||
void discoversAuditingPropertyOnAccessor() {
|
||||
|
||||
Sample sample = new Sample();
|
||||
|
||||
@@ -99,7 +99,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-365
|
||||
public void settingInavailablePropertyIsNoop() {
|
||||
void settingInavailablePropertyIsNoop() {
|
||||
|
||||
Sample sample = new Sample();
|
||||
|
||||
@@ -109,19 +109,19 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-365
|
||||
public void doesNotReturnWrapperForEntityNotUsingAuditing() {
|
||||
void doesNotReturnWrapperForEntityNotUsingAuditing() {
|
||||
assertThat(factory.getBeanWrapperFor(new NoAuditing())).isNotPresent();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-365
|
||||
public void returnsAuditableWrapperForAuditable() {
|
||||
void returnsAuditableWrapperForAuditable() {
|
||||
|
||||
assertThat(factory.getBeanWrapperFor(mock(ExtendingAuditable.class)))
|
||||
.hasValueSatisfying(it -> assertThat(it).isInstanceOf(AuditableInterfaceBeanWrapper.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-638
|
||||
public void returnsLastModificationCalendarAsCalendar() {
|
||||
void returnsLastModificationCalendarAsCalendar() {
|
||||
|
||||
Date reference = new Date();
|
||||
|
||||
@@ -133,7 +133,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-638
|
||||
public void returnsLastModificationDateTimeAsCalendar() {
|
||||
void returnsLastModificationDateTimeAsCalendar() {
|
||||
|
||||
org.joda.time.LocalDateTime reference = new org.joda.time.LocalDateTime();
|
||||
|
||||
@@ -142,7 +142,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-638
|
||||
public void returnsLastModificationDateAsCalendar() {
|
||||
void returnsLastModificationDateAsCalendar() {
|
||||
|
||||
Date reference = new Date();
|
||||
|
||||
@@ -151,7 +151,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-638, DATACMNS-43
|
||||
public void returnsLastModificationJsr310DateTimeAsCalendar() {
|
||||
void returnsLastModificationJsr310DateTimeAsCalendar() {
|
||||
|
||||
LocalDateTime reference = LocalDateTime.now();
|
||||
|
||||
@@ -159,7 +159,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-638, DATACMNS-43
|
||||
public void returnsLastModificationThreeTenBpDateTimeAsCalendar() {
|
||||
void returnsLastModificationThreeTenBpDateTimeAsCalendar() {
|
||||
|
||||
org.threeten.bp.LocalDateTime reference = org.threeten.bp.LocalDateTime.now();
|
||||
|
||||
@@ -168,7 +168,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1109
|
||||
public void exposesInstantAsModificationDate() {
|
||||
void exposesInstantAsModificationDate() {
|
||||
|
||||
SampleWithInstant sample = new SampleWithInstant();
|
||||
sample.modified = Instant.now();
|
||||
@@ -180,7 +180,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1259
|
||||
public void exposesLongAsModificationDate() {
|
||||
void exposesLongAsModificationDate() {
|
||||
|
||||
Long reference = new Date().getTime();
|
||||
|
||||
@@ -188,7 +188,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1274
|
||||
public void writesNestedAuditingData() {
|
||||
void writesNestedAuditingData() {
|
||||
|
||||
WithEmbedded target = new WithEmbedded();
|
||||
target.embedded = new Embedded();
|
||||
@@ -217,7 +217,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1461, DATACMNS-1671
|
||||
public void skipsNullIntermediatesWhenSettingProperties() {
|
||||
void skipsNullIntermediatesWhenSettingProperties() {
|
||||
|
||||
WithEmbedded withEmbedded = new WithEmbedded();
|
||||
|
||||
@@ -228,7 +228,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1438
|
||||
public void skipsCollectionPropertiesWhenSettingProperties() {
|
||||
void skipsCollectionPropertiesWhenSettingProperties() {
|
||||
|
||||
WithEmbedded withEmbedded = new WithEmbedded();
|
||||
withEmbedded.embedded = new Embedded();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
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.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.auditing.DefaultAuditableBeanWrapperFactory.ReflectionAuditingBeanWrapper;
|
||||
@@ -34,7 +34,7 @@ import org.springframework.data.convert.Jsr310Converters.LocalDateTimeToDateConv
|
||||
* @author Oliver Gierke
|
||||
* @since 1.5
|
||||
*/
|
||||
public class ReflectionAuditingBeanWrapperUnitTests {
|
||||
class ReflectionAuditingBeanWrapperUnitTests {
|
||||
|
||||
AnnotationAuditingMetadata metadata;
|
||||
AnnotatedUser user;
|
||||
@@ -42,29 +42,29 @@ public class ReflectionAuditingBeanWrapperUnitTests {
|
||||
|
||||
LocalDateTime time = LocalDateTime.now();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.user = new AnnotatedUser();
|
||||
this.wrapper = new ReflectionAuditingBeanWrapper(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setsDateTimeFieldCorrectly() {
|
||||
void setsDateTimeFieldCorrectly() {
|
||||
|
||||
wrapper.setCreatedDate(time);
|
||||
assertThat(user.createdDate).isEqualTo(new DateTime(LocalDateTimeToDateConverter.INSTANCE.convert(time)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setsDateFieldCorrectly() {
|
||||
void setsDateFieldCorrectly() {
|
||||
|
||||
wrapper.setLastModifiedDate(time);
|
||||
assertThat(user.lastModifiedDate).isEqualTo(LocalDateTimeToDateConverter.INSTANCE.convert(time));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setsLongFieldCorrectly() {
|
||||
void setsLongFieldCorrectly() {
|
||||
|
||||
class Sample {
|
||||
|
||||
@@ -84,7 +84,7 @@ public class ReflectionAuditingBeanWrapperUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setsAuditorFieldsCorrectly() {
|
||||
void setsAuditorFieldsCorrectly() {
|
||||
|
||||
Object object = new Object();
|
||||
|
||||
|
||||
@@ -20,10 +20,11 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
@@ -38,13 +39,13 @@ import org.springframework.data.auditing.EnableAuditing;
|
||||
* @author Oliver Gierke
|
||||
* @author Francisco Soler
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AuditingBeanDefinitionRegistrarSupportUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AuditingBeanDefinitionRegistrarSupportUnitTests {
|
||||
|
||||
@Mock BeanDefinitionRegistry registry;
|
||||
|
||||
@Test // DATCMNS-389
|
||||
public void testRegisterBeanDefinitions() {
|
||||
void testRegisterBeanDefinitions() {
|
||||
|
||||
AuditingBeanDefinitionRegistrarSupport registrar = new DummyAuditingBeanDefinitionRegistrarSupport();
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfig.class);
|
||||
@@ -54,7 +55,7 @@ public class AuditingBeanDefinitionRegistrarSupportUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1453
|
||||
public void rejectsNullAnnotationMetadata() {
|
||||
void rejectsNullAnnotationMetadata() {
|
||||
|
||||
AuditingBeanDefinitionRegistrarSupport registrar = new DummyAuditingBeanDefinitionRegistrarSupport();
|
||||
|
||||
@@ -63,7 +64,7 @@ public class AuditingBeanDefinitionRegistrarSupportUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1453
|
||||
public void rejectsNullRegistry() {
|
||||
void rejectsNullRegistry() {
|
||||
|
||||
AuditingBeanDefinitionRegistrarSupport registrar = new DummyAuditingBeanDefinitionRegistrarSupport();
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfig.class);
|
||||
|
||||
@@ -22,11 +22,12 @@ import java.io.IOException;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
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.springframework.beans.factory.parsing.ReaderContext;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -35,6 +36,7 @@ import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.data.config.TypeFilterParser.Type;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
@@ -43,8 +45,8 @@ import org.xml.sax.SAXException;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TypeFilterParserUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class TypeFilterParserUnitTests {
|
||||
|
||||
TypeFilterParser parser;
|
||||
Element documentElement;
|
||||
@@ -54,8 +56,8 @@ public class TypeFilterParserUnitTests {
|
||||
|
||||
@Mock ClassPathScanningCandidateComponentProvider scanner;
|
||||
|
||||
@Before
|
||||
public void setUp() throws SAXException, IOException, ParserConfigurationException {
|
||||
@BeforeEach
|
||||
void setUp() throws SAXException, IOException, ParserConfigurationException {
|
||||
|
||||
parser = new TypeFilterParser(context, classLoader);
|
||||
|
||||
@@ -68,7 +70,7 @@ public class TypeFilterParserUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsesIncludesCorrectly() throws Exception {
|
||||
void parsesIncludesCorrectly() throws Exception {
|
||||
|
||||
Element element = DomUtils.getChildElementByTagName(documentElement, "firstSample");
|
||||
|
||||
@@ -77,7 +79,7 @@ public class TypeFilterParserUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsesExcludesCorrectly() throws Exception {
|
||||
void parsesExcludesCorrectly() throws Exception {
|
||||
|
||||
Element element = DomUtils.getChildElementByTagName(documentElement, "secondSample");
|
||||
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -17,17 +17,17 @@ package org.springframework.data.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractAggregateRoot}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class AbstractAggregateRootUnitTests {
|
||||
class AbstractAggregateRootUnitTests {
|
||||
|
||||
@Test // DATACMNS-928
|
||||
public void registersEvent() {
|
||||
void registersEvent() {
|
||||
|
||||
Object event = new Object();
|
||||
|
||||
@@ -38,7 +38,7 @@ public class AbstractAggregateRootUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-928
|
||||
public void clearsEvents() {
|
||||
void clearsEvents() {
|
||||
|
||||
Object event = new Object();
|
||||
|
||||
@@ -53,7 +53,7 @@ public class AbstractAggregateRootUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-928, DATACMNS-1162
|
||||
public void copiesEventsFromExistingAggregate() {
|
||||
void copiesEventsFromExistingAggregate() {
|
||||
|
||||
SampleAggregate aggregate = new SampleAggregate();
|
||||
aggregate.registerEvent(new Object());
|
||||
@@ -64,7 +64,7 @@ public class AbstractAggregateRootUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-928, DATACMNS-1162
|
||||
public void addsEventAndReturnsAggregate() {
|
||||
void addsEventAndReturnsAggregate() {
|
||||
|
||||
Object first = new Object();
|
||||
Object second = new Object();
|
||||
@@ -80,7 +80,7 @@ public class AbstractAggregateRootUnitTests {
|
||||
|
||||
@Test // DATACMNS-928, DATACMNS-1162
|
||||
@SuppressWarnings("null")
|
||||
public void rejectsNullEvent() {
|
||||
void rejectsNullEvent() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
.isThrownBy(() -> new SampleAggregate().andEvent(null));
|
||||
@@ -88,7 +88,7 @@ public class AbstractAggregateRootUnitTests {
|
||||
|
||||
@Test // DATACMNS-928
|
||||
@SuppressWarnings("null")
|
||||
public void rejectsNullEventForRegistration() {
|
||||
void rejectsNullEventForRegistration() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
.isThrownBy(() -> new SampleAggregate().registerEvent(null));
|
||||
@@ -96,7 +96,7 @@ public class AbstractAggregateRootUnitTests {
|
||||
|
||||
@Test // DATACMNS-928, DATACMNS-1162
|
||||
@SuppressWarnings("null")
|
||||
public void rejectsNullAggregate() {
|
||||
void rejectsNullAggregate() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
.isThrownBy(() -> new SampleAggregate().andEventsFrom(null));
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.domain;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.UnitTestUtils.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Thomas Darimont
|
||||
@@ -29,17 +29,17 @@ public abstract class AbstractPageRequestUnitTests {
|
||||
public abstract AbstractPageRequest newPageRequest(int page, int size);
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void preventsNegativePage() {
|
||||
void preventsNegativePage() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> newPageRequest(-1, 10));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void preventsNegativeSize() {
|
||||
void preventsNegativeSize() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> newPageRequest(0, -1));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void navigatesPageablesCorrectly() {
|
||||
void navigatesPageablesCorrectly() {
|
||||
|
||||
Pageable request = newPageRequest(1, 10);
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class AbstractPageRequestUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void equalsHonoursPageAndSize() {
|
||||
void equalsHonoursPageAndSize() {
|
||||
|
||||
AbstractPageRequest request = newPageRequest(0, 10);
|
||||
|
||||
@@ -73,12 +73,12 @@ public abstract class AbstractPageRequestUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-377
|
||||
public void preventsPageSizeLessThanOne() {
|
||||
void preventsPageSizeLessThanOne() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> newPageRequest(0, 0));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1327
|
||||
public void getOffsetShouldNotCauseOverflow() {
|
||||
void getOffsetShouldNotCauseOverflow() {
|
||||
|
||||
AbstractPageRequest request = newPageRequest(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.springframework.data.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
/**
|
||||
@@ -10,17 +10,17 @@ import org.springframework.data.domain.Sort.Direction;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class DirectionUnitTests {
|
||||
class DirectionUnitTests {
|
||||
|
||||
@Test
|
||||
public void jpaValueMapping() throws Exception {
|
||||
void jpaValueMapping() throws Exception {
|
||||
|
||||
assertThat(Direction.fromString("asc")).isEqualTo(Direction.ASC);
|
||||
assertThat(Direction.fromString("desc")).isEqualTo(Direction.DESC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsInvalidString() {
|
||||
void rejectsInvalidString() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Direction.fromString("foo"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.data.domain;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.ExampleMatcher.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit test for {@link ExampleMatcher}.
|
||||
@@ -28,43 +28,43 @@ import org.junit.Test;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack K2 - Der Berg Ruft (Club Mix)
|
||||
*/
|
||||
public class ExampleMatcherUnitTests {
|
||||
class ExampleMatcherUnitTests {
|
||||
|
||||
ExampleMatcher matcher;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
matcher = matching();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void defaultStringMatcherShouldReturnDefault() {
|
||||
void defaultStringMatcherShouldReturnDefault() {
|
||||
assertThat(matcher.getDefaultStringMatcher()).isEqualTo(StringMatcher.DEFAULT);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void ignoreCaseShouldReturnFalseByDefault() {
|
||||
void ignoreCaseShouldReturnFalseByDefault() {
|
||||
assertThat(matcher.isIgnoreCaseEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void ignoredPathsIsEmptyByDefault() {
|
||||
void ignoredPathsIsEmptyByDefault() {
|
||||
assertThat(matcher.getIgnoredPaths()).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void nullHandlerShouldReturnIgnoreByDefault() {
|
||||
void nullHandlerShouldReturnIgnoreByDefault() {
|
||||
assertThat(matcher.getNullHandler()).isEqualTo(NullHandler.IGNORE);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void ignoredPathsIsNotModifiable() {
|
||||
void ignoredPathsIsNotModifiable() {
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||
.isThrownBy(() -> matcher.getIgnoredPaths().add("¯\\_(ツ)_/¯"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void ignoreCaseShouldReturnTrueWhenIgnoreCaseEnabled() {
|
||||
void ignoreCaseShouldReturnTrueWhenIgnoreCaseEnabled() {
|
||||
|
||||
matcher = matching().withIgnoreCase();
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ExampleMatcherUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void ignoreCaseShouldReturnTrueWhenIgnoreCaseSet() {
|
||||
void ignoreCaseShouldReturnTrueWhenIgnoreCaseSet() {
|
||||
|
||||
matcher = matching().withIgnoreCase(true);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ExampleMatcherUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void nullHandlerShouldReturnInclude() {
|
||||
void nullHandlerShouldReturnInclude() {
|
||||
|
||||
matcher = matching().withIncludeNullValues();
|
||||
|
||||
@@ -88,7 +88,7 @@ public class ExampleMatcherUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void nullHandlerShouldReturnIgnore() {
|
||||
void nullHandlerShouldReturnIgnore() {
|
||||
|
||||
matcher = matching().withIgnoreNullValues();
|
||||
|
||||
@@ -96,7 +96,7 @@ public class ExampleMatcherUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void nullHandlerShouldReturnConfiguredValue() {
|
||||
void nullHandlerShouldReturnConfiguredValue() {
|
||||
|
||||
matcher = matching().withNullHandler(NullHandler.INCLUDE);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class ExampleMatcherUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void ignoredPathsShouldReturnCorrectProperties() {
|
||||
void ignoredPathsShouldReturnCorrectProperties() {
|
||||
|
||||
matcher = matching().withIgnorePaths("foo", "bar", "baz");
|
||||
|
||||
@@ -113,7 +113,7 @@ public class ExampleMatcherUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void ignoredPathsShouldReturnUniqueProperties() {
|
||||
void ignoredPathsShouldReturnUniqueProperties() {
|
||||
|
||||
matcher = matching().withIgnorePaths("foo", "bar", "foo");
|
||||
|
||||
@@ -122,7 +122,7 @@ public class ExampleMatcherUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void withCreatesNewInstance() {
|
||||
void withCreatesNewInstance() {
|
||||
|
||||
matcher = matching().withIgnorePaths("foo", "bar", "foo");
|
||||
ExampleMatcher configuredExampleSpec = matcher.withIgnoreCase();
|
||||
@@ -136,28 +136,28 @@ public class ExampleMatcherUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-879
|
||||
public void defaultMatcherRequiresAllMatching() {
|
||||
void defaultMatcherRequiresAllMatching() {
|
||||
|
||||
assertThat(matching().isAllMatching()).isTrue();
|
||||
assertThat(matching().isAnyMatching()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-879
|
||||
public void allMatcherRequiresAllMatching() {
|
||||
void allMatcherRequiresAllMatching() {
|
||||
|
||||
assertThat(matchingAll().isAllMatching()).isTrue();
|
||||
assertThat(matchingAll().isAnyMatching()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-879
|
||||
public void anyMatcherYieldsAnyMatching() {
|
||||
void anyMatcherYieldsAnyMatching() {
|
||||
|
||||
assertThat(matchingAny().isAnyMatching()).isTrue();
|
||||
assertThat(matchingAny().isAllMatching()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-900
|
||||
public void shouldCompareUsingHashCodeAndEquals() {
|
||||
void shouldCompareUsingHashCodeAndEquals() {
|
||||
|
||||
matcher = matching() //
|
||||
.withIgnorePaths("foo", "bar", "baz") //
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.data.domain;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.ExampleMatcher.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test for {@link Example}.
|
||||
@@ -28,13 +28,13 @@ import org.junit.Test;
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ExampleUnitTests {
|
||||
class ExampleUnitTests {
|
||||
|
||||
Person person;
|
||||
Example<Person> example;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
person = new Person();
|
||||
person.firstname = "rand";
|
||||
@@ -43,17 +43,17 @@ public class ExampleUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void rejectsNullProbe() {
|
||||
void rejectsNullProbe() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Example.of(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-810
|
||||
public void retunsSampleObjectsClassAsProbeType() {
|
||||
void retunsSampleObjectsClassAsProbeType() {
|
||||
assertThat(example.getProbeType()).isEqualTo(Person.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-900
|
||||
public void shouldCompareUsingHashCodeAndEquals() throws Exception {
|
||||
void shouldCompareUsingHashCodeAndEquals() throws Exception {
|
||||
|
||||
Example<Person> example = Example.of(person, matching().withIgnoreCase("firstname"));
|
||||
Example<Person> sameAsExample = Example.of(person, matching().withIgnoreCase("firstname"));
|
||||
|
||||
@@ -22,17 +22,17 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit test for {@link PageImpl}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class PageImplUnitTests {
|
||||
class PageImplUnitTests {
|
||||
|
||||
@Test
|
||||
public void assertEqualsForSimpleSetup() throws Exception {
|
||||
void assertEqualsForSimpleSetup() throws Exception {
|
||||
|
||||
PageImpl<String> page = new PageImpl<>(Collections.singletonList("Foo"));
|
||||
|
||||
@@ -41,7 +41,7 @@ public class PageImplUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertEqualsForComplexSetup() throws Exception {
|
||||
void assertEqualsForComplexSetup() throws Exception {
|
||||
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
List<String> content = Collections.singletonList("Foo");
|
||||
@@ -56,17 +56,17 @@ public class PageImplUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preventsNullContentForSimpleSetup() {
|
||||
void preventsNullContentForSimpleSetup() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new PageImpl<>(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preventsNullContentForAdvancedSetup() {
|
||||
void preventsNullContentForAdvancedSetup() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new PageImpl<>(null, null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNextPageable() {
|
||||
void returnsNextPageable() {
|
||||
|
||||
Page<Object> page = new PageImpl<>(Collections.singletonList(new Object()), PageRequest.of(0, 1), 10);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class PageImplUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsPreviousPageable() {
|
||||
void returnsPreviousPageable() {
|
||||
|
||||
Page<Object> page = new PageImpl<>(Collections.singletonList(new Object()), PageRequest.of(1, 1), 2);
|
||||
|
||||
@@ -94,7 +94,7 @@ public class PageImplUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createsPageForEmptyContentCorrectly() {
|
||||
void createsPageForEmptyContentCorrectly() {
|
||||
|
||||
List<String> list = Collections.emptyList();
|
||||
Page<String> page = new PageImpl<>(list);
|
||||
@@ -114,7 +114,7 @@ public class PageImplUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-323
|
||||
public void returnsCorrectTotalPages() {
|
||||
void returnsCorrectTotalPages() {
|
||||
|
||||
Page<String> page = new PageImpl<>(Collections.singletonList("a"));
|
||||
|
||||
@@ -124,7 +124,7 @@ public class PageImplUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-635
|
||||
public void transformsPageCorrectly() {
|
||||
void transformsPageCorrectly() {
|
||||
|
||||
Page<Integer> transformed = new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(0, 2), 10)
|
||||
.map(String::length);
|
||||
@@ -134,36 +134,36 @@ public class PageImplUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-713
|
||||
public void adaptsTotalForLastPageOnIntermediateDeletion() {
|
||||
void adaptsTotalForLastPageOnIntermediateDeletion() {
|
||||
assertThat(new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(0, 5), 3).getTotalElements()).isEqualTo(2L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-713
|
||||
public void adaptsTotalForLastPageOnIntermediateInsertion() {
|
||||
void adaptsTotalForLastPageOnIntermediateInsertion() {
|
||||
assertThat(new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(0, 5), 1).getTotalElements()).isEqualTo(2L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-713
|
||||
public void adaptsTotalForLastPageOnIntermediateDeletionOnLastPate() {
|
||||
void adaptsTotalForLastPageOnIntermediateDeletionOnLastPate() {
|
||||
assertThat(new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(1, 10), 13).getTotalElements())
|
||||
.isEqualTo(12L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-713
|
||||
public void adaptsTotalForLastPageOnIntermediateInsertionOnLastPate() {
|
||||
void adaptsTotalForLastPageOnIntermediateInsertionOnLastPate() {
|
||||
assertThat(new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(1, 10), 11).getTotalElements())
|
||||
.isEqualTo(12L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-713
|
||||
public void doesNotAdapttotalIfPageIsEmpty() {
|
||||
void doesNotAdapttotalIfPageIsEmpty() {
|
||||
|
||||
assertThat(new PageImpl<>(Collections.<String> emptyList(), PageRequest.of(1, 10), 0).getTotalElements())
|
||||
.isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1476
|
||||
public void returnsSelfPagablesIfThePageIsAlreadyTheFirstOrLastOne() {
|
||||
void returnsSelfPagablesIfThePageIsAlreadyTheFirstOrLastOne() {
|
||||
|
||||
Pageable pageable = PageRequest.of(0, 2);
|
||||
Slice<String> page = new PageImpl<>(Arrays.asList("foo", "bar"), pageable, 2);
|
||||
@@ -176,7 +176,7 @@ public class PageImplUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1613
|
||||
public void usesContentLengthForSizeIfNoPageableGiven() {
|
||||
void usesContentLengthForSizeIfNoPageableGiven() {
|
||||
|
||||
Page<Integer> page = new PageImpl<>(Arrays.asList(1, 2));
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.domain;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.UnitTestUtils.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ import org.springframework.data.domain.Sort.Direction;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class PageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
class PageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -37,12 +37,12 @@ public class PageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
return PageRequest.of(page, size);
|
||||
}
|
||||
|
||||
public AbstractPageRequest newPageRequest(int page, int size, Sort sort) {
|
||||
AbstractPageRequest newPageRequest(int page, int size, Sort sort) {
|
||||
return PageRequest.of(page, size, sort);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsRegardsSortCorrectly() {
|
||||
void equalsRegardsSortCorrectly() {
|
||||
|
||||
Sort sort = Sort.by(Direction.DESC, "foo");
|
||||
AbstractPageRequest request = PageRequest.of(0, 10, sort);
|
||||
@@ -64,7 +64,7 @@ public class PageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1581
|
||||
public void rejectsNullSort() {
|
||||
void rejectsNullSort() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
.isThrownBy(() -> PageRequest.of(0, 10, null));
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.domain.Range.Bound;
|
||||
|
||||
@@ -28,16 +28,16 @@ import org.springframework.data.domain.Range.Bound;
|
||||
* @author Mark Paluch
|
||||
* @since 1.10
|
||||
*/
|
||||
public class RangeUnitTests {
|
||||
class RangeUnitTests {
|
||||
|
||||
@Test // DATACMNS-651
|
||||
public void rejectsNullReferenceValuesForContains() {
|
||||
void rejectsNullReferenceValuesForContains() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> Range.from(Bound.inclusive(10L)).to(Bound.inclusive(20L)).contains(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-651
|
||||
public void excludesLowerBoundIfConfigured() {
|
||||
void excludesLowerBoundIfConfigured() {
|
||||
|
||||
Range<Long> range = Range.from(Bound.exclusive(10L)).to(Bound.inclusive(20L));
|
||||
|
||||
@@ -49,7 +49,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-651
|
||||
public void excludesUpperBoundIfConfigured() {
|
||||
void excludesUpperBoundIfConfigured() {
|
||||
|
||||
Range<Long> range = Range.of(Bound.inclusive(10L), Bound.exclusive(20L));
|
||||
|
||||
@@ -61,7 +61,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-651, DATACMNS-1050
|
||||
public void handlesOpenUpperBoundCorrectly() {
|
||||
void handlesOpenUpperBoundCorrectly() {
|
||||
|
||||
Range<Long> range = Range.of(Bound.inclusive(10L), Bound.unbounded());
|
||||
|
||||
@@ -76,7 +76,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-651, DATACMNS-1050
|
||||
public void handlesOpenLowerBoundCorrectly() {
|
||||
void handlesOpenLowerBoundCorrectly() {
|
||||
|
||||
Range<Long> range = Range.of(Bound.unbounded(), Bound.inclusive(20L));
|
||||
|
||||
@@ -90,7 +90,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1050
|
||||
public void createsInclusiveBoundaryCorrectly() {
|
||||
void createsInclusiveBoundaryCorrectly() {
|
||||
|
||||
Bound<Integer> bound = Bound.inclusive(10);
|
||||
|
||||
@@ -99,7 +99,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1050
|
||||
public void createsExclusiveBoundaryCorrectly() {
|
||||
void createsExclusiveBoundaryCorrectly() {
|
||||
|
||||
Bound<Double> bound = Bound.exclusive(10d);
|
||||
|
||||
@@ -108,7 +108,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1050
|
||||
public void createsRangeFromBoundariesCorrectly() {
|
||||
void createsRangeFromBoundariesCorrectly() {
|
||||
|
||||
Bound<Long> lower = Bound.inclusive(10L);
|
||||
Bound<Long> upper = Bound.inclusive(20L);
|
||||
@@ -122,7 +122,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1050
|
||||
public void shouldExclusiveBuildRangeLowerFirst() {
|
||||
void shouldExclusiveBuildRangeLowerFirst() {
|
||||
|
||||
Range<Long> range = Range.from(Bound.exclusive(10L)).to(Bound.exclusive(20L));
|
||||
|
||||
@@ -136,7 +136,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1050
|
||||
public void shouldBuildRange() {
|
||||
void shouldBuildRange() {
|
||||
|
||||
Range<Long> range = Range.from(Bound.inclusive(10L)).to(Bound.inclusive(20L));
|
||||
|
||||
@@ -150,7 +150,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1050
|
||||
public void createsUnboundedRange() {
|
||||
void createsUnboundedRange() {
|
||||
|
||||
Range<Long> range = Range.unbounded();
|
||||
|
||||
@@ -160,7 +160,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1499
|
||||
public void createsOpenRange() {
|
||||
void createsOpenRange() {
|
||||
|
||||
Range<Long> range = Range.open(5L, 10L);
|
||||
|
||||
@@ -169,7 +169,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1499
|
||||
public void createsClosedRange() {
|
||||
void createsClosedRange() {
|
||||
|
||||
Range<Long> range = Range.closed(5L, 10L);
|
||||
|
||||
@@ -178,7 +178,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1499
|
||||
public void createsLeftOpenRange() {
|
||||
void createsLeftOpenRange() {
|
||||
|
||||
Range<Long> range = Range.leftOpen(5L, 10L);
|
||||
|
||||
@@ -187,7 +187,7 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1499
|
||||
public void createsRightOpenRange() {
|
||||
void createsRightOpenRange() {
|
||||
|
||||
Range<Long> range = Range.rightOpen(5L, 10L);
|
||||
|
||||
@@ -196,17 +196,17 @@ public class RangeUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1499
|
||||
public void createsLeftUnboundedRange() {
|
||||
void createsLeftUnboundedRange() {
|
||||
assertThat(Range.leftUnbounded(Bound.inclusive(10L)).contains(-10000L)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1499
|
||||
public void createsRightUnboundedRange() {
|
||||
void createsRightUnboundedRange() {
|
||||
assertThat(Range.rightUnbounded(Bound.inclusive(10L)).contains(10000L)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1499
|
||||
public void createsSingleValueRange() {
|
||||
void createsSingleValueRange() {
|
||||
assertThat(Range.just(10L).contains(10L)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import lombok.Getter;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.data.domain.Sort.Order;
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SortUnitTests {
|
||||
class SortUnitTests {
|
||||
|
||||
/**
|
||||
* Asserts that the class applies the default sort order if no order or {@code null} was provided.
|
||||
@@ -42,7 +42,7 @@ public class SortUnitTests {
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void appliesDefaultForOrder() {
|
||||
void appliesDefaultForOrder() {
|
||||
assertThat(Sort.by("foo").iterator().next().getDirection()).isEqualTo(Sort.DEFAULT_DIRECTION);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class SortUnitTests {
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("null")
|
||||
public void preventsNullProperties() {
|
||||
void preventsNullProperties() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Sort.by(Direction.ASC, (String[]) null));
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class SortUnitTests {
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void preventsNullProperty() {
|
||||
void preventsNullProperty() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Sort.by(Direction.ASC, (String) null));
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class SortUnitTests {
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void preventsEmptyProperty() {
|
||||
void preventsEmptyProperty() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Sort.by(Direction.ASC, ""));
|
||||
}
|
||||
|
||||
@@ -83,19 +83,19 @@ public class SortUnitTests {
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void preventsNoProperties() {
|
||||
void preventsNoProperties() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Sort.by(Direction.ASC));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowsCombiningSorts() {
|
||||
void allowsCombiningSorts() {
|
||||
|
||||
Sort sort = Sort.by("foo").and(Sort.by("bar"));
|
||||
assertThat(sort).containsExactly(Order.by("foo"), Order.by("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesAdditionalNullSort() {
|
||||
void handlesAdditionalNullSort() {
|
||||
|
||||
Sort sort = Sort.by("foo").and(Sort.unsorted());
|
||||
|
||||
@@ -103,12 +103,12 @@ public class SortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-281, DATACMNS-1021
|
||||
public void configuresIgnoreCaseForOrder() {
|
||||
void configuresIgnoreCaseForOrder() {
|
||||
assertThat(Order.asc("foo").ignoreCase().isIgnoreCase()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-281, DATACMNS-1021
|
||||
public void orderDoesNotIgnoreCaseByDefault() {
|
||||
void orderDoesNotIgnoreCaseByDefault() {
|
||||
|
||||
assertThat(Order.by("foo").isIgnoreCase()).isFalse();
|
||||
assertThat(Order.asc("foo").isIgnoreCase()).isFalse();
|
||||
@@ -116,14 +116,14 @@ public class SortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1021
|
||||
public void createsOrderWithDirection() {
|
||||
void createsOrderWithDirection() {
|
||||
|
||||
assertThat(Order.asc("foo").getDirection()).isEqualTo(Direction.ASC);
|
||||
assertThat(Order.desc("foo").getDirection()).isEqualTo(Direction.DESC);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-436
|
||||
public void ordersWithDifferentIgnoreCaseDoNotEqual() {
|
||||
void ordersWithDifferentIgnoreCaseDoNotEqual() {
|
||||
|
||||
Order foo = Order.by("foo");
|
||||
Order fooIgnoreCase = Order.by("foo").ignoreCase();
|
||||
@@ -133,27 +133,27 @@ public class SortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-491
|
||||
public void orderWithNullHandlingHintNullsFirst() {
|
||||
void orderWithNullHandlingHintNullsFirst() {
|
||||
assertThat(Order.by("foo").nullsFirst().getNullHandling()).isEqualTo(NULLS_FIRST);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-491
|
||||
public void orderWithNullHandlingHintNullsLast() {
|
||||
void orderWithNullHandlingHintNullsLast() {
|
||||
assertThat(Order.by("foo").nullsLast().getNullHandling()).isEqualTo(NULLS_LAST);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-491
|
||||
public void orderWithNullHandlingHintNullsNative() {
|
||||
void orderWithNullHandlingHintNullsNative() {
|
||||
assertThat(Order.by("foo").nullsNative().getNullHandling()).isEqualTo(NATIVE);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-491
|
||||
public void orderWithDefaultNullHandlingHint() {
|
||||
void orderWithDefaultNullHandlingHint() {
|
||||
assertThat(Order.by("foo").getNullHandling()).isEqualTo(NATIVE);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-908
|
||||
public void createsNewOrderForDifferentProperty() {
|
||||
void createsNewOrderForDifferentProperty() {
|
||||
|
||||
Order source = Order.desc("foo").nullsFirst().ignoreCase();
|
||||
Order result = source.withProperty("bar");
|
||||
@@ -166,7 +166,7 @@ public class SortUnitTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("null")
|
||||
public void preventsNullDirection() {
|
||||
void preventsNullDirection() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)//
|
||||
.isThrownBy(() -> Sort.by((Direction) null, "foo"))//
|
||||
@@ -174,7 +174,7 @@ public class SortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1450
|
||||
public void translatesTypedSortCorrectly() {
|
||||
void translatesTypedSortCorrectly() {
|
||||
|
||||
assertThat(Sort.sort(Sample.class).by(Sample::getNested).by(Nested::getFirstname)) //
|
||||
.containsExactly(Order.by("nested.firstname"));
|
||||
|
||||
@@ -5,7 +5,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public abstract class UnitTestUtils {
|
||||
abstract class UnitTestUtils {
|
||||
|
||||
private UnitTestUtils() {
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class UnitTestUtils {
|
||||
* @param first
|
||||
* @param second
|
||||
*/
|
||||
public static void assertEqualsAndHashcode(Object first, Object second) {
|
||||
static void assertEqualsAndHashcode(Object first, Object second) {
|
||||
|
||||
assertThat(first).isEqualTo(second);
|
||||
assertThat(second).isEqualTo(first);
|
||||
@@ -30,7 +30,7 @@ public abstract class UnitTestUtils {
|
||||
* @param first
|
||||
* @param second
|
||||
*/
|
||||
public static void assertNotEqualsAndHashcode(Object first, Object second) {
|
||||
static void assertNotEqualsAndHashcode(Object first, Object second) {
|
||||
|
||||
assertThat(first).isNotEqualTo(second);
|
||||
assertThat(second).isNotEqualTo(first);
|
||||
|
||||
@@ -35,8 +35,8 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -53,7 +53,7 @@ import org.springframework.hateoas.Link;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SpringDataJaxbUnitTests {
|
||||
class SpringDataJaxbUnitTests {
|
||||
|
||||
Marshaller marshaller;
|
||||
Unmarshaller unmarshaller;
|
||||
@@ -65,8 +65,8 @@ public class SpringDataJaxbUnitTests {
|
||||
|
||||
String reference = readFile(resource);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
|
||||
JAXBContext context = JAXBContext.newInstance("org.springframework.data.domain.jaxb");
|
||||
|
||||
@@ -77,7 +77,7 @@ public class SpringDataJaxbUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesCustomTypeAdapterForPageRequests() throws Exception {
|
||||
void usesCustomTypeAdapterForPageRequests() throws Exception {
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
Wrapper wrapper = new Wrapper();
|
||||
@@ -90,7 +90,7 @@ public class SpringDataJaxbUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readsPageRequest() throws Exception {
|
||||
void readsPageRequest() throws Exception {
|
||||
|
||||
Object result = unmarshaller.unmarshal(resource.getFile());
|
||||
|
||||
@@ -100,7 +100,7 @@ public class SpringDataJaxbUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writesPlainPage() throws Exception {
|
||||
void writesPlainPage() throws Exception {
|
||||
|
||||
PageWrapper wrapper = new PageWrapper();
|
||||
Content content = new Content();
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.geo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
@@ -26,14 +26,14 @@ import org.springframework.util.SerializationUtils;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class BoxUnitTests {
|
||||
class BoxUnitTests {
|
||||
|
||||
Box first = new Box(new Point(1d, 1d), new Point(2d, 2d));
|
||||
Box second = new Box(new Point(1d, 1d), new Point(2d, 2d));
|
||||
Box third = new Box(new Point(3d, 3d), new Point(1d, 1d));
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void equalsWorksCorrectly() {
|
||||
void equalsWorksCorrectly() {
|
||||
|
||||
assertThat(first.equals(second)).isTrue();
|
||||
assertThat(second.equals(first)).isTrue();
|
||||
@@ -41,20 +41,20 @@ public class BoxUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void hashCodeWorksCorrectly() {
|
||||
void hashCodeWorksCorrectly() {
|
||||
|
||||
assertThat(first.hashCode()).isEqualTo(second.hashCode());
|
||||
assertThat(first.hashCode()).isNotEqualTo(third.hashCode());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void testToString() {
|
||||
void testToString() {
|
||||
|
||||
assertThat(first.toString()).isEqualTo("Box [Point [x=1.000000, y=1.000000], Point [x=2.000000, y=2.000000]]");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-482
|
||||
public void testSerialization() {
|
||||
void testSerialization() {
|
||||
|
||||
Box serialized = (Box) SerializationUtils.deserialize(SerializationUtils.serialize(first));
|
||||
assertThat(serialized).isEqualTo(first);
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.geo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
@@ -26,20 +26,20 @@ import org.springframework.util.SerializationUtils;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class CircleUnitTests {
|
||||
class CircleUnitTests {
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void rejectsNullOrigin() {
|
||||
void rejectsNullOrigin() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Circle(null, new Distance(0)));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void rejectsNegativeRadius() {
|
||||
void rejectsNegativeRadius() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Circle(1, 1, -1));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void considersTwoCirclesEqualCorrectly() {
|
||||
void considersTwoCirclesEqualCorrectly() {
|
||||
|
||||
Circle left = new Circle(1, 1, 1);
|
||||
Circle right = new Circle(1, 1, 1);
|
||||
@@ -54,13 +54,13 @@ public class CircleUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void testToString() {
|
||||
void testToString() {
|
||||
|
||||
assertThat(new Circle(1, 1, 1).toString()).isEqualTo("Circle: [center=Point [x=1.000000, y=1.000000], radius=1.0]");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-482
|
||||
public void testSerialization() {
|
||||
void testSerialization() {
|
||||
|
||||
Circle circle = new Circle(1, 1, 1);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.geo.Metrics.*;
|
||||
|
||||
import org.assertj.core.data.Offset;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.domain.Range.Bound;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
@@ -31,19 +31,19 @@ import org.springframework.util.SerializationUtils;
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class DistanceUnitTests {
|
||||
class DistanceUnitTests {
|
||||
|
||||
private static final Offset<Double> EPS = Offset.offset(0.000000001);
|
||||
private static final double TEN_MILES_NORMALIZED = 0.002523219294755161;
|
||||
private static final double TEN_KM_NORMALIZED = 0.001567855942887398;
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void defaultsMetricToNeutralOne() {
|
||||
void defaultsMetricToNeutralOne() {
|
||||
assertThat(new Distance(2.5).getMetric()).isEqualTo((Metric) Metrics.NEUTRAL);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void addsDistancesWithoutExplicitMetric() {
|
||||
void addsDistancesWithoutExplicitMetric() {
|
||||
|
||||
Distance left = new Distance(2.5, KILOMETERS);
|
||||
Distance right = new Distance(2.5, KILOMETERS);
|
||||
@@ -52,7 +52,7 @@ public class DistanceUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void addsDistancesWithExplicitMetric() {
|
||||
void addsDistancesWithExplicitMetric() {
|
||||
|
||||
Distance left = new Distance(2.5, KILOMETERS);
|
||||
Distance right = new Distance(2.5, KILOMETERS);
|
||||
@@ -61,7 +61,7 @@ public class DistanceUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-474
|
||||
public void distanceWithSameMetricShoudEqualAfterConversion() {
|
||||
void distanceWithSameMetricShoudEqualAfterConversion() {
|
||||
|
||||
assertThat(new Distance(1).in(NEUTRAL)).isEqualTo(new Distance(1));
|
||||
assertThat(new Distance(TEN_KM_NORMALIZED).in(KILOMETERS)).isEqualTo(new Distance(10, KILOMETERS));
|
||||
@@ -69,14 +69,14 @@ public class DistanceUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-474
|
||||
public void distanceWithDifferentMetricShoudEqualAfterConversion() {
|
||||
void distanceWithDifferentMetricShoudEqualAfterConversion() {
|
||||
|
||||
assertThat(new Distance(10, MILES)).isEqualTo(new Distance(TEN_MILES_NORMALIZED).in(MILES));
|
||||
assertThat(new Distance(10, KILOMETERS)).isEqualTo(new Distance(TEN_KM_NORMALIZED).in(KILOMETERS));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-474
|
||||
public void conversionShouldProduceCorrectNormalizedValue() {
|
||||
void conversionShouldProduceCorrectNormalizedValue() {
|
||||
|
||||
assertThat(new Distance(TEN_KM_NORMALIZED, NEUTRAL).in(KILOMETERS).getNormalizedValue())
|
||||
.isCloseTo(new Distance(10, KILOMETERS).getNormalizedValue(), EPS);
|
||||
@@ -98,7 +98,7 @@ public class DistanceUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-474
|
||||
public void toStringAfterConversion() {
|
||||
void toStringAfterConversion() {
|
||||
|
||||
assertThat(new Distance(10, KILOMETERS).in(MILES).toString())
|
||||
.isEqualTo(new Distance(6.21371256214785, MILES).toString());
|
||||
@@ -107,7 +107,7 @@ public class DistanceUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-482
|
||||
public void testSerialization() {
|
||||
void testSerialization() {
|
||||
|
||||
Distance dist = new Distance(10, KILOMETERS);
|
||||
|
||||
@@ -116,12 +116,12 @@ public class DistanceUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-626
|
||||
public void returnsMetricsAbbreviationAsUnit() {
|
||||
void returnsMetricsAbbreviationAsUnit() {
|
||||
assertThat(new Distance(10, KILOMETERS).getUnit()).isEqualTo("km");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-651
|
||||
public void createsARangeCorrectly() {
|
||||
void createsARangeCorrectly() {
|
||||
|
||||
Distance twoKilometers = new Distance(2, KILOMETERS);
|
||||
Distance tenKilometers = new Distance(10, KILOMETERS);
|
||||
@@ -134,7 +134,7 @@ public class DistanceUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-651
|
||||
public void createsARangeFromPiecesCorrectly() {
|
||||
void createsARangeFromPiecesCorrectly() {
|
||||
|
||||
Distance twoKilometers = new Distance(2, KILOMETERS);
|
||||
Distance tenKilometers = new Distance(10, KILOMETERS);
|
||||
@@ -147,7 +147,7 @@ public class DistanceUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-651
|
||||
public void implementsComparableCorrectly() {
|
||||
void implementsComparableCorrectly() {
|
||||
|
||||
Distance twoKilometers = new Distance(2, KILOMETERS);
|
||||
Distance tenKilometers = new Distance(10, KILOMETERS);
|
||||
|
||||
@@ -17,8 +17,8 @@ package org.springframework.data.geo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@@ -27,19 +27,19 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class GeoModuleIntegrationTests {
|
||||
class GeoModuleIntegrationTests {
|
||||
|
||||
ObjectMapper mapper;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.mapper = new ObjectMapper();
|
||||
this.mapper.registerModule(new GeoModule());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-475
|
||||
public void deserializesDistance() throws Exception {
|
||||
void deserializesDistance() throws Exception {
|
||||
|
||||
String json = "{\"value\":10.0,\"metric\":\"KILOMETERS\"}";
|
||||
Distance reference = new Distance(10.0, Metrics.KILOMETERS);
|
||||
@@ -49,7 +49,7 @@ public class GeoModuleIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-475
|
||||
public void deserializesPoint() throws Exception {
|
||||
void deserializesPoint() throws Exception {
|
||||
|
||||
String json = "{\"x\":10.0,\"y\":20.0}";
|
||||
Point reference = new Point(10.0, 20.0);
|
||||
@@ -59,7 +59,7 @@ public class GeoModuleIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-475
|
||||
public void deserializesCircle() throws Exception {
|
||||
void deserializesCircle() throws Exception {
|
||||
|
||||
String json = "{\"center\":{\"x\":10.0,\"y\":20.0},\"radius\":{\"value\":10.0,\"metric\":\"KILOMETERS\"}}";
|
||||
Circle reference = new Circle(new Point(10.0, 20.0), new Distance(10, Metrics.KILOMETERS));
|
||||
@@ -69,7 +69,7 @@ public class GeoModuleIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-475
|
||||
public void deserializesBox() throws Exception {
|
||||
void deserializesBox() throws Exception {
|
||||
|
||||
String json = "{\"first\":{\"x\":1.0,\"y\":2.0},\"second\":{\"x\":2.0,\"y\":3.0}}";
|
||||
Box reference = new Box(new Point(1, 2), new Point(2, 3));
|
||||
@@ -79,7 +79,7 @@ public class GeoModuleIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-475
|
||||
public void deserializesPolygon() throws Exception {
|
||||
void deserializesPolygon() throws Exception {
|
||||
|
||||
String json = "{\"points\":[{\"x\":1.0,\"y\":2.0},{\"x\":2.0,\"y\":3.0},{\"x\":3.0,\"y\":4.0}]}";
|
||||
Polygon reference = new Polygon(new Point(1, 2), new Point(2, 3), new Point(3, 4));
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.geo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ import org.springframework.util.SerializationUtils;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class GeoResultUnitTests {
|
||||
class GeoResultUnitTests {
|
||||
|
||||
GeoResult<String> first = new GeoResult<>("Foo", new Distance(2.5));
|
||||
GeoResult<String> second = new GeoResult<>("Foo", new Distance(2.5));
|
||||
@@ -34,13 +34,13 @@ public class GeoResultUnitTests {
|
||||
GeoResult<String> fourth = new GeoResult<>("Foo", new Distance(5.2));
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void considersSameInstanceEqual() {
|
||||
void considersSameInstanceEqual() {
|
||||
|
||||
assertThat(first.equals(first)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void considersSameValuesAsEqual() {
|
||||
void considersSameValuesAsEqual() {
|
||||
|
||||
assertThat(first.equals(second)).isTrue();
|
||||
assertThat(second.equals(first)).isTrue();
|
||||
@@ -53,12 +53,12 @@ public class GeoResultUnitTests {
|
||||
@Test
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
// DATACMNS-437
|
||||
public void rejectsNullContent() {
|
||||
void rejectsNullContent() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new GeoResult(null, new Distance(2.5)));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-482
|
||||
public void testSerialization() {
|
||||
void testSerialization() {
|
||||
|
||||
GeoResult<String> result = new GeoResult<>("test", new Distance(2));
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
@@ -29,11 +29,11 @@ import org.springframework.util.SerializationUtils;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class GeoResultsUnitTests {
|
||||
class GeoResultsUnitTests {
|
||||
|
||||
@Test // DATACMNS-437
|
||||
@SuppressWarnings("unchecked")
|
||||
public void calculatesAverageForGivenGeoResults() {
|
||||
void calculatesAverageForGivenGeoResults() {
|
||||
|
||||
GeoResult<Object> first = new GeoResult<>(new Object(), new Distance(2));
|
||||
GeoResult<Object> second = new GeoResult<>(new Object(), new Distance(5));
|
||||
@@ -43,7 +43,7 @@ public class GeoResultsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-482
|
||||
public void testSerialization() {
|
||||
void testSerialization() {
|
||||
|
||||
GeoResult<String> result = new GeoResult<>("test", new Distance(2));
|
||||
GeoResults<String> geoResults = new GeoResults<>(Collections.singletonList(result));
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.geo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
@@ -26,15 +26,15 @@ import org.springframework.util.SerializationUtils;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class PointUnitTests {
|
||||
class PointUnitTests {
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void rejectsNullforCopyConstructor() {
|
||||
void rejectsNullforCopyConstructor() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Point(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void equalsIsImplementedCorrectly() {
|
||||
void equalsIsImplementedCorrectly() {
|
||||
|
||||
assertThat(new Point(1.5, 1.5)).isEqualTo(new Point(1.5, 1.5));
|
||||
assertThat(new Point(1.5, 1.5)).isNotEqualTo(new Point(2.0, 2.0));
|
||||
@@ -42,12 +42,12 @@ public class PointUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void invokingToStringWorksCorrectly() {
|
||||
void invokingToStringWorksCorrectly() {
|
||||
assertThat(new Point(1.5, 1.5).toString()).isEqualTo("Point [x=1.500000, y=1.500000]");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-482
|
||||
public void testSerialization() {
|
||||
void testSerialization() {
|
||||
|
||||
Point point = new Point(1.5, 1.5);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.geo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
@@ -26,19 +26,19 @@ import org.springframework.util.SerializationUtils;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class PolygonUnitTests {
|
||||
class PolygonUnitTests {
|
||||
|
||||
Point first = new Point(1, 1);
|
||||
Point second = new Point(2, 2);
|
||||
Point third = new Point(3, 3);
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void rejectsNullPoints() {
|
||||
void rejectsNullPoints() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Polygon(null, null, null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void createsSimplePolygon() {
|
||||
void createsSimplePolygon() {
|
||||
|
||||
Polygon polygon = new Polygon(third, second, first);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class PolygonUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void isEqualForSamePoints() {
|
||||
void isEqualForSamePoints() {
|
||||
|
||||
Polygon left = new Polygon(third, second, first);
|
||||
Polygon right = new Polygon(third, second, first);
|
||||
@@ -56,14 +56,14 @@ public class PolygonUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-437
|
||||
public void testToString() {
|
||||
void testToString() {
|
||||
|
||||
assertThat(new Polygon(third, second, first).toString()).isEqualTo(
|
||||
"Polygon: [Point [x=3.000000, y=3.000000],Point [x=2.000000, y=2.000000],Point [x=1.000000, y=1.000000]]");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-482
|
||||
public void testSerialization() {
|
||||
void testSerialization() {
|
||||
|
||||
Polygon polygon = new Polygon(third, second, first);
|
||||
|
||||
|
||||
@@ -23,12 +23,10 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.runners.Enclosed;
|
||||
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.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.Metrics;
|
||||
|
||||
@@ -37,54 +35,40 @@ import org.springframework.data.geo.Metrics;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(Enclosed.class)
|
||||
public class DistanceFormatterUnitTests {
|
||||
class DistanceFormatterUnitTests {
|
||||
|
||||
static Distance REFERENCE = new Distance(10.8, Metrics.KILOMETERS);
|
||||
|
||||
@Test
|
||||
public void testname() {
|
||||
// To make sure Maven picks up the tests
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
void rejectsArbitraryNonsense() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> INSTANCE.convert("foo"));
|
||||
}
|
||||
|
||||
public static class UnparameterizedTests {
|
||||
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
public void rejectsArbitraryNonsense() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> INSTANCE.convert("foo"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
public void rejectsUnsupportedMetric() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> INSTANCE.convert("10.8cm"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
public void printsDistance() {
|
||||
assertThat(INSTANCE.print(REFERENCE, Locale.US)).isEqualTo("10.8km");
|
||||
}
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
void rejectsUnsupportedMetric() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> INSTANCE.convert("10.8cm"));
|
||||
}
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public static class ParameterizedTests {
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
void printsDistance() {
|
||||
assertThat(INSTANCE.print(REFERENCE, Locale.US)).isEqualTo("10.8km");
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<String[]> parameters() {
|
||||
return Arrays.asList(new String[] { "10.8km" }, new String[] { " 10.8km" }, new String[] { " 10.8 km" },
|
||||
new String[] { " 10.8 km " }, new String[] { " 10.8 KM" }, new String[] { " 10.8 kilometers" },
|
||||
new String[] { " 10.8 KILOMETERS" }, new String[] { " 10.8 KILOMETERS " });
|
||||
}
|
||||
static Collection<String[]> parameters() {
|
||||
return Arrays.asList(new String[] { "10.8km" }, new String[] { " 10.8km" }, new String[] { " 10.8 km" },
|
||||
new String[] { " 10.8 km " }, new String[] { " 10.8 KM" }, new String[] { " 10.8 kilometers" },
|
||||
new String[] { " 10.8 KILOMETERS" }, new String[] { " 10.8 KILOMETERS " });
|
||||
}
|
||||
|
||||
public @Parameter String source;
|
||||
@ParameterizedTest // DATAREST-279, DATACMNS-626
|
||||
@MethodSource("parameters")
|
||||
void parsesDistanceFromString(String source) {
|
||||
assertThat(INSTANCE.convert(source)).isEqualTo(REFERENCE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
public void parsesDistanceFromString() {
|
||||
assertThat(INSTANCE.convert(source)).isEqualTo(REFERENCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsesDistances() throws ParseException {
|
||||
assertThat(INSTANCE.parse(source, Locale.US)).isEqualTo(REFERENCE);
|
||||
}
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void parsesDistances(String source) throws ParseException {
|
||||
assertThat(INSTANCE.parse(source, Locale.US)).isEqualTo(REFERENCE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,9 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.runners.Enclosed;
|
||||
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.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.data.geo.Point;
|
||||
|
||||
@@ -37,53 +34,47 @@ import org.springframework.data.geo.Point;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(Enclosed.class)
|
||||
public class PointFormatterUnitTests {
|
||||
class PointFormatterUnitTests {
|
||||
|
||||
static Point REFERENCE = new Point(20.9, 10.8);
|
||||
|
||||
@Test
|
||||
public void testname() {
|
||||
void testname() {
|
||||
// To make sure Maven picks up the tests
|
||||
}
|
||||
|
||||
public static class UnparameterizedTests {
|
||||
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
public void rejectsArbitraryNonsense() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> INSTANCE.convert("foo")).withMessageContaining("comma");
|
||||
}
|
||||
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
public void rejectsMoreThanTwoCoordinates() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> INSTANCE.convert("10.8,20.9,30.10"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
public void rejectsInvalidCoordinate() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> INSTANCE.convert("10.8,foo"));
|
||||
}
|
||||
@Test
|
||||
// DATAREST-279, DATACMNS-626
|
||||
void rejectsArbitraryNonsense() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> INSTANCE.convert("foo")).withMessageContaining("comma");
|
||||
}
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public static class ParameterizedTests {
|
||||
@Test
|
||||
// DATAREST-279, DATACMNS-626
|
||||
void rejectsMoreThanTwoCoordinates() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> INSTANCE.convert("10.8,20.9,30.10"));
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<String[]> parameters() {
|
||||
return Arrays.asList(new String[] { "10.8,20.9" }, new String[] { " 10.8,20.9 " }, new String[] { " 10.8 ,20.9" },
|
||||
new String[] { " 10.8, 20.9 " });
|
||||
}
|
||||
@Test
|
||||
// DATAREST-279, DATACMNS-626
|
||||
void rejectsInvalidCoordinate() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> INSTANCE.convert("10.8,foo"));
|
||||
}
|
||||
|
||||
public @Parameter String source;
|
||||
static Collection<String[]> parameters() {
|
||||
return Arrays.asList(new String[] { "10.8,20.9" }, new String[] { " 10.8,20.9 " }, new String[] { " 10.8 ,20.9" },
|
||||
new String[] { " 10.8, 20.9 " });
|
||||
}
|
||||
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
public void convertsPointFromString() {
|
||||
assertThat(INSTANCE.convert(source)).isEqualTo(REFERENCE);
|
||||
}
|
||||
@ParameterizedTest // DATAREST-279, DATACMNS-626
|
||||
@MethodSource("parameters")
|
||||
void convertsPointFromString(String source) {
|
||||
assertThat(INSTANCE.convert(source)).isEqualTo(REFERENCE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-279, DATACMNS-626
|
||||
public void parsesPoint() throws ParseException {
|
||||
assertThat(INSTANCE.parse(source, Locale.US)).isEqualTo(REFERENCE);
|
||||
}
|
||||
@ParameterizedTest // DATAREST-279, DATACMNS-626
|
||||
@MethodSource("parameters")
|
||||
void parsesPoint(String source) throws ParseException {
|
||||
assertThat(INSTANCE.parse(source, Locale.US)).isEqualTo(REFERENCE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.time.ZoneOffset;
|
||||
import java.util.Date;
|
||||
|
||||
import org.assertj.core.api.SoftAssertions;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.annotation.Reference;
|
||||
|
||||
@@ -34,12 +34,12 @@ import org.springframework.data.annotation.Reference;
|
||||
* @author Oliver Gierke
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public class AnnotationRevisionMetadataUnitTests {
|
||||
class AnnotationRevisionMetadataUnitTests {
|
||||
|
||||
SoftAssertions softly = new SoftAssertions();
|
||||
|
||||
@Test // DATACMNS-1173
|
||||
public void exposesNoInformationOnEmptyProbe() {
|
||||
void exposesNoInformationOnEmptyProbe() {
|
||||
|
||||
Sample sample = new Sample();
|
||||
RevisionMetadata<Long> metadata = getMetadata(sample);
|
||||
@@ -55,7 +55,7 @@ public class AnnotationRevisionMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1173
|
||||
public void exposesRevisionNumber() {
|
||||
void exposesRevisionNumber() {
|
||||
|
||||
Sample sample = new Sample();
|
||||
sample.revisionNumber = 1L;
|
||||
@@ -69,7 +69,7 @@ public class AnnotationRevisionMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1173
|
||||
public void exposesRevisionDateAndInstantForLocalDateTime() {
|
||||
void exposesRevisionDateAndInstantForLocalDateTime() {
|
||||
|
||||
Sample sample = new Sample();
|
||||
sample.revisionDate = LocalDateTime.now();
|
||||
@@ -84,7 +84,7 @@ public class AnnotationRevisionMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1251
|
||||
public void exposesRevisionDateAndInstantForInstant() {
|
||||
void exposesRevisionDateAndInstantForInstant() {
|
||||
|
||||
SampleWithInstant sample = new SampleWithInstant();
|
||||
sample.revisionInstant = Instant.now();
|
||||
@@ -99,7 +99,7 @@ public class AnnotationRevisionMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1290
|
||||
public void exposesRevisionDateAndInstantForLong() {
|
||||
void exposesRevisionDateAndInstantForLong() {
|
||||
|
||||
SampleWithLong sample = new SampleWithLong();
|
||||
sample.revisionLong = 4711L;
|
||||
@@ -116,7 +116,7 @@ public class AnnotationRevisionMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1384
|
||||
public void supportsTimestampRevisionInstant() {
|
||||
void supportsTimestampRevisionInstant() {
|
||||
|
||||
SampleWithTimestamp sample = new SampleWithTimestamp();
|
||||
Instant now = Instant.now();
|
||||
@@ -128,7 +128,7 @@ public class AnnotationRevisionMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1384
|
||||
public void supportsDateRevisionInstant() {
|
||||
void supportsDateRevisionInstant() {
|
||||
|
||||
SampleWithDate sample = new SampleWithDate();
|
||||
Date date = new Date();
|
||||
|
||||
@@ -24,10 +24,10 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RevisionMetadata}.
|
||||
@@ -35,13 +35,13 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
* @author Oliver Gierke
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RevisionUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RevisionUnitTests {
|
||||
|
||||
@Mock RevisionMetadata<Integer> firstMetadata, secondMetadata;
|
||||
|
||||
@Test
|
||||
public void comparesCorrectly() {
|
||||
void comparesCorrectly() {
|
||||
|
||||
when(firstMetadata.getRevisionNumber()).thenReturn(Optional.of(1));
|
||||
when(secondMetadata.getRevisionNumber()).thenReturn(Optional.of(2));
|
||||
@@ -56,7 +56,7 @@ public class RevisionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-187
|
||||
public void returnsRevisionNumber() {
|
||||
void returnsRevisionNumber() {
|
||||
|
||||
Optional<Integer> reference = Optional.of(4711);
|
||||
when(firstMetadata.getRevisionNumber()).thenReturn(reference);
|
||||
@@ -65,7 +65,7 @@ public class RevisionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1251
|
||||
public void returnsRevisionInstant() {
|
||||
void returnsRevisionInstant() {
|
||||
|
||||
Optional<Instant> reference = Optional.of(Instant.now());
|
||||
when(firstMetadata.getRevisionInstant()).thenReturn(reference);
|
||||
@@ -74,7 +74,7 @@ public class RevisionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-218
|
||||
public void returnsRevisionMetadata() {
|
||||
void returnsRevisionMetadata() {
|
||||
assertThat(Revision.of(firstMetadata, new Object()).getMetadata()).isEqualTo(firstMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,25 +22,25 @@ import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Revisions}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RevisionsUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RevisionsUnitTests {
|
||||
|
||||
@Mock RevisionMetadata<Integer> first, second;
|
||||
Revision<Integer, Object> firstRevision, secondRevision;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
when(first.getRevisionNumber()).thenReturn(Optional.of(0));
|
||||
when(second.getRevisionNumber()).thenReturn(Optional.of(10));
|
||||
@@ -50,13 +50,13 @@ public class RevisionsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsCorrectLatestRevision() {
|
||||
void returnsCorrectLatestRevision() {
|
||||
assertThat(Revisions.of(Arrays.asList(firstRevision, secondRevision)).getLatestRevision())
|
||||
.isEqualTo(secondRevision);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void iteratesInCorrectOrder() {
|
||||
void iteratesInCorrectOrder() {
|
||||
|
||||
Revisions<Integer, Object> revisions = Revisions.of(Arrays.asList(firstRevision, secondRevision));
|
||||
Iterator<Revision<Integer, Object>> iterator = revisions.iterator();
|
||||
@@ -69,13 +69,13 @@ public class RevisionsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reversedRevisionsStillReturnsCorrectLatestRevision() {
|
||||
void reversedRevisionsStillReturnsCorrectLatestRevision() {
|
||||
assertThat(Revisions.of(Arrays.asList(firstRevision, secondRevision)).reverse().getLatestRevision())
|
||||
.isEqualTo(secondRevision);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void iteratesReversedRevisionsInCorrectOrder() {
|
||||
void iteratesReversedRevisionsInCorrectOrder() {
|
||||
|
||||
Revisions<Integer, Object> revisions = Revisions.of(Arrays.asList(firstRevision, secondRevision));
|
||||
Iterator<Revision<Integer, Object>> iterator = revisions.reverse().iterator();
|
||||
@@ -88,7 +88,7 @@ public class RevisionsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcesInvalidlyOrderedRevisionsToBeOrdered() {
|
||||
void forcesInvalidlyOrderedRevisionsToBeOrdered() {
|
||||
|
||||
Revisions<Integer, Object> revisions = Revisions.of(Arrays.asList(secondRevision, firstRevision));
|
||||
Iterator<Revision<Integer, Object>> iterator = revisions.iterator();
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.convert.EntityInstantiators;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
import org.springframework.data.mapping.context.SamplePersistentProperty;
|
||||
|
||||
@@ -17,8 +17,8 @@ package org.springframework.data.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
import org.springframework.data.mapping.context.SamplePersistentProperty;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class MappingMetadataTests {
|
||||
|
||||
SampleMappingContext ctx;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ctx = new SampleMappingContext();
|
||||
}
|
||||
|
||||
@@ -19,10 +19,11 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
@@ -32,17 +33,17 @@ import org.springframework.data.util.TypeInformation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
|
||||
@Mock PersistentEntity<Object, P> entity;
|
||||
@Mock PersistentEntity<String, P> stringEntity;
|
||||
|
||||
TypeInformation<Object> type = ClassTypeInformation.from(Object.class);
|
||||
Annotation[] annotations = new Annotation[0];
|
||||
private TypeInformation<Object> type = ClassTypeInformation.from(Object.class);
|
||||
private Annotation[] annotations = new Annotation[0];
|
||||
|
||||
@Test
|
||||
public void twoParametersWithIdenticalSetupEqual() {
|
||||
void twoParametersWithIdenticalSetupEqual() {
|
||||
|
||||
Parameter<Object, P> left = new Parameter<>("name", type, annotations, entity);
|
||||
Parameter<Object, P> right = new Parameter<>("name", type, annotations, entity);
|
||||
@@ -52,7 +53,7 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoParametersWithIdenticalSetupAndNullNameEqual() {
|
||||
void twoParametersWithIdenticalSetupAndNullNameEqual() {
|
||||
|
||||
Parameter<Object, P> left = new Parameter<>(null, type, annotations, entity);
|
||||
Parameter<Object, P> right = new Parameter<>(null, type, annotations, entity);
|
||||
@@ -62,7 +63,7 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoParametersWithIdenticalAndNullEntitySetupEqual() {
|
||||
void twoParametersWithIdenticalAndNullEntitySetupEqual() {
|
||||
|
||||
Parameter<Object, P> left = new Parameter<>("name", type, annotations, null);
|
||||
Parameter<Object, P> right = new Parameter<>("name", type, annotations, null);
|
||||
@@ -72,7 +73,7 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoParametersWithDifferentNameAreNotEqual() {
|
||||
void twoParametersWithDifferentNameAreNotEqual() {
|
||||
|
||||
Parameter<Object, P> left = new Parameter<>("first", type, annotations, entity);
|
||||
Parameter<Object, P> right = new Parameter<>("second", type, annotations, entity);
|
||||
@@ -81,7 +82,7 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoParametersWithDifferenTypeAreNotEqual() {
|
||||
void twoParametersWithDifferenTypeAreNotEqual() {
|
||||
|
||||
Parameter<Object, P> left = new Parameter<>("name", type, annotations, entity);
|
||||
Parameter<String, P> right = new Parameter<>("name", ClassTypeInformation.from(String.class), annotations,
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
import org.springframework.data.mapping.context.SamplePersistentProperty;
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.data.mapping.PreferredConstructorDiscovererUnitTests.Outer.Inner;
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link TargetAwareIdentifierAccessor}.
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -38,10 +38,10 @@ import org.springframework.data.mapping.callback.CapturingEntityCallback.ThirdCa
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class DefaultEntityCallbacksUnitTests {
|
||||
class DefaultEntityCallbacksUnitTests {
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void shouldDispatchCallback() {
|
||||
void shouldDispatchCallback() {
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class DefaultEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void shouldDispatchCallsToLambdaReceivers() {
|
||||
void shouldDispatchCallsToLambdaReceivers() {
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(LambdaConfig.class);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DefaultEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void invokeGenericEvent() {
|
||||
void invokeGenericEvent() {
|
||||
|
||||
DefaultEntityCallbacks callbacks = new DefaultEntityCallbacks();
|
||||
callbacks.addEntityCallback(new GenericPersonCallback());
|
||||
@@ -78,7 +78,7 @@ public class DefaultEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void invokeGenericEventWithArgs() {
|
||||
void invokeGenericEventWithArgs() {
|
||||
|
||||
DefaultEntityCallbacks callbacks = new DefaultEntityCallbacks();
|
||||
callbacks.addEntityCallback(new GenericPersonCallbackWithArgs());
|
||||
@@ -90,7 +90,7 @@ public class DefaultEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void invokeInvalidEvent() {
|
||||
void invokeInvalidEvent() {
|
||||
|
||||
DefaultEntityCallbacks callbacks = new DefaultEntityCallbacks();
|
||||
callbacks.addEntityCallback(new InvalidEntityCallback() {});
|
||||
@@ -101,7 +101,7 @@ public class DefaultEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void passesInvocationResultOnAlongTheChain() {
|
||||
void passesInvocationResultOnAlongTheChain() {
|
||||
|
||||
CapturingEntityCallback first = new FirstCallback();
|
||||
CapturingEntityCallback second = new SecondCallback();
|
||||
@@ -121,7 +121,7 @@ public class DefaultEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void errorsOnNullEntity() {
|
||||
void errorsOnNullEntity() {
|
||||
|
||||
DefaultEntityCallbacks callbacks = new DefaultEntityCallbacks();
|
||||
callbacks.addEntityCallback(new CapturingEntityCallback());
|
||||
@@ -131,7 +131,7 @@ public class DefaultEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void errorsOnNullValueReturnedByCallbackEntity() {
|
||||
void errorsOnNullValueReturnedByCallbackEntity() {
|
||||
|
||||
CapturingEntityCallback first = new FirstCallback();
|
||||
CapturingEntityCallback second = new SecondCallback(null);
|
||||
@@ -153,7 +153,7 @@ public class DefaultEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void detectsMultipleCallbacksWithinOneClass() {
|
||||
void detectsMultipleCallbacksWithinOneClass() {
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MultipleCallbacksInOneClassConfig.class);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -36,10 +36,10 @@ import org.springframework.data.mapping.callback.CapturingEntityCallback.ThirdCa
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class DefaultReactiveEntityCallbacksUnitTests {
|
||||
class DefaultReactiveEntityCallbacksUnitTests {
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void dispatchResolvesOnSubscribe() {
|
||||
void dispatchResolvesOnSubscribe() {
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class);
|
||||
|
||||
@@ -56,7 +56,7 @@ public class DefaultReactiveEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void invokeGenericEvent() {
|
||||
void invokeGenericEvent() {
|
||||
|
||||
DefaultReactiveEntityCallbacks callbacks = new DefaultReactiveEntityCallbacks();
|
||||
callbacks.addEntityCallback(new GenericPersonCallback());
|
||||
@@ -68,7 +68,7 @@ public class DefaultReactiveEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void passesInvocationResultOnAlongTheChain() {
|
||||
void passesInvocationResultOnAlongTheChain() {
|
||||
|
||||
CapturingEntityCallback first = new FirstCallback();
|
||||
CapturingEntityCallback second = new SecondCallback();
|
||||
@@ -91,7 +91,7 @@ public class DefaultReactiveEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void errorsOnNullEntity() {
|
||||
void errorsOnNullEntity() {
|
||||
|
||||
DefaultReactiveEntityCallbacks callbacks = new DefaultReactiveEntityCallbacks();
|
||||
callbacks.addEntityCallback(new CapturingEntityCallback());
|
||||
@@ -101,7 +101,7 @@ public class DefaultReactiveEntityCallbacksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void errorsOnNullValueReturnedByCallbackEntity() {
|
||||
void errorsOnNullValueReturnedByCallbackEntity() {
|
||||
|
||||
CapturingEntityCallback first = new FirstCallback();
|
||||
CapturingEntityCallback second = new SecondCallback(null);
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -34,10 +34,10 @@ import org.springframework.data.mapping.PersonDocument;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class EntityCallbackDiscovererUnitTests {
|
||||
class EntityCallbackDiscovererUnitTests {
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void shouldDiscoverCallbackType() {
|
||||
void shouldDiscoverCallbackType() {
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class EntityCallbackDiscovererUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void shouldDiscoverCallbackTypeByName() {
|
||||
void shouldDiscoverCallbackTypeByName() {
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class EntityCallbackDiscovererUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void shouldSupportCallbackTypes() {
|
||||
void shouldSupportCallbackTypes() {
|
||||
|
||||
EntityCallbackDiscoverer discoverer = new EntityCallbackDiscoverer();
|
||||
|
||||
@@ -79,7 +79,7 @@ public class EntityCallbackDiscovererUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void shouldSupportInstanceCallbackTypes() {
|
||||
void shouldSupportInstanceCallbackTypes() {
|
||||
|
||||
EntityCallbackDiscoverer discoverer = new EntityCallbackDiscoverer();
|
||||
|
||||
@@ -99,7 +99,7 @@ public class EntityCallbackDiscovererUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1467
|
||||
public void shouldDispatchInOrder() {
|
||||
void shouldDispatchInOrder() {
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(OrderedConfig.class);
|
||||
|
||||
@@ -155,14 +155,14 @@ public class EntityCallbackDiscovererUnitTests {
|
||||
@Order(3)
|
||||
static class Third implements EntityCallback<Person> {
|
||||
|
||||
public Person beforeSave(Person object) {
|
||||
Person beforeSave(Person object) {
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
static class Second implements EntityCallback<Person>, Ordered {
|
||||
|
||||
public Person beforeSave(Person object) {
|
||||
Person beforeSave(Person object) {
|
||||
return object;
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class EntityCallbackDiscovererUnitTests {
|
||||
@Order(1)
|
||||
static class First implements EntityCallback<Person> {
|
||||
|
||||
public Person beforeSave(Person object) {
|
||||
Person beforeSave(Person object) {
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -36,10 +36,10 @@ import org.springframework.data.util.TypeInformation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class AbstractMappingContextIntegrationTests<T extends PersistentProperty<T>> {
|
||||
class AbstractMappingContextIntegrationTests<T extends PersistentProperty<T>> {
|
||||
|
||||
@Test // DATACMNS-457
|
||||
public void returnsManagedType() {
|
||||
void returnsManagedType() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
context.setInitialEntitySet(Collections.singleton(Person.class));
|
||||
@@ -49,7 +49,7 @@ public class AbstractMappingContextIntegrationTests<T extends PersistentProperty
|
||||
}
|
||||
|
||||
@Test // DATACMNS-457
|
||||
public void indicatesManagedType() {
|
||||
void indicatesManagedType() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
context.setInitialEntitySet(Collections.singleton(Person.class));
|
||||
@@ -59,7 +59,7 @@ public class AbstractMappingContextIntegrationTests<T extends PersistentProperty
|
||||
}
|
||||
|
||||
@Test // DATACMNS-243
|
||||
public void createsPersistentEntityForInterfaceCorrectly() {
|
||||
void createsPersistentEntityForInterfaceCorrectly() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = context
|
||||
@@ -69,7 +69,7 @@ public class AbstractMappingContextIntegrationTests<T extends PersistentProperty
|
||||
}
|
||||
|
||||
@Test // DATACMNS-65
|
||||
public void foo() throws InterruptedException {
|
||||
void foo() throws InterruptedException {
|
||||
|
||||
final DummyMappingContext context = new DummyMappingContext();
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.data.annotation.Id;
|
||||
@@ -53,19 +53,19 @@ import org.springframework.data.util.TypeInformation;
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class AbstractMappingContextUnitTests {
|
||||
class AbstractMappingContextUnitTests {
|
||||
|
||||
SampleMappingContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
context = new SampleMappingContext();
|
||||
context.setSimpleTypeHolder(new SimpleTypeHolder(Collections.singleton(LocalDateTime.class), true));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-92
|
||||
public void doesNotAddInvalidEntity() {
|
||||
void doesNotAddInvalidEntity() {
|
||||
|
||||
context = TypeRejectingMappingContext.rejecting(() -> new MappingException("Not supported!"), Unsupported.class);
|
||||
|
||||
@@ -74,7 +74,7 @@ public class AbstractMappingContextUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registersEntitiesOnInitialization() {
|
||||
void registersEntitiesOnInitialization() {
|
||||
|
||||
ApplicationContext applicationContext = mock(ApplicationContext.class);
|
||||
|
||||
@@ -88,24 +88,24 @@ public class AbstractMappingContextUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-214
|
||||
public void returnsNullPersistentEntityForSimpleTypes() {
|
||||
void returnsNullPersistentEntityForSimpleTypes() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
assertThat(context.getPersistentEntity(String.class)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-214
|
||||
public void rejectsNullValueForGetPersistentEntityOfClass() {
|
||||
void rejectsNullValueForGetPersistentEntityOfClass() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> context.getPersistentEntity((Class<?>) null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-214
|
||||
public void rejectsNullValueForGetPersistentEntityOfTypeInformation() {
|
||||
void rejectsNullValueForGetPersistentEntityOfTypeInformation() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> context.getPersistentEntity((TypeInformation<?>) null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-228
|
||||
public void doesNotCreatePersistentPropertyForGroovyMetaClass() {
|
||||
void doesNotCreatePersistentPropertyForGroovyMetaClass() {
|
||||
|
||||
SampleMappingContext mappingContext = new SampleMappingContext();
|
||||
mappingContext.initialize();
|
||||
@@ -116,7 +116,7 @@ public class AbstractMappingContextUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-332
|
||||
public void usesMostConcreteProperty() {
|
||||
void usesMostConcreteProperty() {
|
||||
|
||||
SampleMappingContext mappingContext = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext
|
||||
@@ -127,7 +127,7 @@ public class AbstractMappingContextUnitTests {
|
||||
|
||||
@Test // DATACMNS-345
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void returnsEntityForComponentType() {
|
||||
void returnsEntityForComponentType() {
|
||||
|
||||
SampleMappingContext mappingContext = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext
|
||||
@@ -139,7 +139,7 @@ public class AbstractMappingContextUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-390
|
||||
public void exposesCopyOfPersistentEntitiesToAvoidConcurrentModificationException() {
|
||||
void exposesCopyOfPersistentEntitiesToAvoidConcurrentModificationException() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
context.getPersistentEntity(ClassTypeInformation.MAP);
|
||||
@@ -154,38 +154,38 @@ public class AbstractMappingContextUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-447
|
||||
public void shouldReturnNullForSimpleTypesIfInStrictIsEnabled() {
|
||||
void shouldReturnNullForSimpleTypesIfInStrictIsEnabled() {
|
||||
|
||||
context.setStrict(true);
|
||||
assertThat(context.getPersistentEntity(Integer.class)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-462
|
||||
public void hasPersistentEntityForCollectionPropertiesAfterInitialization() {
|
||||
void hasPersistentEntityForCollectionPropertiesAfterInitialization() {
|
||||
|
||||
context.getPersistentEntity(Sample.class);
|
||||
assertHasEntityFor(Person.class, context, true);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-479
|
||||
public void doesNotAddMapImplementationClassesAsPersistentEntity() {
|
||||
void doesNotAddMapImplementationClassesAsPersistentEntity() {
|
||||
|
||||
context.getPersistentEntity(Sample.class);
|
||||
assertHasEntityFor(TreeMap.class, context, false);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1171
|
||||
public void shouldCreateEntityForKotlinDataClass() {
|
||||
void shouldCreateEntityForKotlinDataClass() {
|
||||
assertThat(context.getPersistentEntity(SimpleDataClass.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1171
|
||||
public void shouldNotCreateEntityForSyntheticKotlinClass() {
|
||||
void shouldNotCreateEntityForSyntheticKotlinClass() {
|
||||
assertThat(context.getPersistentEntity(TypeCreatingSyntheticClass.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1208
|
||||
public void ensureHasPersistentEntityReportsFalseForTypesThatShouldntBeCreated() {
|
||||
void ensureHasPersistentEntityReportsFalseForTypesThatShouldntBeCreated() {
|
||||
|
||||
assertThat(context.hasPersistentEntityFor(String.class)).isFalse();
|
||||
assertThat(context.getPersistentEntity(String.class)).isNull();
|
||||
@@ -193,7 +193,7 @@ public class AbstractMappingContextUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1214
|
||||
public void doesNotReturnPersistentEntityForCustomSimpleTypeProperty() {
|
||||
void doesNotReturnPersistentEntityForCustomSimpleTypeProperty() {
|
||||
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Person.class);
|
||||
SamplePersistentProperty property = entity.getRequiredPersistentProperty("date");
|
||||
@@ -202,7 +202,7 @@ public class AbstractMappingContextUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1574
|
||||
public void cleansUpCacheForRuntimeException() {
|
||||
void cleansUpCacheForRuntimeException() {
|
||||
|
||||
TypeRejectingMappingContext context = TypeRejectingMappingContext.rejecting(() -> new RuntimeException(),
|
||||
Unsupported.class);
|
||||
@@ -278,7 +278,7 @@ public class AbstractMappingContextUnitTests {
|
||||
* @param types must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static <T extends RuntimeException> TypeRejectingMappingContext rejecting(Supplier<T> exception,
|
||||
static <T extends RuntimeException> TypeRejectingMappingContext rejecting(Supplier<T> exception,
|
||||
Class<?>... types) {
|
||||
return new TypeRejectingMappingContext(exception, Arrays.asList(types));
|
||||
}
|
||||
|
||||
@@ -22,11 +22,12 @@ import static org.mockito.Mockito.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
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.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyPath;
|
||||
@@ -36,8 +37,8 @@ import org.springframework.data.mapping.PersistentPropertyPath;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultPersistentPropertyPathUnitTests<P extends PersistentProperty<P>> {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DefaultPersistentPropertyPathUnitTests<P extends PersistentProperty<P>> {
|
||||
|
||||
@Mock P first, second;
|
||||
|
||||
@@ -46,19 +47,19 @@ public class DefaultPersistentPropertyPathUnitTests<P extends PersistentProperty
|
||||
PersistentPropertyPath<P> oneLeg;
|
||||
PersistentPropertyPath<P> twoLegs;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
oneLeg = new DefaultPersistentPropertyPath<>(Collections.singletonList(first));
|
||||
twoLegs = new DefaultPersistentPropertyPath<>(Arrays.asList(first, second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNullProperties() {
|
||||
void rejectsNullProperties() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new DefaultPersistentPropertyPath<>(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesPropertyNameForSimpleDotPath() {
|
||||
void usesPropertyNameForSimpleDotPath() {
|
||||
|
||||
when(first.getName()).thenReturn("foo");
|
||||
when(second.getName()).thenReturn("bar");
|
||||
@@ -67,7 +68,7 @@ public class DefaultPersistentPropertyPathUnitTests<P extends PersistentProperty
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesConverterToCreatePropertyPath() {
|
||||
void usesConverterToCreatePropertyPath() {
|
||||
|
||||
when(converter.convert(any())).thenReturn("foo");
|
||||
|
||||
@@ -75,28 +76,28 @@ public class DefaultPersistentPropertyPathUnitTests<P extends PersistentProperty
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsCorrectLeafProperty() {
|
||||
void returnsCorrectLeafProperty() {
|
||||
|
||||
assertThat(twoLegs.getLeafProperty()).isEqualTo(second);
|
||||
assertThat(oneLeg.getLeafProperty()).isEqualTo(first);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsCorrectBaseProperty() {
|
||||
void returnsCorrectBaseProperty() {
|
||||
|
||||
assertThat(twoLegs.getBaseProperty()).isEqualTo(first);
|
||||
assertThat(oneLeg.getBaseProperty()).isEqualTo(first);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detectsBasePathCorrectly() {
|
||||
void detectsBasePathCorrectly() {
|
||||
|
||||
assertThat(oneLeg.isBasePathOf(twoLegs)).isTrue();
|
||||
assertThat(twoLegs.isBasePathOf(oneLeg)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculatesExtensionCorrectly() {
|
||||
void calculatesExtensionCorrectly() {
|
||||
|
||||
PersistentPropertyPath<P> extension = twoLegs.getExtensionForBaseOf(oneLeg);
|
||||
|
||||
@@ -104,17 +105,17 @@ public class DefaultPersistentPropertyPathUnitTests<P extends PersistentProperty
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsTheCorrectParentPath() {
|
||||
void returnsTheCorrectParentPath() {
|
||||
assertThat(twoLegs.getParentPath()).isEqualTo(oneLeg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsEmptyPathForRootLevelProperty() {
|
||||
void returnsEmptyPathForRootLevelProperty() {
|
||||
assertThat(oneLeg.getParentPath()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnItselfForEmptyPath() {
|
||||
void returnItselfForEmptyPath() {
|
||||
|
||||
PersistentPropertyPath<P> parent = oneLeg.getParentPath();
|
||||
PersistentPropertyPath<P> parentsParent = parent.getParentPath();
|
||||
@@ -124,23 +125,23 @@ public class DefaultPersistentPropertyPathUnitTests<P extends PersistentProperty
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathReturnsCorrectSize() {
|
||||
void pathReturnsCorrectSize() {
|
||||
assertThat(oneLeg.getLength()).isEqualTo(1);
|
||||
assertThat(twoLegs.getLength()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-444
|
||||
public void skipsMappedPropertyNameIfConverterReturnsNull() {
|
||||
void skipsMappedPropertyNameIfConverterReturnsNull() {
|
||||
assertThat(twoLegs.toDotPath(source -> null)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-444
|
||||
public void skipsMappedPropertyNameIfConverterReturnsEmptyStrings() {
|
||||
void skipsMappedPropertyNameIfConverterReturnsEmptyStrings() {
|
||||
assertThat(twoLegs.toDotPath(source -> "")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1466
|
||||
public void returnsNullForLeafPropertyOnEmptyPath() {
|
||||
void returnsNullForLeafPropertyOnEmptyPath() {
|
||||
|
||||
PersistentPropertyPath<P> path = new DefaultPersistentPropertyPath<P>(Collections.emptyList());
|
||||
|
||||
@@ -148,7 +149,7 @@ public class DefaultPersistentPropertyPathUnitTests<P extends PersistentProperty
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1466
|
||||
public void returnsNullForBasePropertyOnEmptyPath() {
|
||||
void returnsNullForBasePropertyOnEmptyPath() {
|
||||
|
||||
PersistentPropertyPath<P> path = new DefaultPersistentPropertyPath<P>(Collections.emptyList());
|
||||
|
||||
|
||||
@@ -17,10 +17,11 @@ package org.springframework.data.mapping.context;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
|
||||
@@ -29,8 +30,8 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MappingContextEventUnitTests<E extends PersistentEntity<?, P>, P extends PersistentProperty<P>> {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class MappingContextEventUnitTests<E extends PersistentEntity<?, P>, P extends PersistentProperty<P>> {
|
||||
|
||||
@Mock
|
||||
E entity;
|
||||
@@ -39,21 +40,21 @@ public class MappingContextEventUnitTests<E extends PersistentEntity<?, P>, P ex
|
||||
MappingContext<?, ?> mappingContext, otherMappingContext;
|
||||
|
||||
@Test
|
||||
public void returnsPersistentEntityHandedToTheEvent() {
|
||||
void returnsPersistentEntityHandedToTheEvent() {
|
||||
|
||||
MappingContextEvent<E, P> event = new MappingContextEvent<>(mappingContext, entity);
|
||||
assertThat(event.getPersistentEntity()).isEqualTo(entity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesMappingContextAsEventSource() {
|
||||
void usesMappingContextAsEventSource() {
|
||||
|
||||
MappingContextEvent<E, P> event = new MappingContextEvent<>(mappingContext, entity);
|
||||
assertThat(event.getSource()).isEqualTo(mappingContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detectsEmittingMappingContextCorrectly() {
|
||||
void detectsEmittingMappingContextCorrectly() {
|
||||
|
||||
MappingContextEvent<E, P> event = new MappingContextEvent<>(mappingContext, entity);
|
||||
assertThat(event.wasEmittedBy(mappingContext)).isTrue();
|
||||
|
||||
@@ -20,10 +20,11 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Reference;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
@@ -34,19 +35,19 @@ import org.springframework.data.util.ClassTypeInformation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PersistentEntitiesUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PersistentEntitiesUnitTests {
|
||||
|
||||
@Mock SampleMappingContext first;
|
||||
@Mock SampleMappingContext second;
|
||||
|
||||
@Test // DATACMNS-458
|
||||
public void rejectsNullMappingContexts() {
|
||||
void rejectsNullMappingContexts() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new PersistentEntities(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-458
|
||||
public void returnsPersistentEntitiesFromMappingContexts() {
|
||||
void returnsPersistentEntitiesFromMappingContexts() {
|
||||
|
||||
when(first.hasPersistentEntityFor(Sample.class)).thenReturn(false);
|
||||
when(second.hasPersistentEntityFor(Sample.class)).thenReturn(true);
|
||||
@@ -61,7 +62,7 @@ public class PersistentEntitiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-458
|
||||
public void indicatesManagedType() {
|
||||
void indicatesManagedType() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
context.setInitialEntitySet(Collections.singleton(Sample.class));
|
||||
@@ -77,7 +78,7 @@ public class PersistentEntitiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1318
|
||||
public void detectsReferredToEntity() {
|
||||
void detectsReferredToEntity() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
context.getPersistentEntity(Sample.class);
|
||||
@@ -92,7 +93,7 @@ public class PersistentEntitiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1318
|
||||
public void rejectsAmbiguousIdentifierType() {
|
||||
void rejectsAmbiguousIdentifierType() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
context.getPersistentEntity(FirstWithLongId.class);
|
||||
@@ -111,7 +112,7 @@ public class PersistentEntitiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1318
|
||||
public void allowsExplicitlyQualifiedReference() {
|
||||
void allowsExplicitlyQualifiedReference() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
context.getPersistentEntity(FirstWithLongId.class);
|
||||
@@ -127,7 +128,7 @@ public class PersistentEntitiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1318
|
||||
public void allowsGenericReference() {
|
||||
void allowsGenericReference() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
context.getPersistentEntity(FirstWithGenericId.class);
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Reference;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentPropertyPath;
|
||||
@@ -37,18 +37,18 @@ import org.springframework.util.StringUtils;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack Cypress Hill - Illusions (Q-Tip Remix, Unreleased & Revamped)
|
||||
*/
|
||||
public class PersistentPropertyPathFactoryUnitTests {
|
||||
class PersistentPropertyPathFactoryUnitTests {
|
||||
|
||||
PersistentPropertyPathFactory<BasicPersistentEntity<Object, SamplePersistentProperty>, SamplePersistentProperty> factory = //
|
||||
new PersistentPropertyPathFactory<>(new SampleMappingContext());
|
||||
|
||||
@Test
|
||||
public void doesNotTryToLookupPersistentEntityForLeafProperty() {
|
||||
void doesNotTryToLookupPersistentEntityForLeafProperty() {
|
||||
assertThat(factory.from(Person.class, "name")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-380
|
||||
public void returnsPersistentPropertyPathForDotPath() {
|
||||
void returnsPersistentPropertyPathForDotPath() {
|
||||
|
||||
PersistentPropertyPath<SamplePersistentProperty> path = factory.from(PersonSample.class, "persons.name");
|
||||
|
||||
@@ -58,17 +58,17 @@ public class PersistentPropertyPathFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-380
|
||||
public void rejectsInvalidPropertyReferenceWithMappingException() {
|
||||
void rejectsInvalidPropertyReferenceWithMappingException() {
|
||||
assertThatExceptionOfType(MappingException.class).isThrownBy(() -> factory.from(PersonSample.class, "foo"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-695
|
||||
public void persistentPropertyPathTraversesGenericTypesCorrectly() {
|
||||
void persistentPropertyPathTraversesGenericTypesCorrectly() {
|
||||
assertThat(factory.from(Outer.class, "field.wrapped.field")).hasSize(3);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-727
|
||||
public void exposesContextForFailingPropertyPathLookup() {
|
||||
void exposesContextForFailingPropertyPathLookup() {
|
||||
|
||||
assertThatExceptionOfType(InvalidPersistentPropertyPath.class)//
|
||||
.isThrownBy(() -> factory.from(PersonSample.class, "persons.firstname"))//
|
||||
@@ -79,14 +79,14 @@ public class PersistentPropertyPathFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1116
|
||||
public void cachesPersistentPropertyPaths() {
|
||||
void cachesPersistentPropertyPaths() {
|
||||
|
||||
assertThat(factory.from(PersonSample.class, "persons.name")) //
|
||||
.isSameAs(factory.from(PersonSample.class, "persons.name"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1275
|
||||
public void findsNestedPropertyByFilter() {
|
||||
void findsNestedPropertyByFilter() {
|
||||
|
||||
PersistentPropertyPaths<?, SamplePersistentProperty> paths = factory.from(Sample.class,
|
||||
property -> property.findAnnotation(Inject.class) != null);
|
||||
@@ -95,7 +95,7 @@ public class PersistentPropertyPathFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1275
|
||||
public void findsNestedPropertiesByFilter() {
|
||||
void findsNestedPropertiesByFilter() {
|
||||
|
||||
PersistentPropertyPaths<?, SamplePersistentProperty> paths = factory.from(Wrapper.class,
|
||||
property -> property.findAnnotation(Inject.class) != null);
|
||||
@@ -106,12 +106,12 @@ public class PersistentPropertyPathFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1275
|
||||
public void createsEmptyPropertyPathCorrectly() {
|
||||
void createsEmptyPropertyPathCorrectly() {
|
||||
assertThat(factory.from(Wrapper.class, "")).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1275
|
||||
public void returnsShortestsPathsFirst() {
|
||||
void returnsShortestsPathsFirst() {
|
||||
|
||||
Streamable<String> paths = factory.from(First.class, it -> true, it -> true) //
|
||||
.map(PersistentPropertyPath::toDotPath);
|
||||
@@ -120,7 +120,7 @@ public class PersistentPropertyPathFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1275
|
||||
public void doesNotTraverseAssociationsByDefault() {
|
||||
void doesNotTraverseAssociationsByDefault() {
|
||||
|
||||
Streamable<String> paths = factory.from(First.class, it -> true) //
|
||||
.map(PersistentPropertyPath::toDotPath);
|
||||
@@ -131,7 +131,7 @@ public class PersistentPropertyPathFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1275
|
||||
public void traversesAssociationsIfTraversalGuardAllowsIt() {
|
||||
void traversesAssociationsIfTraversalGuardAllowsIt() {
|
||||
|
||||
PersistentPropertyPaths<First, SamplePersistentProperty> paths = //
|
||||
factory.from(First.class, it -> true, it -> true);
|
||||
@@ -141,7 +141,7 @@ public class PersistentPropertyPathFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1275
|
||||
public void returnsEmptyPropertyPathsIfNoneSelected() {
|
||||
void returnsEmptyPropertyPathsIfNoneSelected() {
|
||||
|
||||
PersistentPropertyPaths<Third, SamplePersistentProperty> paths = factory.from(Third.class, it -> false);
|
||||
|
||||
@@ -150,7 +150,7 @@ public class PersistentPropertyPathFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1275
|
||||
public void returnsShortestPathFirst() {
|
||||
void returnsShortestPathFirst() {
|
||||
|
||||
PersistentPropertyPaths<First, SamplePersistentProperty> paths = factory.from(First.class, it -> !it.isEntity(),
|
||||
it -> true);
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.mapping.context;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.mapping.context.AbstractMappingContext.PersistentPropertyFilter.PropertyMatch;
|
||||
|
||||
/**
|
||||
@@ -26,15 +26,15 @@ import org.springframework.data.mapping.context.AbstractMappingContext.Persisten
|
||||
* @since 1.4
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class PropertyMatchUnitTests {
|
||||
class PropertyMatchUnitTests {
|
||||
|
||||
@Test
|
||||
public void rejectsBothParametersBeingNull() {
|
||||
void rejectsBothParametersBeingNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new PropertyMatch(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesFieldByConcreteNameAndType() throws Exception {
|
||||
void matchesFieldByConcreteNameAndType() throws Exception {
|
||||
|
||||
PropertyMatch match = new PropertyMatch("name", "java.lang.String");
|
||||
assertThat(match.matches("this$0", Object.class)).isFalse();
|
||||
@@ -43,7 +43,7 @@ public class PropertyMatchUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesFieldByNamePattern() throws Exception {
|
||||
void matchesFieldByNamePattern() throws Exception {
|
||||
|
||||
PropertyMatch match = new PropertyMatch("this\\$.*", "java.lang.Object");
|
||||
assertThat(match.matches("this$0", Object.class)).isTrue();
|
||||
@@ -52,7 +52,7 @@ public class PropertyMatchUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesFieldByNameOnly() throws Exception {
|
||||
void matchesFieldByNameOnly() throws Exception {
|
||||
|
||||
PropertyMatch match = new PropertyMatch("this\\$.*", null);
|
||||
assertThat(match.matches("this$0", Object.class)).isTrue();
|
||||
@@ -61,7 +61,7 @@ public class PropertyMatchUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesFieldByTypeNameOnly() throws Exception {
|
||||
void matchesFieldByTypeNameOnly() throws Exception {
|
||||
|
||||
PropertyMatch match = new PropertyMatch(null, "java.lang.Object");
|
||||
assertThat(match.matches("this$0", Object.class)).isTrue();
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
|
||||
public class SamplePersistentProperty extends AnnotationBasedPersistentProperty<SamplePersistentProperty> {
|
||||
|
||||
public SamplePersistentProperty(Property property, BasicPersistentEntity<?, SamplePersistentProperty> owner,
|
||||
SamplePersistentProperty(Property property, BasicPersistentEntity<?, SamplePersistentProperty> owner,
|
||||
SimpleTypeHolder simpleTypeHolder) {
|
||||
super(property, owner, simpleTypeHolder);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ import java.util.Optional;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -52,12 +52,12 @@ import org.springframework.util.ReflectionUtils;
|
||||
*/
|
||||
public class AbstractPersistentPropertyUnitTests {
|
||||
|
||||
TypeInformation<TestClassComplex> typeInfo;
|
||||
PersistentEntity<TestClassComplex, SamplePersistentProperty> entity;
|
||||
SimpleTypeHolder typeHolder;
|
||||
private TypeInformation<TestClassComplex> typeInfo;
|
||||
private PersistentEntity<TestClassComplex, SamplePersistentProperty> entity;
|
||||
private SimpleTypeHolder typeHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
typeInfo = ClassTypeInformation.from(TestClassComplex.class);
|
||||
entity = new BasicPersistentEntity<>(typeInfo);
|
||||
@@ -65,27 +65,27 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-68
|
||||
public void discoversComponentTypeCorrectly() throws Exception {
|
||||
void discoversComponentTypeCorrectly() {
|
||||
assertThat(getProperty(TestClassComplex.class, "testClassSet").getComponentType()).isEqualTo(Object.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-101
|
||||
public void returnsNestedEntityTypeCorrectly() {
|
||||
void returnsNestedEntityTypeCorrectly() {
|
||||
assertThat(getProperty(TestClassComplex.class, "testClassSet").getPersistentEntityTypes()).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-132
|
||||
public void isEntityWorksForUntypedMaps() throws Exception {
|
||||
void isEntityWorksForUntypedMaps() {
|
||||
assertThat(getProperty(TestClassComplex.class, "map").isEntity()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-132
|
||||
public void isEntityWorksForUntypedCollection() throws Exception {
|
||||
void isEntityWorksForUntypedCollection() {
|
||||
assertThat(getProperty(TestClassComplex.class, "collection").isEntity()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-121
|
||||
public void considersPropertiesEqualIfFieldEquals() {
|
||||
void considersPropertiesEqualIfFieldEquals() {
|
||||
|
||||
SamplePersistentProperty firstProperty = getProperty(FirstConcrete.class, "genericField");
|
||||
SamplePersistentProperty secondProperty = getProperty(SecondConcrete.class, "genericField");
|
||||
@@ -95,12 +95,12 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-180
|
||||
public void doesNotConsiderJavaTransientFieldsTransient() {
|
||||
void doesNotConsiderJavaTransientFieldsTransient() {
|
||||
assertThat(getProperty(TestClassComplex.class, "transientField").isTransient()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-206
|
||||
public void findsSimpleGettersAndASetters() {
|
||||
void findsSimpleGettersAndASetters() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(AccessorTestClass.class, "id");
|
||||
|
||||
@@ -109,7 +109,7 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-206
|
||||
public void doesNotUseInvalidGettersAndASetters() {
|
||||
void doesNotUseInvalidGettersAndASetters() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(AccessorTestClass.class, "anotherId");
|
||||
|
||||
@@ -118,7 +118,7 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-206
|
||||
public void usesCustomGetter() {
|
||||
void usesCustomGetter() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(AccessorTestClass.class, "yetAnotherId");
|
||||
|
||||
@@ -127,7 +127,7 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-206
|
||||
public void usesCustomSetter() {
|
||||
void usesCustomSetter() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(AccessorTestClass.class, "yetYetAnotherId");
|
||||
|
||||
@@ -136,7 +136,7 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-206
|
||||
public void doesNotDiscoverGetterAndSetterIfNoPropertyDescriptorGiven() {
|
||||
void doesNotDiscoverGetterAndSetterIfNoPropertyDescriptorGiven() {
|
||||
|
||||
Field field = ReflectionUtils.findField(AccessorTestClass.class, "id");
|
||||
Property property = Property.of(ClassTypeInformation.from(AccessorTestClass.class), field);
|
||||
@@ -149,7 +149,7 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-337
|
||||
public void resolvesActualType() {
|
||||
void resolvesActualType() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "person");
|
||||
assertThat(property.getActualType()).isEqualTo(Person.class);
|
||||
@@ -165,35 +165,35 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-462
|
||||
public void considersCollectionPropertyEntitiesIfComponentTypeIsEntity() {
|
||||
void considersCollectionPropertyEntitiesIfComponentTypeIsEntity() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "persons");
|
||||
assertThat(property.isEntity()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-462
|
||||
public void considersMapPropertyEntitiesIfValueTypeIsEntity() {
|
||||
void considersMapPropertyEntitiesIfValueTypeIsEntity() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "personMap");
|
||||
assertThat(property.isEntity()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-462
|
||||
public void considersArrayPropertyEntitiesIfComponentTypeIsEntity() {
|
||||
void considersArrayPropertyEntitiesIfComponentTypeIsEntity() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "personArray");
|
||||
assertThat(property.isEntity()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-462
|
||||
public void considersCollectionPropertySimpleIfComponentTypeIsSimple() {
|
||||
void considersCollectionPropertySimpleIfComponentTypeIsSimple() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "strings");
|
||||
assertThat(property.isEntity()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-562
|
||||
public void doesNotConsiderPropertyWithTreeMapMapValueAnEntity() {
|
||||
void doesNotConsiderPropertyWithTreeMapMapValueAnEntity() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(TreeMapWrapper.class, "map");
|
||||
assertThat(property.getPersistentEntityTypes()).isEmpty();
|
||||
@@ -201,14 +201,14 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-867
|
||||
public void resolvesFieldNameWithUnderscoresCorrectly() {
|
||||
void resolvesFieldNameWithUnderscoresCorrectly() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(TestClassComplex.class, "var_name_with_underscores");
|
||||
assertThat(property.getName()).isEqualTo("var_name_with_underscores");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1139
|
||||
public void resolvesGenericsForRawType() {
|
||||
void resolvesGenericsForRawType() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(FirstConcrete.class, "genericField");
|
||||
|
||||
@@ -216,7 +216,7 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1180
|
||||
public void returnsAccessorsForGenericReturnType() {
|
||||
void returnsAccessorsForGenericReturnType() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(ConcreteGetter.class, "genericField");
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.data.annotation.AccessType;
|
||||
@@ -55,7 +55,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
BasicPersistentEntity<Object, SamplePersistentProperty> entity;
|
||||
SampleMappingContext context;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
||||
context = new SampleMappingContext();
|
||||
|
||||
@@ -30,11 +30,12 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.data.annotation.AccessType;
|
||||
import org.springframework.data.annotation.AccessType.Type;
|
||||
@@ -67,35 +68,35 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
|
||||
@Mock T property, anotherProperty;
|
||||
|
||||
@Test
|
||||
public void assertInvariants() {
|
||||
void assertInvariants() {
|
||||
PersistentEntitySpec.assertInvariants(createEntity(Person.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNullTypeInformation() {
|
||||
void rejectsNullTypeInformation() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new BasicPersistentEntity<Object, T>(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNullProperty() {
|
||||
void rejectsNullProperty() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> createEntity(Person.class, null).addPersistentProperty(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullForTypeAliasIfNoneConfigured() {
|
||||
void returnsNullForTypeAliasIfNoneConfigured() {
|
||||
|
||||
PersistentEntity<Entity, T> entity = createEntity(Entity.class);
|
||||
assertThat(entity.getTypeAlias()).isEqualTo(Alias.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsTypeAliasIfAnnotated() {
|
||||
void returnsTypeAliasIfAnnotated() {
|
||||
|
||||
PersistentEntity<AliasedEntity, T> entity = createEntity(AliasedEntity.class);
|
||||
assertThat(entity.getTypeAlias()).isEqualTo(Alias.of("foo"));
|
||||
@@ -103,7 +104,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
|
||||
@Test // DATACMNS-50
|
||||
@SuppressWarnings("unchecked")
|
||||
public void considersComparatorForPropertyOrder() {
|
||||
void considersComparatorForPropertyOrder() {
|
||||
|
||||
BasicPersistentEntity<Person, T> entity = createEntity(Person.class,
|
||||
Comparator.comparing(PersistentProperty::getName));
|
||||
@@ -133,7 +134,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-18, DATACMNS-1364
|
||||
public void addingAndIdPropertySetsIdPropertyInternally() {
|
||||
void addingAndIdPropertySetsIdPropertyInternally() {
|
||||
|
||||
MutablePersistentEntity<Person, T> entity = createEntity(Person.class);
|
||||
assertThat(entity.getIdProperty()).isNull();
|
||||
@@ -145,7 +146,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-186, DATACMNS-1364
|
||||
public void rejectsIdPropertyIfAlreadySet() {
|
||||
void rejectsIdPropertyIfAlreadySet() {
|
||||
|
||||
MutablePersistentEntity<Person, T> entity = createEntity(Person.class);
|
||||
|
||||
@@ -159,7 +160,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-365
|
||||
public void detectsPropertyWithAnnotation() {
|
||||
void detectsPropertyWithAnnotation() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
|
||||
@@ -176,7 +177,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1122
|
||||
public void reportsRequiredPropertyName() {
|
||||
void reportsRequiredPropertyName() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
|
||||
@@ -186,7 +187,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-809
|
||||
public void returnsGeneratedPropertyAccessorForPropertyAccessor() {
|
||||
void returnsGeneratedPropertyAccessorForPropertyAccessor() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
|
||||
@@ -206,7 +207,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-596
|
||||
public void rejectsNullBeanForPropertyAccessor() {
|
||||
void rejectsNullBeanForPropertyAccessor() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
|
||||
@@ -215,7 +216,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-596
|
||||
public void rejectsNonMatchingBeanForPropertyAccessor() {
|
||||
void rejectsNonMatchingBeanForPropertyAccessor() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
|
||||
@@ -224,7 +225,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-597
|
||||
public void supportsSubtypeInstancesOnPropertyAccessorLookup() {
|
||||
void supportsSubtypeInstancesOnPropertyAccessorLookup() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
|
||||
@@ -233,7 +234,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-825
|
||||
public void returnsTypeAliasIfAnnotatedUsingComposedAnnotation() {
|
||||
void returnsTypeAliasIfAnnotatedUsingComposedAnnotation() {
|
||||
|
||||
PersistentEntity<AliasEntityUsingComposedAnnotation, T> entity = createEntity(
|
||||
AliasEntityUsingComposedAnnotation.class);
|
||||
@@ -241,7 +242,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-866
|
||||
public void invalidBeanAccessCreatesDescriptiveErrorMessage() {
|
||||
void invalidBeanAccessCreatesDescriptiveErrorMessage() {
|
||||
|
||||
PersistentEntity<Entity, T> entity = createEntity(Entity.class);
|
||||
|
||||
@@ -250,7 +251,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-934, DATACMNS-867
|
||||
public void rejectsNullAssociation() {
|
||||
void rejectsNullAssociation() {
|
||||
|
||||
MutablePersistentEntity<Entity, T> entity = createEntity(Entity.class);
|
||||
|
||||
@@ -258,7 +259,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1141
|
||||
public void getRequiredAnnotationReturnsAnnotation() {
|
||||
void getRequiredAnnotationReturnsAnnotation() {
|
||||
|
||||
PersistentEntity<AliasEntityUsingComposedAnnotation, T> entity = createEntity(
|
||||
AliasEntityUsingComposedAnnotation.class);
|
||||
@@ -266,7 +267,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1141
|
||||
public void getRequiredAnnotationThrowsException() {
|
||||
void getRequiredAnnotationThrowsException() {
|
||||
|
||||
PersistentEntity<AliasEntityUsingComposedAnnotation, T> entity = createEntity(
|
||||
AliasEntityUsingComposedAnnotation.class);
|
||||
@@ -275,7 +276,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1210
|
||||
public void findAnnotationShouldBeThreadSafe() throws InterruptedException {
|
||||
void findAnnotationShouldBeThreadSafe() throws InterruptedException {
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(2);
|
||||
CountDownLatch syncLatch = new CountDownLatch(1);
|
||||
@@ -330,7 +331,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1325
|
||||
public void supportsPersistableViaIdentifierAccessor() {
|
||||
void supportsPersistableViaIdentifierAccessor() {
|
||||
|
||||
PersistentEntity<PersistableEntity, T> entity = createEntity(PersistableEntity.class);
|
||||
|
||||
@@ -338,20 +339,20 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1322
|
||||
public void detectsImmutableEntity() {
|
||||
void detectsImmutableEntity() {
|
||||
|
||||
assertThat(createEntity(SomeValue.class).isImmutable()).isTrue();
|
||||
assertThat(createEntity(Entity.class).isImmutable()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1366
|
||||
public void exposesPropertyPopulationRequired() {
|
||||
void exposesPropertyPopulationRequired() {
|
||||
|
||||
assertThat(createPopulatedPersistentEntity(PropertyPopulationRequired.class).requiresPropertyPopulation()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1366
|
||||
public void exposesPropertyPopulationNotRequired() {
|
||||
void exposesPropertyPopulationNotRequired() {
|
||||
|
||||
Stream.of(PropertyPopulationNotRequired.class, PropertyPopulationNotRequiredWithTransient.class) //
|
||||
.forEach(it -> assertThat(createPopulatedPersistentEntity(it).requiresPropertyPopulation()).isFalse());
|
||||
@@ -372,7 +373,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@TypeAlias("foo")
|
||||
static class AliasedEntity {
|
||||
private static class AliasedEntity {
|
||||
|
||||
}
|
||||
|
||||
@@ -399,12 +400,12 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@ComposedTypeAlias
|
||||
static class AliasEntityUsingComposedAnnotation {}
|
||||
private static class AliasEntityUsingComposedAnnotation {}
|
||||
|
||||
static class Subtype extends Entity {}
|
||||
private static class Subtype extends Entity {}
|
||||
|
||||
@AccessType(Type.PROPERTY)
|
||||
static class EntityWithAnnotation {
|
||||
private static class EntityWithAnnotation {
|
||||
|
||||
}
|
||||
|
||||
@@ -434,25 +435,25 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
@Immutable
|
||||
static class SomeValue {}
|
||||
private static class SomeValue {}
|
||||
|
||||
// DATACMNS-1366
|
||||
|
||||
@RequiredArgsConstructor
|
||||
static class PropertyPopulationRequired {
|
||||
private static class PropertyPopulationRequired {
|
||||
|
||||
private final String firstname, lastname;
|
||||
private String email;
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
static class PropertyPopulationNotRequired {
|
||||
private static class PropertyPopulationNotRequired {
|
||||
|
||||
private final String firstname, lastname;
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
static class PropertyPopulationNotRequiredWithTransient {
|
||||
private static class PropertyPopulationNotRequiredWithTransient {
|
||||
|
||||
private final String firstname, lastname;
|
||||
private @Transient String email;
|
||||
|
||||
@@ -18,10 +18,11 @@ package org.springframework.data.mapping.model;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.data.mapping.PersistentProperty;
|
||||
|
||||
/**
|
||||
@@ -30,7 +31,7 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
* @author Oliver Gierke
|
||||
* @since 1.9
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class CamelCaseAbbreviatingFieldNamingStrategyUnitTests {
|
||||
|
||||
FieldNamingStrategy strategy = new CamelCaseAbbreviatingFieldNamingStrategy();
|
||||
@@ -38,7 +39,7 @@ public class CamelCaseAbbreviatingFieldNamingStrategyUnitTests {
|
||||
@Mock PersistentProperty<?> property;
|
||||
|
||||
@Test // DATACMNS-523
|
||||
public void abbreviatesToCamelCase() {
|
||||
void abbreviatesToCamelCase() {
|
||||
|
||||
assertFieldNameForPropertyName("fooBar", "fb");
|
||||
assertFieldNameForPropertyName("fooBARFooBar", "fbfb");
|
||||
|
||||
@@ -25,10 +25,13 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.classloadersupport.HidingClassLoader;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -45,8 +48,9 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProperty<P>> {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProperty<P>> {
|
||||
|
||||
ClassGeneratingEntityInstantiator instance = new ClassGeneratingEntityInstantiator();
|
||||
|
||||
@@ -54,7 +58,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
@Mock ParameterValueProvider<P> provider;
|
||||
|
||||
@Test
|
||||
public void instantiatesSimpleObjectCorrectly() {
|
||||
void instantiatesSimpleObjectCorrectly() {
|
||||
|
||||
doReturn(Object.class).when(entity).getType();
|
||||
|
||||
@@ -62,7 +66,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantiatesArrayCorrectly() {
|
||||
void instantiatesArrayCorrectly() {
|
||||
|
||||
doReturn(String[][].class).when(entity).getType();
|
||||
|
||||
@@ -70,7 +74,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1126
|
||||
public void instantiatesTypeWithPreferredConstructorUsingParameterValueProvider() {
|
||||
void instantiatesTypeWithPreferredConstructorUsingParameterValueProvider() {
|
||||
|
||||
PreferredConstructor<Foo, P> constructor = PreferredConstructorDiscoverer.discover(Foo.class);
|
||||
|
||||
@@ -85,7 +89,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
|
||||
@Test // DATACMNS-300, DATACMNS-578
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void throwsExceptionOnBeanInstantiationException() {
|
||||
void throwsExceptionOnBeanInstantiationException() {
|
||||
|
||||
doReturn(PersistentEntity.class).when(entity).getType();
|
||||
|
||||
@@ -94,7 +98,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-134, DATACMNS-578
|
||||
public void createsInnerClassInstanceCorrectly() {
|
||||
void createsInnerClassInstanceCorrectly() {
|
||||
|
||||
BasicPersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(from(Inner.class));
|
||||
assertThat(entity.getPersistenceConstructor()).satisfies(constructor -> {
|
||||
@@ -120,7 +124,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
|
||||
@Test // DATACMNS-283, DATACMNS-578
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void capturesContextOnInstantiationException() throws Exception {
|
||||
void capturesContextOnInstantiationException() throws Exception {
|
||||
|
||||
PersistentEntity<Sample, P> entity = new BasicPersistentEntity<>(from(Sample.class));
|
||||
|
||||
@@ -149,7 +153,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
|
||||
@Test // DATACMNS-1175
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void createsInstancesWithRecursionAndSameCtorArgCountCorrectly() {
|
||||
void createsInstancesWithRecursionAndSameCtorArgCountCorrectly() {
|
||||
|
||||
PersistentEntity<SampleWithReference, P> outer = new BasicPersistentEntity<>(from(SampleWithReference.class));
|
||||
PersistentEntity<Sample, P> inner = new BasicPersistentEntity<>(from(Sample.class));
|
||||
@@ -182,7 +186,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-578, DATACMNS-1126
|
||||
public void instantiateObjCtorDefault() {
|
||||
void instantiateObjCtorDefault() {
|
||||
|
||||
doReturn(ObjCtorDefault.class).when(entity).getType();
|
||||
doReturn(PreferredConstructorDiscoverer.discover(ObjCtorDefault.class))//
|
||||
@@ -193,7 +197,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-578, DATACMNS-1126
|
||||
public void instantiateObjCtorNoArgs() {
|
||||
void instantiateObjCtorNoArgs() {
|
||||
|
||||
doReturn(ObjCtorNoArgs.class).when(entity).getType();
|
||||
doReturn(PreferredConstructorDiscoverer.discover(ObjCtorNoArgs.class))//
|
||||
@@ -209,7 +213,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-578, DATACMNS-1126
|
||||
public void instantiateObjCtor1ParamString() {
|
||||
void instantiateObjCtor1ParamString() {
|
||||
|
||||
doReturn(ObjCtor1ParamString.class).when(entity).getType();
|
||||
doReturn(PreferredConstructorDiscoverer.discover(ObjCtor1ParamString.class))//
|
||||
@@ -227,7 +231,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-578, DATACMNS-1126
|
||||
public void instantiateObjCtor2ParamStringString() {
|
||||
void instantiateObjCtor2ParamStringString() {
|
||||
|
||||
doReturn(ObjCtor2ParamStringString.class).when(entity).getType();
|
||||
doReturn(PreferredConstructorDiscoverer.discover(ObjCtor2ParamStringString.class))//
|
||||
@@ -247,7 +251,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-578, DATACMNS-1126
|
||||
public void instantiateObjectCtor1ParamInt() {
|
||||
void instantiateObjectCtor1ParamInt() {
|
||||
|
||||
doReturn(ObjectCtor1ParamInt.class).when(entity).getType();
|
||||
doReturn(PreferredConstructorDiscoverer.discover(ObjectCtor1ParamInt.class))//
|
||||
@@ -265,7 +269,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1200
|
||||
public void instantiateObjectCtor1ParamIntWithoutValue() {
|
||||
void instantiateObjectCtor1ParamIntWithoutValue() {
|
||||
|
||||
doReturn(ObjectCtor1ParamInt.class).when(entity).getType();
|
||||
doReturn(PreferredConstructorDiscoverer.discover(ObjectCtor1ParamInt.class))//
|
||||
@@ -277,7 +281,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
|
||||
@Test // DATACMNS-578, DATACMNS-1126
|
||||
@SuppressWarnings("unchecked")
|
||||
public void instantiateObjectCtor7ParamsString5IntsString() {
|
||||
void instantiateObjectCtor7ParamsString5IntsString() {
|
||||
|
||||
doReturn(ObjectCtor7ParamsString5IntsString.class).when(entity).getType();
|
||||
doReturn(PreferredConstructorDiscoverer.discover(ObjectCtor7ParamsString5IntsString.class))//
|
||||
@@ -304,7 +308,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1373
|
||||
public void shouldInstantiateProtectedInnerClass() {
|
||||
void shouldInstantiateProtectedInnerClass() {
|
||||
|
||||
prepareMocks(ProtectedInnerClass.class);
|
||||
|
||||
@@ -313,7 +317,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1373
|
||||
public void shouldInstantiatePackagePrivateInnerClass() {
|
||||
void shouldInstantiatePackagePrivateInnerClass() {
|
||||
|
||||
prepareMocks(PackagePrivateInnerClass.class);
|
||||
|
||||
@@ -322,7 +326,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1373
|
||||
public void shouldNotInstantiatePrivateInnerClass() {
|
||||
void shouldNotInstantiatePrivateInnerClass() {
|
||||
|
||||
prepareMocks(PrivateInnerClass.class);
|
||||
|
||||
@@ -330,7 +334,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1373
|
||||
public void shouldInstantiateClassWithPackagePrivateConstructor() {
|
||||
void shouldInstantiateClassWithPackagePrivateConstructor() {
|
||||
|
||||
prepareMocks(ClassWithPackagePrivateConstructor.class);
|
||||
|
||||
@@ -339,7 +343,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1373
|
||||
public void shouldInstantiateClassInDefaultPackage() throws ClassNotFoundException {
|
||||
void shouldInstantiateClassInDefaultPackage() throws ClassNotFoundException {
|
||||
|
||||
Class<?> typeInDefaultPackage = Class.forName("TypeInDefaultPackage");
|
||||
prepareMocks(typeInDefaultPackage);
|
||||
@@ -349,7 +353,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1373
|
||||
public void shouldNotInstantiateClassWithPrivateConstructor() {
|
||||
void shouldNotInstantiateClassWithPrivateConstructor() {
|
||||
|
||||
prepareMocks(ClassWithPrivateConstructor.class);
|
||||
|
||||
@@ -357,7 +361,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1422
|
||||
public void shouldUseReflectionIfFrameworkTypesNotVisible() throws Exception {
|
||||
void shouldUseReflectionIfFrameworkTypesNotVisible() throws Exception {
|
||||
|
||||
HidingClassLoader classLoader = HidingClassLoader.hide(ObjectInstantiator.class);
|
||||
classLoader.excludePackage("org.springframework.data.mapping");
|
||||
|
||||
@@ -24,10 +24,9 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.data.annotation.AccessType;
|
||||
import org.springframework.data.annotation.AccessType.Type;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -42,26 +41,12 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class ClassGeneratingPropertyAccessorFactoryDatatypeTests {
|
||||
|
||||
private final ClassGeneratingPropertyAccessorFactory factory = new ClassGeneratingPropertyAccessorFactory();
|
||||
private final SampleMappingContext mappingContext = new SampleMappingContext();
|
||||
|
||||
private final Object bean;
|
||||
private final String propertyName;
|
||||
private final Object value;
|
||||
|
||||
public ClassGeneratingPropertyAccessorFactoryDatatypeTests(Object bean, String propertyName, Object value,
|
||||
String displayName) {
|
||||
|
||||
this.bean = bean;
|
||||
this.propertyName = propertyName;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Parameters(name = "{3}")
|
||||
public static List<Object[]> parameters() throws Exception {
|
||||
static List<Object[]> parameters() throws Exception {
|
||||
|
||||
List<Object[]> parameters = new ArrayList<>();
|
||||
List<Class<?>> types = Arrays.asList(FieldAccess.class, PropertyAccess.class, PrivateFinalFieldAccess.class,
|
||||
@@ -120,8 +105,9 @@ public class ClassGeneratingPropertyAccessorFactoryDatatypeTests {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Test // DATACMNS-809
|
||||
public void shouldSetAndGetProperty() throws Exception {
|
||||
@ParameterizedTest(name = "{3}") // DATACMNS-809
|
||||
@MethodSource("parameters")
|
||||
void shouldSetAndGetProperty(Object bean, String propertyName, Object value, String displayName) {
|
||||
|
||||
assertThat(getProperty(bean, propertyName)).satisfies(property -> {
|
||||
|
||||
@@ -132,8 +118,10 @@ public class ClassGeneratingPropertyAccessorFactoryDatatypeTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATACMNS-809
|
||||
public void shouldUseClassPropertyAccessorFactory() throws Exception {
|
||||
@ParameterizedTest(name = "{3}") // DATACMNS-809
|
||||
@MethodSource("parameters")
|
||||
void shouldUseClassPropertyAccessorFactory(Object bean, String propertyName, Object value, String displayName)
|
||||
throws Exception {
|
||||
|
||||
BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntity = mappingContext
|
||||
.getRequiredPersistentEntity(bean.getClass());
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.data.mapping.model;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.assertj.core.api.Assumptions.*;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
@@ -24,10 +24,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.data.annotation.AccessType;
|
||||
import org.springframework.data.annotation.AccessType.Type;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -36,32 +35,18 @@ import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
import org.springframework.data.mapping.context.SamplePersistentProperty;
|
||||
import org.springframework.data.mapping.model.subpackage.TypeInOtherPackage;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ClassGeneratingPropertyAccessorFactory}
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class ClassGeneratingPropertyAccessorFactoryTests {
|
||||
|
||||
private final static ClassGeneratingPropertyAccessorFactory factory = new ClassGeneratingPropertyAccessorFactory();
|
||||
private final static SampleMappingContext mappingContext = new SampleMappingContext();
|
||||
|
||||
private final Object bean;
|
||||
private final String propertyName;
|
||||
private final Class<?> expectedConstructorType;
|
||||
|
||||
public ClassGeneratingPropertyAccessorFactoryTests(Object bean, String propertyName, Class<?> expectedConstructorType,
|
||||
String displayName) {
|
||||
|
||||
this.bean = bean;
|
||||
this.propertyName = propertyName;
|
||||
this.expectedConstructorType = expectedConstructorType;
|
||||
}
|
||||
|
||||
@Parameters(name = "{3}")
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Object[]> parameters() throws ReflectiveOperationException {
|
||||
|
||||
@@ -102,15 +87,19 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1201
|
||||
public void shouldSupportGeneratedPropertyAccessors() {
|
||||
@ParameterizedTest(name = "{3}") // DATACMNS-1201
|
||||
@MethodSource("parameters")
|
||||
void shouldSupportGeneratedPropertyAccessors(Object bean, String propertyName, Class<?> expectedConstructorType,
|
||||
String displayName) {
|
||||
assertThat(factory.isSupported(mappingContext.getRequiredPersistentEntity(bean.getClass()))).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-809, // DATACMNS-1322
|
||||
public void shouldSetAndGetProperty() throws Exception {
|
||||
@ParameterizedTest(name = "{3}") // DATACMNS-809, DATACMNS-1322
|
||||
@MethodSource("parameters")
|
||||
void shouldSetAndGetProperty(Object bean, String propertyName, Class<?> expectedConstructorType, String displayName)
|
||||
throws Exception {
|
||||
|
||||
assumeTrue(StringUtils.hasText(propertyName));
|
||||
assumeThat(propertyName).isNotEmpty();
|
||||
|
||||
assertThat(getProperty(bean, propertyName)).satisfies(property -> {
|
||||
|
||||
@@ -127,9 +116,11 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATACMNS-809
|
||||
@ParameterizedTest(name = "{3}") // DATACMNS-809
|
||||
@MethodSource("parameters")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void accessorShouldDeclareConstructor() throws Exception {
|
||||
void accessorShouldDeclareConstructor(Object bean, String propertyName, Class<?> expectedConstructorType,
|
||||
String displayName) throws Exception {
|
||||
|
||||
PersistentPropertyAccessor persistentPropertyAccessor = getPersistentPropertyAccessor(bean);
|
||||
|
||||
@@ -139,30 +130,37 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
|
||||
assertThat(declaredConstructors[0].getParameterTypes()[0]).isEqualTo(expectedConstructorType);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-809
|
||||
public void shouldFailOnNullBean() {
|
||||
@ParameterizedTest(name = "{3}") // DATACMNS-809
|
||||
@MethodSource("parameters")
|
||||
void shouldFailOnNullBean(Object bean, String propertyName, Class<?> expectedConstructorType, String displayName) {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> factory.getPropertyAccessor(mappingContext.getRequiredPersistentEntity(bean.getClass()), null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-809
|
||||
public void getPropertyShouldFailOnUnhandledProperty() {
|
||||
@ParameterizedTest(name = "{3}") // DATACMNS-809
|
||||
@MethodSource("parameters")
|
||||
void getPropertyShouldFailOnUnhandledProperty(Object bean, String propertyName, Class<?> expectedConstructorType,
|
||||
String displayName) {
|
||||
|
||||
assertThat(getProperty(new Dummy(), "dummy"))
|
||||
.satisfies(property -> assertThatExceptionOfType(UnsupportedOperationException.class)//
|
||||
.isThrownBy(() -> getPersistentPropertyAccessor(bean).getProperty(property)));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-809
|
||||
public void setPropertyShouldFailOnUnhandledProperty() {
|
||||
@ParameterizedTest(name = "{3}") // DATACMNS-809
|
||||
@MethodSource("parameters")
|
||||
void setPropertyShouldFailOnUnhandledProperty(Object bean, String propertyName, Class<?> expectedConstructorType,
|
||||
String displayName) {
|
||||
|
||||
assertThat(getProperty(new Dummy(), "dummy"))
|
||||
.satisfies(property -> assertThatExceptionOfType(UnsupportedOperationException.class)//
|
||||
.isThrownBy(() -> getPersistentPropertyAccessor(bean).setProperty(property, Optional.empty())));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-809
|
||||
public void shouldUseClassPropertyAccessorFactory() throws Exception {
|
||||
@ParameterizedTest(name = "{3}") // DATACMNS-809
|
||||
@MethodSource("parameters")
|
||||
void shouldUseClassPropertyAccessorFactory(Object bean, String propertyName, Class<?> expectedConstructorType,
|
||||
String displayName) throws Exception {
|
||||
|
||||
BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntity = mappingContext
|
||||
.getRequiredPersistentEntity(bean.getClass());
|
||||
|
||||
@@ -22,7 +22,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Value;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
|
||||
@@ -21,10 +21,11 @@ import static org.mockito.Mockito.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.data.mapping.PersistentEntity;
|
||||
|
||||
/**
|
||||
@@ -32,26 +33,26 @@ import org.springframework.data.mapping.PersistentEntity;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EntityInstantiatorsUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class EntityInstantiatorsUnitTests {
|
||||
|
||||
@Mock PersistentEntity<?, ?> entity;
|
||||
@Mock EntityInstantiator customInstantiator;
|
||||
|
||||
@Test
|
||||
public void rejectsNullFallbackInstantiator() {
|
||||
void rejectsNullFallbackInstantiator() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new EntityInstantiators((EntityInstantiator) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesReflectionEntityInstantiatorAsDefaultFallback() {
|
||||
void usesReflectionEntityInstantiatorAsDefaultFallback() {
|
||||
|
||||
EntityInstantiators instantiators = new EntityInstantiators();
|
||||
assertThat(instantiators.getInstantiatorFor(entity)).isInstanceOf(ClassGeneratingEntityInstantiator.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsCustomInstantiatorForTypeIfRegistered() {
|
||||
void returnsCustomInstantiatorForTypeIfRegistered() {
|
||||
|
||||
doReturn(String.class).when(entity).getType();
|
||||
|
||||
@@ -62,7 +63,7 @@ public class EntityInstantiatorsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesCustomFallbackInstantiatorsIfConfigured() {
|
||||
void usesCustomFallbackInstantiatorsIfConfigured() {
|
||||
|
||||
doReturn(Object.class).when(entity).getType();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.mapping.model;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mapping.IdentifierAccessor;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
@@ -26,24 +26,24 @@ import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class IdPropertyIdentifierAccessorUnitTests {
|
||||
class IdPropertyIdentifierAccessorUnitTests {
|
||||
|
||||
SampleMappingContext mappingContext = new SampleMappingContext();
|
||||
|
||||
@Test // DATACMNS-599
|
||||
public void rejectsEntityWithoutIdentifierProperty() {
|
||||
void rejectsEntityWithoutIdentifierProperty() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new IdPropertyIdentifierAccessor(mappingContext.getRequiredPersistentEntity(Sample.class), new Sample()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-599
|
||||
public void rejectsNullBean() {
|
||||
void rejectsNullBean() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new IdPropertyIdentifierAccessor(mappingContext.getRequiredPersistentEntity(SampleWithId.class), null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-599
|
||||
public void returnsIdentifierValue() {
|
||||
void returnsIdentifierValue() {
|
||||
|
||||
SampleWithId sample = new SampleWithId();
|
||||
sample.id = 1L;
|
||||
@@ -54,7 +54,7 @@ public class IdPropertyIdentifierAccessorUnitTests {
|
||||
assertThat(accessor.getIdentifier()).isEqualTo(sample.id);
|
||||
}
|
||||
|
||||
static class Sample {}
|
||||
private static class Sample {}
|
||||
|
||||
static class SampleWithId {
|
||||
@Id Long id;
|
||||
|
||||
@@ -26,12 +26,11 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
import org.springframework.data.mapping.context.SamplePersistentProperty;
|
||||
import org.springframework.data.mapping.model.With32Args;
|
||||
import org.springframework.data.mapping.model.With33Args;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.domain.Persistable;
|
||||
@@ -33,12 +33,12 @@ import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
* @soundtrack Scary Pockets - Crash Into Me (Dave Matthews Band Cover feat. Julia Nunes) -
|
||||
* https://www.youtube.com/watch?v=syGlBNVGEqU
|
||||
*/
|
||||
public class PersistentEntityIsNewStrategyUnitTests {
|
||||
class PersistentEntityIsNewStrategyUnitTests {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
private SampleMappingContext context = new SampleMappingContext();
|
||||
|
||||
@Test // DATACMNS-133
|
||||
public void detectsNewEntityForPrimitiveId() {
|
||||
void detectsNewEntityForPrimitiveId() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(PrimitiveIdEntity.class);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class PersistentEntityIsNewStrategyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-133
|
||||
public void detectsNotNewEntityForPrimitiveId() {
|
||||
void detectsNotNewEntityForPrimitiveId() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(PrimitiveIdEntity.class);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class PersistentEntityIsNewStrategyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-133
|
||||
public void detectsNewEntityForWrapperId() {
|
||||
void detectsNewEntityForWrapperId() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(PrimitiveWrapperIdEntity.class);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class PersistentEntityIsNewStrategyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-133
|
||||
public void detectsNotNewEntityForWrapperId() {
|
||||
void detectsNotNewEntityForWrapperId() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(PrimitiveWrapperIdEntity.class);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class PersistentEntityIsNewStrategyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-133
|
||||
public void rejectsUnsupportedIdentifierType() {
|
||||
void rejectsUnsupportedIdentifierType() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(UnsupportedPrimitiveIdEntity.class);
|
||||
|
||||
@@ -88,7 +88,7 @@ public class PersistentEntityIsNewStrategyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1333
|
||||
public void discoversNewPersistableEntity() {
|
||||
void discoversNewPersistableEntity() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(PersistableEntity.class);
|
||||
|
||||
@@ -96,7 +96,7 @@ public class PersistentEntityIsNewStrategyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1333
|
||||
public void discoversNonNewPersistableEntity() {
|
||||
void discoversNonNewPersistableEntity() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(PersistableEntity.class);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class PersistentEntityIsNewStrategyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1333
|
||||
public void prefersVersionOverIdentifier() {
|
||||
void prefersVersionOverIdentifier() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(VersionedEntity.class);
|
||||
|
||||
@@ -118,7 +118,7 @@ public class PersistentEntityIsNewStrategyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1333
|
||||
public void considersEntityWithoutIdNew() {
|
||||
void considersEntityWithoutIdNew() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(NoIdEntity.class);
|
||||
|
||||
@@ -170,5 +170,5 @@ public class PersistentEntityIsNewStrategyUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
static class NoIdEntity {}
|
||||
private static class NoIdEntity {}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,11 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -37,14 +38,14 @@ import org.springframework.data.util.ClassTypeInformation;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PersistentEntityParameterValueProviderUnitTests<P extends PersistentProperty<P>> {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PersistentEntityParameterValueProviderUnitTests<P extends PersistentProperty<P>> {
|
||||
|
||||
@Mock PropertyValueProvider<P> propertyValueProvider;
|
||||
@Mock P property;
|
||||
|
||||
@Test // DATACMNS-134
|
||||
public void usesParentObjectAsImplicitFirstConstructorArgument() {
|
||||
void usesParentObjectAsImplicitFirstConstructorArgument() {
|
||||
|
||||
Object outer = new Outer();
|
||||
|
||||
@@ -69,7 +70,7 @@ public class PersistentEntityParameterValueProviderUnitTests<P extends Persisten
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsPropertyIfNameDoesNotMatch() {
|
||||
void rejectsPropertyIfNameDoesNotMatch() {
|
||||
|
||||
PersistentEntity<Entity, P> entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Entity.class));
|
||||
ParameterValueProvider<P> provider = new PersistentEntityParameterValueProvider<>(entity, propertyValueProvider,
|
||||
|
||||
@@ -27,10 +27,10 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.data.classloadersupport.HidingClassLoader;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
@@ -43,20 +43,10 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class PersistentPropertyAccessorTests {
|
||||
|
||||
private final static SampleMappingContext MAPPING_CONTEXT = new SampleMappingContext();
|
||||
|
||||
private final Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction;
|
||||
|
||||
public PersistentPropertyAccessorTests(Function<Object, PersistentPropertyAccessor<?>> propertyAccessor,
|
||||
String displayName) {
|
||||
|
||||
this.propertyAccessorFunction = propertyAccessor;
|
||||
}
|
||||
|
||||
@Parameters(name = "{1}")
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Object[]> parameters() {
|
||||
|
||||
@@ -74,8 +64,9 @@ public class PersistentPropertyAccessorTests {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1322
|
||||
public void shouldSetProperty() {
|
||||
@ParameterizedTest // DATACMNS-1322
|
||||
@MethodSource("parameters")
|
||||
void shouldSetProperty(Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction) {
|
||||
|
||||
DataClass bean = new DataClass();
|
||||
PersistentPropertyAccessor accessor = propertyAccessorFunction.apply(bean);
|
||||
@@ -88,8 +79,9 @@ public class PersistentPropertyAccessorTests {
|
||||
assertThat(accessor.getProperty(property)).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1322
|
||||
public void shouldSetKotlinDataClassProperty() {
|
||||
@ParameterizedTest // DATACMNS-1322
|
||||
@MethodSource("parameters")
|
||||
void shouldSetKotlinDataClassProperty(Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction) {
|
||||
|
||||
DataClassKt bean = new DataClassKt("foo");
|
||||
PersistentPropertyAccessor accessor = propertyAccessorFunction.apply(bean);
|
||||
@@ -102,8 +94,10 @@ public class PersistentPropertyAccessorTests {
|
||||
assertThat(accessor.getProperty(property)).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1322, DATACMNS-1391
|
||||
public void shouldSetExtendedKotlinDataClassProperty() {
|
||||
@ParameterizedTest // DATACMNS-1322, DATACMNS-1391
|
||||
@MethodSource("parameters")
|
||||
void shouldSetExtendedKotlinDataClassProperty(
|
||||
Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction) {
|
||||
|
||||
ExtendedDataClassKt bean = new ExtendedDataClassKt(0, "bar");
|
||||
PersistentPropertyAccessor accessor = propertyAccessorFunction.apply(bean);
|
||||
@@ -116,8 +110,9 @@ public class PersistentPropertyAccessorTests {
|
||||
assertThat(accessor.getProperty(property)).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1391
|
||||
public void shouldUseKotlinGeneratedCopyMethod() {
|
||||
@ParameterizedTest // DATACMNS-1391
|
||||
@MethodSource("parameters")
|
||||
void shouldUseKotlinGeneratedCopyMethod(Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction) {
|
||||
|
||||
UnusedCustomCopy bean = new UnusedCustomCopy(new Timestamp(100));
|
||||
PersistentPropertyAccessor accessor = propertyAccessorFunction.apply(bean);
|
||||
@@ -130,8 +125,10 @@ public class PersistentPropertyAccessorTests {
|
||||
assertThat(accessor.getProperty(property)).isEqualTo(new Timestamp(200));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1391
|
||||
public void kotlinCopyMethodShouldNotSetUnsettableProperty() {
|
||||
@ParameterizedTest // DATACMNS-1391
|
||||
@MethodSource("parameters")
|
||||
void kotlinCopyMethodShouldNotSetUnsettableProperty(
|
||||
Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction) {
|
||||
|
||||
SingleSettableProperty bean = new SingleSettableProperty(UUID.randomUUID());
|
||||
PersistentPropertyAccessor accessor = propertyAccessorFunction.apply(bean);
|
||||
@@ -140,8 +137,10 @@ public class PersistentPropertyAccessorTests {
|
||||
assertThatThrownBy(() -> accessor.setProperty(property, 1)).isInstanceOf(UnsupportedOperationException.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1451
|
||||
public void shouldSet17thImmutableNullableKotlinProperty() {
|
||||
@ParameterizedTest // DATACMNS-1451
|
||||
@MethodSource("parameters")
|
||||
void shouldSet17thImmutableNullableKotlinProperty(
|
||||
Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction) {
|
||||
|
||||
With33Args bean = new With33Args();
|
||||
PersistentPropertyAccessor accessor = propertyAccessorFunction.apply(bean);
|
||||
@@ -153,8 +152,9 @@ public class PersistentPropertyAccessorTests {
|
||||
assertThat(updated.get17()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1322
|
||||
public void shouldWitherProperty() {
|
||||
@ParameterizedTest // DATACMNS-1322
|
||||
@MethodSource("parameters")
|
||||
void shouldWitherProperty(Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction) {
|
||||
|
||||
ValueClass bean = new ValueClass("foo", "bar");
|
||||
PersistentPropertyAccessor accessor = propertyAccessorFunction.apply(bean);
|
||||
@@ -167,8 +167,9 @@ public class PersistentPropertyAccessorTests {
|
||||
assertThat(accessor.getProperty(property)).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1322
|
||||
public void shouldRejectImmutablePropertyUpdate() {
|
||||
@ParameterizedTest // DATACMNS-1322
|
||||
@MethodSource("parameters")
|
||||
void shouldRejectImmutablePropertyUpdate(Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction) {
|
||||
|
||||
ValueClass bean = new ValueClass("foo", "bar");
|
||||
PersistentPropertyAccessor accessor = propertyAccessorFunction.apply(bean);
|
||||
@@ -177,8 +178,10 @@ public class PersistentPropertyAccessorTests {
|
||||
assertThatThrownBy(() -> accessor.setProperty(property, "value")).isInstanceOf(UnsupportedOperationException.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1322
|
||||
public void shouldRejectImmutableKotlinClassPropertyUpdate() {
|
||||
@ParameterizedTest // DATACMNS-1322
|
||||
@MethodSource("parameters")
|
||||
void shouldRejectImmutableKotlinClassPropertyUpdate(
|
||||
Function<Object, PersistentPropertyAccessor<?>> propertyAccessorFunction) {
|
||||
|
||||
ValueClassKt bean = new ValueClassKt("foo");
|
||||
PersistentPropertyAccessor accessor = propertyAccessorFunction.apply(bean);
|
||||
@@ -188,7 +191,7 @@ public class PersistentPropertyAccessorTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1422
|
||||
public void shouldUseReflectionIfFrameworkTypesNotVisible() throws Exception {
|
||||
void shouldUseReflectionIfFrameworkTypesNotVisible() throws Exception {
|
||||
|
||||
HidingClassLoader classLoader = HidingClassLoader.hide(Assert.class);
|
||||
classLoader.excludePackage("org.springframework.data.mapping.model");
|
||||
@@ -216,7 +219,7 @@ public class PersistentPropertyAccessorTests {
|
||||
|
||||
@Value
|
||||
|
||||
static class ValueClass {
|
||||
private static class ValueClass {
|
||||
@With String id;
|
||||
String immutable;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.mapping.model;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
import org.springframework.data.mapping.context.SamplePersistentProperty;
|
||||
@@ -28,10 +28,10 @@ import org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFac
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
public class PropertyAccessorClassGeneratorUnitTests {
|
||||
class PropertyAccessorClassGeneratorUnitTests {
|
||||
|
||||
@Test // DATACMNS-1602
|
||||
public void reusesAlreadyDeclaredClass() {
|
||||
void reusesAlreadyDeclaredClass() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Sample.class);
|
||||
@@ -42,5 +42,5 @@ public class PropertyAccessorClassGeneratorUnitTests {
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
static class Sample {}
|
||||
private static class Sample {}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import lombok.Value;
|
||||
import lombok.With;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -29,10 +29,10 @@ import org.springframework.util.ReflectionUtils;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class PropertyUnitTests {
|
||||
class PropertyUnitTests {
|
||||
|
||||
@Test // DATACMNS-1322
|
||||
public void shouldNotFindWitherMethod() {
|
||||
void shouldNotFindWitherMethod() {
|
||||
|
||||
assertThat(Property
|
||||
.of(ClassTypeInformation.from(ImmutableType.class), ReflectionUtils.findField(ImmutableType.class, "id"))
|
||||
@@ -43,7 +43,7 @@ public class PropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1322
|
||||
public void shouldDiscoverWitherMethod() {
|
||||
void shouldDiscoverWitherMethod() {
|
||||
|
||||
Property property = Property.of(ClassTypeInformation.from(WitherType.class),
|
||||
ReflectionUtils.findField(WitherType.class, "id"));
|
||||
@@ -55,7 +55,7 @@ public class PropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1421
|
||||
public void shouldDiscoverDerivedWitherMethod() {
|
||||
void shouldDiscoverDerivedWitherMethod() {
|
||||
|
||||
Property property = Property.of(ClassTypeInformation.from(DerivedWitherClass.class),
|
||||
ReflectionUtils.findField(DerivedWitherClass.class, "id"));
|
||||
@@ -68,7 +68,7 @@ public class PropertyUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1421
|
||||
public void shouldNotDiscoverWitherMethodWithIncompatibleReturnType() {
|
||||
void shouldNotDiscoverWitherMethodWithIncompatibleReturnType() {
|
||||
|
||||
Property property = Property.of(ClassTypeInformation.from(AnotherLevel.class),
|
||||
ReflectionUtils.findField(AnotherLevel.class, "id"));
|
||||
@@ -97,7 +97,7 @@ public class PropertyUnitTests {
|
||||
|
||||
@Value
|
||||
@With
|
||||
static class WitherType {
|
||||
private static class WitherType {
|
||||
|
||||
String id;
|
||||
String name;
|
||||
@@ -117,7 +117,7 @@ public class PropertyUnitTests {
|
||||
|
||||
private final String id;
|
||||
|
||||
protected DerivedWitherClass(String id) {
|
||||
DerivedWitherClass(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,11 @@ import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
@@ -43,28 +44,28 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Johannes Mockenhaupt
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<P>> {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<P>> {
|
||||
|
||||
@Mock PersistentEntity<?, P> entity;
|
||||
@Mock ParameterValueProvider<P> provider;
|
||||
|
||||
@Test
|
||||
public void instantiatesSimpleObjectCorrectly() {
|
||||
void instantiatesSimpleObjectCorrectly() {
|
||||
|
||||
doReturn(Object.class).when(entity).getType();
|
||||
INSTANCE.createInstance(entity, provider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantiatesArrayCorrectly() {
|
||||
void instantiatesArrayCorrectly() {
|
||||
|
||||
doReturn(String[][].class).when(entity).getType();
|
||||
INSTANCE.createInstance(entity, provider);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1126
|
||||
public void instantiatesTypeWithPreferredConstructorUsingParameterValueProvider() {
|
||||
void instantiatesTypeWithPreferredConstructorUsingParameterValueProvider() {
|
||||
|
||||
PreferredConstructor<Foo, P> constructor = PreferredConstructorDiscoverer.discover(Foo.class);
|
||||
|
||||
@@ -79,7 +80,7 @@ public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<
|
||||
|
||||
@Test // DATACMNS-300
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void throwsExceptionOnBeanInstantiationException() {
|
||||
void throwsExceptionOnBeanInstantiationException() {
|
||||
|
||||
doReturn(PersistentEntity.class).when(entity).getType();
|
||||
|
||||
@@ -88,7 +89,7 @@ public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<
|
||||
}
|
||||
|
||||
@Test // DATACMNS-134
|
||||
public void createsInnerClassInstanceCorrectly() {
|
||||
void createsInnerClassInstanceCorrectly() {
|
||||
|
||||
BasicPersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(from(Inner.class));
|
||||
assertThat(entity.getPersistenceConstructor()).satisfies(it -> {
|
||||
@@ -114,7 +115,7 @@ public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<
|
||||
|
||||
@Test // DATACMNS-283
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void capturesContextOnInstantiationException() throws Exception {
|
||||
void capturesContextOnInstantiationException() throws Exception {
|
||||
|
||||
PersistentEntity<Sample, P> entity = new BasicPersistentEntity<>(from(Sample.class));
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.mapping.AccessOptions;
|
||||
import org.springframework.data.mapping.AccessOptions.SetOptions.SetNulls;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
@@ -45,15 +45,15 @@ import org.springframework.data.mapping.context.SamplePersistentProperty;
|
||||
* @since 2.3
|
||||
* @soundtrack Ron Spielman Trio - Raindrops (Electric Tales)
|
||||
*/
|
||||
public class SimplePersistentPropertyPathAccessorUnitTests {
|
||||
class SimplePersistentPropertyPathAccessorUnitTests {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
private SampleMappingContext context = new SampleMappingContext();
|
||||
|
||||
Customer first = new Customer("1");
|
||||
Customer second = new Customer("2");
|
||||
private Customer first = new Customer("1");
|
||||
private Customer second = new Customer("2");
|
||||
|
||||
@Test // DATACMNS-1438
|
||||
public void setsPropertyContainingCollectionPathForAllElements() {
|
||||
void setsPropertyContainingCollectionPathForAllElements() {
|
||||
|
||||
Customers customers = new Customers(Arrays.asList(first, second), Collections.emptyMap());
|
||||
|
||||
@@ -61,7 +61,7 @@ public class SimplePersistentPropertyPathAccessorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1438
|
||||
public void setsPropertyContainingMapPathForAllValues() {
|
||||
void setsPropertyContainingMapPathForAllValues() {
|
||||
|
||||
Map<String, Customer> map = new HashMap<>();
|
||||
map.put("1", first);
|
||||
@@ -73,7 +73,7 @@ public class SimplePersistentPropertyPathAccessorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1461
|
||||
public void skipsNullValueIfConfigured() {
|
||||
void skipsNullValueIfConfigured() {
|
||||
|
||||
CustomerWrapper wrapper = new CustomerWrapper(null);
|
||||
|
||||
@@ -115,7 +115,7 @@ public class SimplePersistentPropertyPathAccessorUnitTests {
|
||||
}
|
||||
|
||||
@Value
|
||||
static class Customers {
|
||||
private static class Customers {
|
||||
@Wither List<Customer> customers;
|
||||
@Wither Map<String, Customer> customerMap;
|
||||
}
|
||||
|
||||
@@ -18,10 +18,11 @@ package org.springframework.data.mapping.model;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.data.mapping.PersistentProperty;
|
||||
|
||||
/**
|
||||
@@ -31,15 +32,15 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
* @author Oliver Gierke
|
||||
* @since 1.9
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SnakeCaseFieldNamingStrategyUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SnakeCaseFieldNamingStrategyUnitTests {
|
||||
|
||||
FieldNamingStrategy strategy = new SnakeCaseFieldNamingStrategy();
|
||||
private FieldNamingStrategy strategy = new SnakeCaseFieldNamingStrategy();
|
||||
|
||||
@Mock PersistentProperty<?> property;
|
||||
|
||||
@Test // DATACMNS-523
|
||||
public void rendersSnakeCaseFieldNames() {
|
||||
void rendersSnakeCaseFieldNames() {
|
||||
|
||||
assertFieldNameForPropertyName("fooBar", "foo_bar");
|
||||
assertFieldNameForPropertyName("FooBar", "foo_bar");
|
||||
|
||||
@@ -18,11 +18,14 @@ package org.springframework.data.mapping.model;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
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.core.convert.ConversionService;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.data.mapping.model.AbstractPersistentPropertyUnitTests.SamplePersistentProperty;
|
||||
@@ -33,20 +36,21 @@ import org.springframework.data.mapping.model.AbstractPersistentPropertyUnitTest
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SpelExpressionParameterProviderUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class SpelExpressionParameterProviderUnitTests {
|
||||
|
||||
@Mock SpELExpressionEvaluator evaluator;
|
||||
@Mock ParameterValueProvider<SamplePersistentProperty> delegate;
|
||||
@Mock ConversionService conversionService;
|
||||
|
||||
SpELExpressionParameterValueProvider<SamplePersistentProperty> provider;
|
||||
private SpELExpressionParameterValueProvider<SamplePersistentProperty> provider;
|
||||
|
||||
Parameter<Object, SamplePersistentProperty> parameter;
|
||||
private Parameter<Object, SamplePersistentProperty> parameter;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
provider = new SpELExpressionParameterValueProvider<>(evaluator, conversionService, delegate);
|
||||
|
||||
parameter = mock(Parameter.class);
|
||||
@@ -56,7 +60,7 @@ public class SpelExpressionParameterProviderUnitTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void delegatesIfParameterDoesNotHaveASpELExpression() {
|
||||
void delegatesIfParameterDoesNotHaveASpELExpression() {
|
||||
|
||||
Parameter<Object, SamplePersistentProperty> parameter = mock(Parameter.class);
|
||||
when(parameter.hasSpelExpression()).thenReturn(false);
|
||||
@@ -67,7 +71,7 @@ public class SpelExpressionParameterProviderUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evaluatesSpELExpression() {
|
||||
void evaluatesSpELExpression() {
|
||||
|
||||
when(parameter.getSpelExpression()).thenReturn("expression");
|
||||
|
||||
@@ -77,7 +81,7 @@ public class SpelExpressionParameterProviderUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handsSpELValueToConversionService() {
|
||||
void handsSpELValueToConversionService() {
|
||||
|
||||
doReturn("source").when(parameter).getSpelExpression();
|
||||
doReturn("value").when(evaluator).evaluate(any());
|
||||
@@ -89,7 +93,7 @@ public class SpelExpressionParameterProviderUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotConvertNullValue() {
|
||||
void doesNotConvertNullValue() {
|
||||
|
||||
doReturn("source").when(parameter).getSpelExpression();
|
||||
doReturn(null).when(evaluator).evaluate(any());
|
||||
@@ -101,7 +105,7 @@ public class SpelExpressionParameterProviderUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsMassagedObjectOnOverride() {
|
||||
void returnsMassagedObjectOnOverride() {
|
||||
|
||||
provider = new SpELExpressionParameterValueProvider<SamplePersistentProperty>(evaluator, conversionService,
|
||||
delegate) {
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
package org.springframework.data.projection;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.assertj.core.api.Assumptions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.MethodHandleLookup;
|
||||
import org.springframework.data.util.Version;
|
||||
|
||||
@@ -28,21 +28,21 @@ import org.springframework.data.util.Version;
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class DefaultMethodInvokingMethodInterceptorUnitTests {
|
||||
class DefaultMethodInvokingMethodInterceptorUnitTests {
|
||||
|
||||
@Test // DATACMNS-1376
|
||||
public void shouldApplyEncapsulatedLookupOnJava9AndHigher() {
|
||||
void shouldApplyEncapsulatedLookupOnJava9AndHigher() {
|
||||
|
||||
assumeTrue(Version.javaVersion().isGreaterThanOrEqualTo(Version.parse("9.0")));
|
||||
assumeThat(Version.javaVersion()).isGreaterThanOrEqualTo(Version.parse("9.0"));
|
||||
|
||||
assertThat(MethodHandleLookup.getMethodHandleLookup()).isEqualTo(MethodHandleLookup.ENCAPSULATED);
|
||||
assertThat(MethodHandleLookup.ENCAPSULATED.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1376
|
||||
public void shouldApplyOpenLookupOnJava8() {
|
||||
void shouldApplyOpenLookupOnJava8() {
|
||||
|
||||
assumeTrue(Version.javaVersion().isLessThan(Version.parse("1.8.9999")));
|
||||
assumeThat(Version.javaVersion()).isLessThan(Version.parse("1.8.9999"));
|
||||
|
||||
assertThat(MethodHandleLookup.getMethodHandleLookup()).isEqualTo(MethodHandleLookup.OPEN);
|
||||
assertThat(MethodHandleLookup.OPEN.isAvailable()).isTrue();
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.beans.PropertyDescriptor;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
/**
|
||||
@@ -31,10 +31,10 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class DefaultProjectionInformationUnitTests {
|
||||
class DefaultProjectionInformationUnitTests {
|
||||
|
||||
@Test // DATACMNS-89
|
||||
public void discoversInputProperties() {
|
||||
void discoversInputProperties() {
|
||||
|
||||
ProjectionInformation information = new DefaultProjectionInformation(CustomerProjection.class);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class DefaultProjectionInformationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1206
|
||||
public void omitsInputPropertiesAcceptingArguments() {
|
||||
void omitsInputPropertiesAcceptingArguments() {
|
||||
|
||||
ProjectionInformation information = new DefaultProjectionInformation(ProjectionAcceptingArguments.class);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class DefaultProjectionInformationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-89
|
||||
public void discoversAllInputProperties() {
|
||||
void discoversAllInputProperties() {
|
||||
|
||||
ProjectionInformation information = new DefaultProjectionInformation(ExtendedProjection.class);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class DefaultProjectionInformationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1206
|
||||
public void discoversInputPropertiesInOrder() {
|
||||
void discoversInputPropertiesInOrder() {
|
||||
|
||||
ProjectionInformation information = new DefaultProjectionInformation(SameMethodNamesInAlternateOrder.class);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class DefaultProjectionInformationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1206
|
||||
public void discoversAllInputPropertiesInOrder() {
|
||||
void discoversAllInputPropertiesInOrder() {
|
||||
|
||||
assertThat(toNames(new DefaultProjectionInformation(CompositeProjection.class).getInputProperties()))
|
||||
.containsExactly("firstname", "lastname", "age");
|
||||
@@ -75,7 +75,7 @@ public class DefaultProjectionInformationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-967
|
||||
public void doesNotConsiderDefaultMethodInputProperties() {
|
||||
void doesNotConsiderDefaultMethodInputProperties() {
|
||||
|
||||
ProjectionInformation information = new DefaultProjectionInformation(WithDefaultMethod.class);
|
||||
|
||||
|
||||
@@ -23,28 +23,28 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MapAccessingMethodInterceptor}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MapAccessingMethodInterceptorUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class MapAccessingMethodInterceptorUnitTests {
|
||||
|
||||
@Mock MethodInvocation invocation;
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void rejectsNullMap() {
|
||||
void rejectsNullMap() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new MapAccessingMethodInterceptor(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void forwardsObjectMethodsToBackingMap() throws Throwable {
|
||||
void forwardsObjectMethodsToBackingMap() throws Throwable {
|
||||
|
||||
Map<String, Object> map = Collections.emptyMap();
|
||||
|
||||
@@ -58,7 +58,7 @@ public class MapAccessingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void setterInvocationStoresValueInMap() throws Throwable {
|
||||
void setterInvocationStoresValueInMap() throws Throwable {
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
@@ -72,7 +72,7 @@ public class MapAccessingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void getterInvocationReturnsValueFromMap() throws Throwable {
|
||||
void getterInvocationReturnsValueFromMap() throws Throwable {
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", "Foo");
|
||||
@@ -85,7 +85,7 @@ public class MapAccessingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void getterReturnsNullIfMapDoesNotContainValue() throws Throwable {
|
||||
void getterReturnsNullIfMapDoesNotContainValue() throws Throwable {
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
@@ -95,7 +95,7 @@ public class MapAccessingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void rejectsNonAccessorInvocation() throws Throwable {
|
||||
void rejectsNonAccessorInvocation() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Sample.class.getMethod("someMethod"));
|
||||
assertThatIllegalArgumentException()
|
||||
|
||||
@@ -28,10 +28,11 @@ import java.util.Set;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
|
||||
@@ -42,8 +43,8 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||
* @author Saulo Medeiros de Araujo
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ProjectingMethodInterceptorUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ProjectingMethodInterceptorUnitTests {
|
||||
|
||||
@Mock MethodInterceptor interceptor;
|
||||
@Mock MethodInvocation invocation;
|
||||
@@ -51,7 +52,7 @@ public class ProjectingMethodInterceptorUnitTests {
|
||||
ConversionService conversionService = new DefaultConversionService();
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void wrapsDelegateResultInProxyIfTypesDontMatch() throws Throwable {
|
||||
void wrapsDelegateResultInProxyIfTypesDontMatch() throws Throwable {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
@@ -63,7 +64,7 @@ public class ProjectingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void retunsDelegateResultAsIsIfTypesMatch() throws Throwable {
|
||||
void retunsDelegateResultAsIsIfTypesMatch() throws Throwable {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(factory, interceptor, conversionService);
|
||||
|
||||
@@ -74,7 +75,7 @@ public class ProjectingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void returnsNullAsIs() throws Throwable {
|
||||
void returnsNullAsIs() throws Throwable {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(factory, interceptor, conversionService);
|
||||
|
||||
@@ -84,7 +85,7 @@ public class ProjectingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void considersPrimitivesAsWrappers() throws Throwable {
|
||||
void considersPrimitivesAsWrappers() throws Throwable {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(factory, interceptor, conversionService);
|
||||
|
||||
@@ -97,7 +98,7 @@ public class ProjectingMethodInterceptorUnitTests {
|
||||
|
||||
@Test // DATAREST-394, DATAREST-408
|
||||
@SuppressWarnings("unchecked")
|
||||
public void appliesProjectionToNonEmptySets() throws Throwable {
|
||||
void appliesProjectionToNonEmptySets() throws Throwable {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
@@ -112,7 +113,7 @@ public class ProjectingMethodInterceptorUnitTests {
|
||||
|
||||
@Test // DATAREST-394, DATAREST-408
|
||||
@SuppressWarnings("unchecked")
|
||||
public void appliesProjectionToNonEmptyLists() throws Throwable {
|
||||
void appliesProjectionToNonEmptyLists() throws Throwable {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
@@ -128,7 +129,7 @@ public class ProjectingMethodInterceptorUnitTests {
|
||||
|
||||
@Test // DATAREST-394, DATAREST-408
|
||||
@SuppressWarnings("unchecked")
|
||||
public void allowsMaskingAnArrayIntoACollection() throws Throwable {
|
||||
void allowsMaskingAnArrayIntoACollection() throws Throwable {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
@@ -143,7 +144,7 @@ public class ProjectingMethodInterceptorUnitTests {
|
||||
|
||||
@Test // DATAREST-394, DATAREST-408
|
||||
@SuppressWarnings("unchecked")
|
||||
public void appliesProjectionToNonEmptyMap() throws Throwable {
|
||||
void appliesProjectionToNonEmptyMap() throws Throwable {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
@@ -159,7 +160,7 @@ public class ProjectingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsSingleElementCollectionForTargetThatReturnsNonCollection() throws Throwable {
|
||||
void returnsSingleElementCollectionForTargetThatReturnsNonCollection() throws Throwable {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
@@ -175,7 +176,7 @@ public class ProjectingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1598
|
||||
public void returnsEnumSet() throws Throwable {
|
||||
void returnsEnumSet() throws Throwable {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.projection;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jayway.jsonpath.Configuration.ConfigurationBuilder;
|
||||
@@ -31,10 +31,10 @@ import com.jayway.jsonpath.ParseContext;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ProjectionIntegrationTests {
|
||||
class ProjectionIntegrationTests {
|
||||
|
||||
@Test // DATACMNS-909
|
||||
public void jacksonSerializationDoesNotExposeDecoratedClass() throws Exception {
|
||||
void jacksonSerializationDoesNotExposeDecoratedClass() throws Exception {
|
||||
|
||||
ProxyProjectionFactory factory = new ProxyProjectionFactory();
|
||||
SampleProjection projection = factory.createProjection(SampleProjection.class);
|
||||
|
||||
@@ -20,10 +20,11 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.beans.NotReadablePropertyException;
|
||||
import org.springframework.beans.NotWritablePropertyException;
|
||||
|
||||
@@ -33,13 +34,13 @@ import org.springframework.beans.NotWritablePropertyException;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PropertyAccessingMethodInterceptorUnitTests {
|
||||
|
||||
@Mock MethodInvocation invocation;
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void triggersPropertyAccessOnTarget() throws Throwable {
|
||||
void triggersPropertyAccessOnTarget() throws Throwable {
|
||||
|
||||
Source source = new Source();
|
||||
source.firstname = "Dave";
|
||||
@@ -51,7 +52,7 @@ public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void throwsAppropriateExceptionIfThePropertyCannotBeFound() throws Throwable {
|
||||
void throwsAppropriateExceptionIfThePropertyCannotBeFound() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("getLastname"));
|
||||
assertThatExceptionOfType(NotReadablePropertyException.class)
|
||||
@@ -59,7 +60,7 @@ public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void forwardsObjectMethodInvocation() throws Throwable {
|
||||
void forwardsObjectMethodInvocation() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Object.class.getMethod("toString"));
|
||||
|
||||
@@ -67,7 +68,7 @@ public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void rejectsNonAccessorMethod() throws Throwable {
|
||||
void rejectsNonAccessorMethod() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("someGarbage"));
|
||||
|
||||
@@ -76,7 +77,7 @@ public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-820
|
||||
public void triggersWritePropertyAccessOnTarget() throws Throwable {
|
||||
void triggersWritePropertyAccessOnTarget() throws Throwable {
|
||||
|
||||
Source source = new Source();
|
||||
source.firstname = "Dave";
|
||||
@@ -90,7 +91,7 @@ public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-820
|
||||
public void throwsAppropriateExceptionIfTheInvocationHasNoArguments() throws Throwable {
|
||||
void throwsAppropriateExceptionIfTheInvocationHasNoArguments() throws Throwable {
|
||||
|
||||
Source source = new Source();
|
||||
|
||||
@@ -102,7 +103,7 @@ public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-820
|
||||
public void throwsAppropriateExceptionIfThePropertyCannotWritten() throws Throwable {
|
||||
void throwsAppropriateExceptionIfThePropertyCannotWritten() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setGarbage", String.class));
|
||||
when(invocation.getArguments()).thenReturn(new Object[] { "Carl" });
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.TargetClassAware;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
@@ -35,31 +35,31 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ProxyProjectionFactoryUnitTests {
|
||||
class ProxyProjectionFactoryUnitTests {
|
||||
|
||||
ProjectionFactory factory = new ProxyProjectionFactory();
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("null")
|
||||
// DATACMNS-630
|
||||
public void rejectsNullProjectionType() {
|
||||
void rejectsNullProjectionType() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factory.createProjection(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("null")
|
||||
// DATACMNS-630
|
||||
public void rejectsNullProjectionTypeWithSource() {
|
||||
void rejectsNullProjectionTypeWithSource() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factory.createProjection(null, new Object()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void returnsNullForNullSource() {
|
||||
void returnsNullForNullSource() {
|
||||
assertThat(factory.createNullableProjection(CustomerExcerpt.class, null)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-221, DATACMNS-630
|
||||
public void createsProjectingProxy() {
|
||||
void createsProjectingProxy() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
@@ -76,7 +76,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221, DATACMNS-630
|
||||
public void proxyExposesTargetClassAware() {
|
||||
void proxyExposesTargetClassAware() {
|
||||
|
||||
CustomerExcerpt proxy = factory.createProjection(CustomerExcerpt.class);
|
||||
|
||||
@@ -85,12 +85,12 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221, DATACMNS-630
|
||||
public void rejectsNonInterfacesAsProjectionTarget() {
|
||||
void rejectsNonInterfacesAsProjectionTarget() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factory.createProjection(Object.class, new Object()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void createsMapBasedProxyFromSource() {
|
||||
void createsMapBasedProxyFromSource() {
|
||||
|
||||
HashMap<String, Object> addressSource = new HashMap<>();
|
||||
addressSource.put("zipCode", "ZIP");
|
||||
@@ -111,7 +111,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void createsEmptyMapBasedProxy() {
|
||||
void createsEmptyMapBasedProxy() {
|
||||
|
||||
CustomerProxy proxy = factory.createProjection(CustomerProxy.class);
|
||||
|
||||
@@ -122,7 +122,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void returnsAllPropertiesAsInputProperties() {
|
||||
void returnsAllPropertiesAsInputProperties() {
|
||||
|
||||
ProjectionInformation projectionInformation = factory.getProjectionInformation(CustomerExcerpt.class);
|
||||
List<PropertyDescriptor> result = projectionInformation.getInputProperties();
|
||||
@@ -131,7 +131,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-655
|
||||
public void invokesDefaultMethodOnProxy() {
|
||||
void invokesDefaultMethodOnProxy() {
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class);
|
||||
|
||||
@@ -143,7 +143,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-648
|
||||
public void exposesProxyTarget() {
|
||||
void exposesProxyTarget() {
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class);
|
||||
|
||||
@@ -152,7 +152,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-722
|
||||
public void doesNotProjectPrimitiveArray() {
|
||||
void doesNotProjectPrimitiveArray() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.picture = "binarydata".getBytes();
|
||||
@@ -163,7 +163,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-722
|
||||
public void projectsNonPrimitiveArray() {
|
||||
void projectsNonPrimitiveArray() {
|
||||
|
||||
Address address = new Address();
|
||||
address.city = "New York";
|
||||
@@ -178,7 +178,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-782
|
||||
public void convertsPrimitiveValues() {
|
||||
void convertsPrimitiveValues() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.id = 1L;
|
||||
@@ -189,7 +189,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-89
|
||||
public void exposesProjectionInformationCorrectly() {
|
||||
void exposesProjectionInformationCorrectly() {
|
||||
|
||||
ProjectionInformation information = factory.getProjectionInformation(CustomerExcerpt.class);
|
||||
|
||||
@@ -198,7 +198,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-829
|
||||
public void projectsMapOfStringToObjectCorrectly() {
|
||||
void projectsMapOfStringToObjectCorrectly() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.data = Collections.singletonMap("key", null);
|
||||
@@ -211,7 +211,7 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1121
|
||||
public void doesNotCreateWrappingProxyIfTargetImplementsProjectionInterface() {
|
||||
void doesNotCreateWrappingProxyIfTargetImplementsProjectionInterface() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
|
||||
@@ -222,17 +222,17 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
|
||||
static class Customer implements Contact {
|
||||
|
||||
public Long id;
|
||||
public String firstname, lastname;
|
||||
public Address address;
|
||||
public byte[] picture;
|
||||
public Address[] shippingAddresses;
|
||||
public Map<String, Object> data;
|
||||
Long id;
|
||||
String firstname, lastname;
|
||||
Address address;
|
||||
byte[] picture;
|
||||
Address[] shippingAddresses;
|
||||
Map<String, Object> data;
|
||||
}
|
||||
|
||||
static class Address {
|
||||
|
||||
public String zipCode, city;
|
||||
String zipCode, city;
|
||||
}
|
||||
|
||||
interface CustomerExcerpt {
|
||||
|
||||
@@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.NotWritablePropertyException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -33,17 +33,17 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
|
||||
SpelAwareProxyProjectionFactory factory;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
factory = new SpelAwareProxyProjectionFactory();
|
||||
}
|
||||
|
||||
@Test // DATAREST-221, DATACMNS-630
|
||||
public void exposesSpelInvokingMethod() {
|
||||
void exposesSpelInvokingMethod() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
@@ -54,7 +54,7 @@ public class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void excludesAtValueAnnotatedMethodsForInputProperties() {
|
||||
void excludesAtValueAnnotatedMethodsForInputProperties() {
|
||||
|
||||
List<PropertyDescriptor> properties = factory //
|
||||
.getProjectionInformation(CustomerExcerpt.class) //
|
||||
@@ -66,7 +66,7 @@ public class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-89
|
||||
public void considersProjectionUsingAtValueNotClosed() {
|
||||
void considersProjectionUsingAtValueNotClosed() {
|
||||
|
||||
ProjectionInformation information = factory.getProjectionInformation(CustomerExcerpt.class);
|
||||
|
||||
@@ -74,7 +74,7 @@ public class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-820
|
||||
public void setsValueUsingProjection() {
|
||||
void setsValueUsingProjection() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
@@ -86,7 +86,7 @@ public class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-820
|
||||
public void settingNotWriteablePropertyFails() {
|
||||
void settingNotWriteablePropertyFails() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
|
||||
@@ -23,10 +23,11 @@ import java.util.Map;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
@@ -37,8 +38,8 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
|
||||
@Mock MethodInterceptor delegate;
|
||||
@Mock MethodInvocation invocation;
|
||||
@@ -46,7 +47,7 @@ public class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
|
||||
@Test // DATAREST-221, DATACMNS-630
|
||||
public void invokesMethodOnTarget() throws Throwable {
|
||||
void invokesMethodOnTarget() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("propertyFromTarget"));
|
||||
|
||||
@@ -57,7 +58,7 @@ public class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221, DATACMNS-630
|
||||
public void invokesMethodOnBean() throws Throwable {
|
||||
void invokesMethodOnBean() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("invokeBean"));
|
||||
|
||||
@@ -71,7 +72,7 @@ public class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void forwardNonAtValueAnnotatedMethodToDelegate() throws Throwable {
|
||||
void forwardNonAtValueAnnotatedMethodToDelegate() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("getName"));
|
||||
|
||||
@@ -84,13 +85,13 @@ public class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void rejectsEmptySpelExpression() {
|
||||
void rejectsEmptySpelExpression() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> new SpelEvaluatingMethodInterceptor(delegate, new Target(),
|
||||
new DefaultListableBeanFactory(), parser, InvalidProjection.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void allowsMapAccessViaPropertyExpression() throws Throwable {
|
||||
void allowsMapAccessViaPropertyExpression() throws Throwable {
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", "Dave");
|
||||
@@ -104,7 +105,7 @@ public class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1150
|
||||
public void forwardsParameterIntoSpElExpressionEvaluation() throws Throwable {
|
||||
void forwardsParameterIntoSpElExpressionEvaluation() throws Throwable {
|
||||
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
factory.registerSingleton("someBean", new SomeBean());
|
||||
|
||||
@@ -17,7 +17,8 @@ package org.springframework.data.querydsl;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.domain.AbstractPageRequest;
|
||||
import org.springframework.data.domain.AbstractPageRequestUnitTests;
|
||||
|
||||
@@ -25,6 +26,7 @@ import org.springframework.data.domain.AbstractPageRequestUnitTests;
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class QPageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.domain.AbstractPageRequestUnitTests#newPageRequest(int, int)
|
||||
@@ -35,7 +37,7 @@ public class QPageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructsQPageRequestWithOrderSpecifiers() {
|
||||
void constructsQPageRequestWithOrderSpecifiers() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QPageRequest pageRequest = QPageRequest.of(0, 10, user.firstname.asc());
|
||||
@@ -44,7 +46,7 @@ public class QPageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructsQPageRequestWithQSort() {
|
||||
void constructsQPageRequestWithQSort() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QPageRequest pageRequest = QPageRequest.of(0, 10, QSort.by(user.firstname.asc()));
|
||||
@@ -53,7 +55,7 @@ public class QPageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1581
|
||||
public void rejectsNullSort() {
|
||||
void rejectsNullSort() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
.isThrownBy(() -> QPageRequest.of(0, 10, (QSort) null));
|
||||
|
||||
@@ -22,7 +22,7 @@ import static org.springframework.data.querydsl.QQSortUnitTests_WrapperToWrapWra
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
@@ -40,15 +40,15 @@ import com.querydsl.core.types.dsl.StringPath;
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class QSortUnitTests {
|
||||
class QSortUnitTests {
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void shouldThrowIfNullIsGiven() {
|
||||
void shouldThrowIfNullIsGiven() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new QSort((List<OrderSpecifier<?>>) null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void sortBySingleProperty() {
|
||||
void sortBySingleProperty() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort qsort = new QSort(user.firstname.asc());
|
||||
@@ -59,7 +59,7 @@ public class QSortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void sortByMultiplyProperties() {
|
||||
void sortByMultiplyProperties() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort qsort = new QSort(user.firstname.asc(), user.lastname.desc());
|
||||
@@ -72,7 +72,7 @@ public class QSortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void sortByMultiplyPropertiesWithAnd() {
|
||||
void sortByMultiplyPropertiesWithAnd() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort qsort = new QSort(user.firstname.asc()).and(new QSort(user.lastname.desc()));
|
||||
@@ -85,7 +85,7 @@ public class QSortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void sortByMultiplyPropertiesWithAndAndVarArgs() {
|
||||
void sortByMultiplyPropertiesWithAndAndVarArgs() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort qsort = new QSort(user.firstname.asc()).and(user.lastname.desc());
|
||||
@@ -98,7 +98,7 @@ public class QSortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void ensureInteroperabilityWithSort() {
|
||||
void ensureInteroperabilityWithSort() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort qsort = new QSort(user.firstname.asc(), user.lastname.desc());
|
||||
@@ -110,7 +110,7 @@ public class QSortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
public void concatenatesPlainSortCorrectly() {
|
||||
void concatenatesPlainSortCorrectly() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort sort = new QSort(user.firstname.asc());
|
||||
@@ -121,7 +121,7 @@ public class QSortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-566
|
||||
public void shouldSupportSortByOperatorExpressions() {
|
||||
void shouldSupportSortByOperatorExpressions() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort sort = new QSort(user.dateOfBirth.yearMonth().asc());
|
||||
@@ -133,7 +133,7 @@ public class QSortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-621
|
||||
public void shouldCreateSortForNestedPathCorrectly() {
|
||||
void shouldCreateSortForNestedPathCorrectly() {
|
||||
|
||||
QSort sort = new QSort(userWrapper.user.firstname.asc());
|
||||
|
||||
@@ -141,7 +141,7 @@ public class QSortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-621
|
||||
public void shouldCreateSortForDeepNestedPathCorrectly() {
|
||||
void shouldCreateSortForDeepNestedPathCorrectly() {
|
||||
|
||||
QSort sort = new QSort(wrapperForUserWrapper.wrapper.user.firstname.asc());
|
||||
|
||||
@@ -149,7 +149,7 @@ public class QSortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-621
|
||||
public void shouldCreateSortForReallyDeepNestedPathCorrectly() {
|
||||
void shouldCreateSortForReallyDeepNestedPathCorrectly() {
|
||||
|
||||
QSort sort = new QSort(wrapperToWrapWrapperForUserWrapper.wrapperForUserWrapper.wrapper.user.firstname.asc());
|
||||
|
||||
@@ -157,7 +157,7 @@ public class QSortUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-755
|
||||
public void handlesPlainStringPathsCorrectly() {
|
||||
void handlesPlainStringPathsCorrectly() {
|
||||
|
||||
StringPath path = new PathBuilderFactory().create(User.class).getString("firstname");
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
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.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.repository.support.RepositoryInvoker;
|
||||
@@ -36,8 +37,8 @@ import com.querydsl.core.types.Predicate;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack Emilie Nicolas - Grown Up
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class QuerydslRepositoryInvokerAdapterUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class QuerydslRepositoryInvokerAdapterUnitTests {
|
||||
|
||||
@Mock RepositoryInvoker delegate;
|
||||
@Mock QuerydslPredicateExecutor<Object> executor;
|
||||
@@ -45,13 +46,13 @@ public class QuerydslRepositoryInvokerAdapterUnitTests {
|
||||
|
||||
QuerydslRepositoryInvokerAdapter adapter;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.adapter = new QuerydslRepositoryInvokerAdapter(delegate, executor, predicate);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void forwardsFindAllToExecutorWithPredicate() {
|
||||
void forwardsFindAllToExecutorWithPredicate() {
|
||||
|
||||
Sort sort = Sort.by("firstname");
|
||||
adapter.invokeFindAll(sort);
|
||||
@@ -61,7 +62,7 @@ public class QuerydslRepositoryInvokerAdapterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void forwardsFindAllWithPageableToExecutorWithPredicate() {
|
||||
void forwardsFindAllWithPageableToExecutorWithPredicate() {
|
||||
|
||||
PageRequest pageable = PageRequest.of(0, 10);
|
||||
adapter.invokeFindAll(pageable);
|
||||
@@ -72,7 +73,7 @@ public class QuerydslRepositoryInvokerAdapterUnitTests {
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@SuppressWarnings("unchecked")
|
||||
public void forwardsMethodsToDelegate() {
|
||||
void forwardsMethodsToDelegate() {
|
||||
|
||||
adapter.hasDeleteMethod();
|
||||
verify(delegate, times(1)).hasDeleteMethod();
|
||||
|
||||
@@ -18,22 +18,22 @@ package org.springframework.data.querydsl;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.querydsl.QuerydslUtils.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link QuerydslUtils}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class QuerydslUtilsUnitTests {
|
||||
class QuerydslUtilsUnitTests {
|
||||
|
||||
@Test // DATACMNS-883
|
||||
public void rendersDotPathForPathTraversalContainingAnyExpression() {
|
||||
void rendersDotPathForPathTraversalContainingAnyExpression() {
|
||||
assertThat(QuerydslUtils.toDotPath(QUser.user.addresses.any().street)).isEqualTo("addresses.street");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-941
|
||||
public void skipsIntermediateDelegates() {
|
||||
void skipsIntermediateDelegates() {
|
||||
|
||||
assertThat(toDotPath(QUser.user.as(QSpecialUser.class).as(QSpecialUser.class).specialProperty))
|
||||
.isEqualTo("specialProperty");
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.querydsl;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.querydsl.core.annotations.QueryEntity;
|
||||
|
||||
@@ -27,28 +27,28 @@ import com.querydsl.core.annotations.QueryEntity;
|
||||
* @author Oliver Gierke
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public class SimpleEntityPathResolverUnitTests {
|
||||
class SimpleEntityPathResolverUnitTests {
|
||||
|
||||
EntityPathResolver resolver = SimpleEntityPathResolver.INSTANCE;
|
||||
|
||||
@Test
|
||||
public void createsRepositoryFromDomainClassCorrectly() throws Exception {
|
||||
void createsRepositoryFromDomainClassCorrectly() throws Exception {
|
||||
assertThat(resolver.createPath(User.class)).isInstanceOf(QUser.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolvesEntityPathForInnerClassCorrectly() throws Exception {
|
||||
void resolvesEntityPathForInnerClassCorrectly() throws Exception {
|
||||
assertThat(resolver.createPath(NamedUser.class)).isInstanceOf(QSimpleEntityPathResolverUnitTests_NamedUser.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsClassWithoutQueryClassConfrmingToTheNamingScheme() {
|
||||
void rejectsClassWithoutQueryClassConfrmingToTheNamingScheme() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> resolver.createPath(QSimpleEntityPathResolverUnitTests_Sample.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1235
|
||||
public void handlesPackageSuffixCorrectly() {
|
||||
void handlesPackageSuffixCorrectly() {
|
||||
assertThat(new SimpleEntityPathResolver(".suffix").createPath(User.class))
|
||||
.isInstanceOf(org.springframework.data.querydsl.suffix.QUser.class);
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import static org.mockito.Mockito.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.data.querydsl.QUser;
|
||||
import org.springframework.data.querydsl.SimpleEntityPathResolver;
|
||||
@@ -42,20 +42,20 @@ import com.querydsl.core.types.Predicate;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack Miles Davis - All Blues (Kind of Blue)
|
||||
*/
|
||||
public class QuerydslBindingsFactoryUnitTests {
|
||||
class QuerydslBindingsFactoryUnitTests {
|
||||
|
||||
static final TypeInformation<?> USER_TYPE = ClassTypeInformation.from(User.class);
|
||||
|
||||
QuerydslBindingsFactory factory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.factory = new QuerydslBindingsFactory(SimpleEntityPathResolver.INSTANCE);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void createBindingsShouldHonorQuerydslBinderCustomizerHookWhenPresent() {
|
||||
void createBindingsShouldHonorQuerydslBinderCustomizerHookWhenPresent() {
|
||||
|
||||
Repositories repositories = mock(Repositories.class);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class QuerydslBindingsFactoryUnitTests {
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void shouldReuseExistingQuerydslBinderCustomizer() {
|
||||
void shouldReuseExistingQuerydslBinderCustomizer() {
|
||||
|
||||
AutowireCapableBeanFactory beanFactory = mock(AutowireCapableBeanFactory.class);
|
||||
when(beanFactory.getBean(SpecificBinding.class)).thenReturn(new SpecificBinding());
|
||||
@@ -96,7 +96,7 @@ public class QuerydslBindingsFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void rejectsPredicateResolutionIfDomainTypeCantBeAutoDetected() {
|
||||
void rejectsPredicateResolutionIfDomainTypeCantBeAutoDetected() {
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class)//
|
||||
.isThrownBy(() -> factory.createBindingsFor(ClassTypeInformation.from(ModelAndView.class)))//
|
||||
@@ -116,7 +116,7 @@ public class QuerydslBindingsFactoryUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
public static class SampleRepo implements QuerydslBinderCustomizer<QUser> {
|
||||
static class SampleRepo implements QuerydslBinderCustomizer<QUser> {
|
||||
|
||||
@Override
|
||||
public void customize(QuerydslBindings bindings, QUser user) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user