Switch to JUnit 5.

Issue #2075.
This commit is contained in:
Oliver Drotbohm
2021-10-12 22:14:05 +02:00
parent 3d03b0cbe6
commit 5f4e24b912
125 changed files with 1607 additions and 1554 deletions

View File

@@ -15,13 +15,13 @@
*/
package org.springframework.data.rest.core;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.core.domain.Person;
import org.springframework.data.rest.core.domain.PersonRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Base class for integration tests loading {@link RepositoryTestsConfig} and populating the {@link PersonRepository}
@@ -29,14 +29,14 @@ import org.springframework.test.context.junit4.SpringRunner;
*
* @author Oliver Gierke
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = RepositoryTestsConfig.class)
public abstract class AbstractIntegrationTests {
@Autowired PersonRepository repository;
@Before
public void populateDatabase() {
@BeforeEach
void populateDatabase() {
repository.save(new Person("John", "Doe"));
}
}

View File

@@ -17,63 +17,63 @@ package org.springframework.data.rest.core;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link Path}.
*
* @author Oliver Gierke
*/
public class PathUnitTests {
class PathUnitTests {
@Test
public void combinesSimplePaths() {
void combinesSimplePaths() {
Path builder = new Path("foo").slash("bar");
assertThat(builder.toString()).isEqualTo("/foo/bar");
}
@Test
public void removesLeadingAndTrailingSlashes() {
void removesLeadingAndTrailingSlashes() {
Path builder = new Path("foo/").slash("/bar").slash("//foobar///");
assertThat(builder.toString()).isEqualTo("/foo/bar/foobar");
}
@Test
public void removesWhitespace() {
void removesWhitespace() {
Path builder = new Path("foo/ ").slash("/ b a r").slash(" //foobar/// ");
assertThat(builder.toString()).isEqualTo("/foo/bar/foobar");
}
@Test
public void matchesWithLeadingSlash() {
void matchesWithLeadingSlash() {
assertThat(new Path("/foobar").matches("/foobar")).isTrue();
}
@Test
public void matchesWithoutLeadingSlash() {
void matchesWithoutLeadingSlash() {
assertThat(new Path("/foobar").matches("foobar")).isTrue();
}
@Test
public void doesNotMatchIfDifferent() {
void doesNotMatchIfDifferent() {
assertThat(new Path("/foobar").matches("barfoo")).isFalse();
}
@Test
public void doesNotPrefixAbsoluteUris() {
void doesNotPrefixAbsoluteUris() {
assertThat(new Path("http://localhost").toString()).isEqualTo("http://localhost");
}
@Test // DATAREST-222
public void doesNotMatchIfReferenceContainsReservedCharacters() {
void doesNotMatchIfReferenceContainsReservedCharacters() {
assertThat(new Path("/foobar").matches("barfoo{?foo}")).isFalse();
}
@Test // DATAREST-222
public void doesNotMatchNullReference() {
void doesNotMatchNullReference() {
assertThat(new Path("/foobar").matches(null)).isFalse();
}
}

View File

@@ -17,7 +17,7 @@ package org.springframework.data.rest.core;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
@@ -36,13 +36,13 @@ import org.springframework.test.annotation.DirtiesContext;
* @author Oliver Gierke
*/
@SuppressWarnings("deprecation")
public class RepositoryRestConfigurationIntegrationTests extends AbstractIntegrationTests {
class RepositoryRestConfigurationIntegrationTests extends AbstractIntegrationTests {
@Autowired RepositoryRestConfiguration config;
@Autowired Repositories repositories;
@Test
public void shouldProvideResourceMappingForConfiguredRepository() throws Exception {
void shouldProvideResourceMappingForConfiguredRepository() throws Exception {
ResourceMapping mapping = config.getResourceMappingForRepository(ConfiguredPersonRepository.class);
@@ -54,7 +54,7 @@ public class RepositoryRestConfigurationIntegrationTests extends AbstractIntegra
@Test // DATAREST-1304
@DirtiesContext
public void exposesLookupPropertyFromLambda() {
void exposesLookupPropertyFromLambda() {
config.withEntityLookup() //
.forRepository(ProfileRepository.class) //

View File

@@ -18,8 +18,8 @@ package org.springframework.data.rest.core;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.rest.core.config.EnumTranslationConfiguration;
import org.springframework.data.rest.core.config.MetadataConfiguration;
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
@@ -37,40 +37,40 @@ import org.springframework.http.MediaType;
* @author Mark Paluch
* @soundtrack Adam F - Circles (Colors)
*/
public class RepositoryRestConfigurationUnitTests {
class RepositoryRestConfigurationUnitTests {
RepositoryRestConfiguration configuration;
@Before
public void setUp() {
@BeforeEach
void setUp() {
this.configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
}
@Test // DATAREST-34
public void returnsBodiesIfAcceptHeaderPresentByDefault() {
void returnsBodiesIfAcceptHeaderPresentByDefault() {
assertThat(configuration.returnBodyOnCreate(MediaType.APPLICATION_JSON_VALUE)).isTrue();
assertThat(configuration.returnBodyOnUpdate(MediaType.APPLICATION_JSON_VALUE)).isTrue();
}
@Test // DATAREST-34
public void doesNotReturnBodiesIfNoAcceptHeaderPresentByDefault() {
void doesNotReturnBodiesIfNoAcceptHeaderPresentByDefault() {
assertThat(configuration.returnBodyOnCreate(null)).isFalse();
assertThat(configuration.returnBodyOnUpdate(null)).isFalse();
}
@Test // DATAREST-34
public void doesNotReturnBodiesIfEmptyAcceptHeaderPresentByDefault() {
void doesNotReturnBodiesIfEmptyAcceptHeaderPresentByDefault() {
assertThat(configuration.returnBodyOnCreate("")).isFalse();
assertThat(configuration.returnBodyOnUpdate("")).isFalse();
}
@Test // DATAREST-34
public void doesNotReturnBodyForUpdateIfExplicitlyDeactivated() {
void doesNotReturnBodyForUpdateIfExplicitlyDeactivated() {
configuration.setReturnBodyOnUpdate(false);
@@ -80,7 +80,7 @@ public class RepositoryRestConfigurationUnitTests {
}
@Test // DATAREST-34
public void doesNotReturnBodyForCreateIfExplicitlyDeactivated() {
void doesNotReturnBodyForCreateIfExplicitlyDeactivated() {
configuration.setReturnBodyOnCreate(false);
@@ -90,7 +90,7 @@ public class RepositoryRestConfigurationUnitTests {
}
@Test // DATAREST-34
public void returnsBodyForUpdateIfExplicitlyActivated() {
void returnsBodyForUpdateIfExplicitlyActivated() {
configuration.setReturnBodyOnUpdate(true);
@@ -100,7 +100,7 @@ public class RepositoryRestConfigurationUnitTests {
}
@Test // DATAREST-34
public void returnsBodyForCreateIfExplicitlyActivated() {
void returnsBodyForCreateIfExplicitlyActivated() {
configuration.setReturnBodyOnCreate(true);
@@ -110,7 +110,7 @@ public class RepositoryRestConfigurationUnitTests {
}
@Test // DATAREST-776
public void considersDomainTypeOfValueRepositoryLookupTypes() {
void considersDomainTypeOfValueRepositoryLookupTypes() {
configuration.withEntityLookup().forLookupRepository(ProfileRepository.class);
@@ -118,13 +118,13 @@ public class RepositoryRestConfigurationUnitTests {
}
@Test // DATAREST-1076
public void rejectsNullRelProvider() {
void rejectsNullRelProvider() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> configuration.setLinkRelationProvider(null));
}
@Test // #1974
public void considersAtRelationOnTypesByDefault() {
void considersAtRelationOnTypesByDefault() {
assertThat(configuration.getLinkRelationProvider().getItemResourceRelFor(Sample.class))
.isEqualTo(LinkRelation.of("something"));
}

View File

@@ -21,7 +21,7 @@ import javax.naming.InvalidNameException;
import javax.naming.Name;
import javax.naming.ldap.LdapName;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.support.DefaultConversionService;
/**
@@ -29,10 +29,10 @@ import org.springframework.core.convert.support.DefaultConversionService;
*
* @author Mark Paluch
*/
public class StringToLdapNameConverterUnitTests {
class StringToLdapNameConverterUnitTests {
@Test // DATAREST-1198
public void shouldCreateLdapName() throws InvalidNameException {
void shouldCreateLdapName() throws InvalidNameException {
LdapName converted = StringToLdapNameConverter.INSTANCE.convert("dc=foo");
@@ -40,14 +40,14 @@ public class StringToLdapNameConverterUnitTests {
}
@Test // DATAREST-1198
public void failedConversionShouldThrowIAE() {
void failedConversionShouldThrowIAE() {
assertThatThrownBy(() -> StringToLdapNameConverter.INSTANCE.convert("foo"))
.isInstanceOf(IllegalArgumentException.class);
}
@Test // DATAREST-1198
public void shouldConvertStringInNameViaConversionService() {
void shouldConvertStringInNameViaConversionService() {
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(StringToLdapNameConverter.INSTANCE);

View File

@@ -24,11 +24,11 @@ import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
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.ConversionFailedException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair;
@@ -47,8 +47,8 @@ import org.springframework.data.util.Streamable;
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class UriToEntityConverterUnitTests {
@ExtendWith(MockitoExtension.class)
class UriToEntityConverterUnitTests {
static final TypeDescriptor URI_TYPE = TypeDescriptor.valueOf(URI.class);
static final TypeDescriptor STRING_TYPE = TypeDescriptor.valueOf(String.class);
@@ -60,8 +60,8 @@ public class UriToEntityConverterUnitTests {
KeyValueMappingContext<?, ?> context;
UriToEntityConverter converter;
@Before
public void setUp() {
@BeforeEach
void setUp() {
this.context = new KeyValueMappingContext<>();
this.context.setInitialEntitySet(new HashSet<Class<?>>(Arrays.asList(Entity.class, NonEntity.class)));
@@ -72,7 +72,7 @@ public class UriToEntityConverterUnitTests {
}
@Test // DATAREST-427
public void supportsOnlyEntitiesWithIdProperty() {
void supportsOnlyEntitiesWithIdProperty() {
Set<ConvertiblePair> result = converter.getConvertibleTypes();
@@ -81,12 +81,12 @@ public class UriToEntityConverterUnitTests {
}
@Test // DATAREST-427
public void cannotConvertEntityWithIdPropertyIfStringConversionMissing() {
void cannotConvertEntityWithIdPropertyIfStringConversionMissing() {
assertThat(converter.matches(URI_TYPE, ENTITY_TYPE)).isFalse();
}
@Test // DATAREST-427
public void canConvertEntityWithIdPropertyAndFromStringConversionPossible() {
void canConvertEntityWithIdPropertyAndFromStringConversionPossible() {
doReturn(Optional.of(mock(RepositoryInformation.class))).when(repositories)
.getRepositoryInformationFor(ENTITY_TYPE.getType());
@@ -95,12 +95,12 @@ public class UriToEntityConverterUnitTests {
}
@Test // DATAREST-427
public void cannotConvertEntityWithoutIdentifier() {
void cannotConvertEntityWithoutIdentifier() {
assertThat(converter.matches(URI_TYPE, TypeDescriptor.valueOf(NonEntity.class))).isFalse();
}
@Test // DATAREST-427
public void invokesConverterWithLastUriPathSegment() {
void invokesConverterWithLastUriPathSegment() {
Entity reference = new Entity();
@@ -108,39 +108,49 @@ public class UriToEntityConverterUnitTests {
doReturn(Optional.of(reference)).when(invoker).invokeFindById("1");
doReturn(invoker).when(invokerFactory).getInvokerFor(ENTITY_TYPE.getType());
assertThat(converter.convert(URI.create("/foo/bar/1"), URI_TYPE, ENTITY_TYPE)).isEqualTo((Object) reference);
assertThat(converter.convert(URI.create("/foo/bar/1"), URI_TYPE, ENTITY_TYPE)).isEqualTo(reference);
}
@Test(expected = ConversionFailedException.class) // DATAREST-427
public void rejectsUnknownType() {
converter.convert(URI.create("/foo/1"), URI_TYPE, STRING_TYPE);
@Test // DATAREST-427
void rejectsUnknownType() {
assertThatExceptionOfType(ConversionFailedException.class) //
.isThrownBy(() -> converter.convert(URI.create("/foo/1"), URI_TYPE, STRING_TYPE));
}
@Test(expected = ConversionFailedException.class) // DATAREST-427
public void rejectsUriWithLessThanTwoSegments() {
converter.convert(URI.create("1"), URI_TYPE, ENTITY_TYPE);
@Test // DATAREST-427
void rejectsUriWithLessThanTwoSegments() {
assertThatExceptionOfType(ConversionFailedException.class) //
.isThrownBy(() -> converter.convert(URI.create("1"), URI_TYPE, ENTITY_TYPE));
}
@Test(expected = IllegalArgumentException.class) // DATAREST-741
public void rejectsNullPersistentEntities() {
new UriToEntityConverter(null, invokerFactory, repositories);
@Test // DATAREST-741
void rejectsNullPersistentEntities() {
assertThatIllegalArgumentException() //
.isThrownBy(() -> new UriToEntityConverter(null, invokerFactory, repositories));
}
@Test(expected = IllegalArgumentException.class) // DATAREST-741
public void rejectsNullRepositoryInvokerFactory() {
new UriToEntityConverter(mock(PersistentEntities.class), null, repositories);
@Test // DATAREST-741
void rejectsNullRepositoryInvokerFactory() {
assertThatIllegalArgumentException() //
.isThrownBy(() -> new UriToEntityConverter(mock(PersistentEntities.class), null, repositories));
}
@Test(expected = IllegalArgumentException.class) // DATAREST-741
public void rejectsNullRepositories() {
new UriToEntityConverter(mock(PersistentEntities.class), invokerFactory, null);
@Test // DATAREST-741
void rejectsNullRepositories() {
assertThatIllegalArgumentException() //
.isThrownBy(() -> new UriToEntityConverter(mock(PersistentEntities.class), invokerFactory, null));
}
/**
* @see DATAREST-1018
*/
@Test
public void doesNotRegisterTypeWithUnmanagedRawType() {
void doesNotRegisterTypeWithUnmanagedRawType() {
PersistentEntities entities = mock(PersistentEntities.class);
doReturn(Streamable.of(ClassTypeInformation.OBJECT)).when(entities).getManagedTypes();

View File

@@ -21,8 +21,8 @@ import java.util.Arrays;
import java.util.Collections;
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.NotReadablePropertyException;
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
import org.springframework.data.mapping.context.PersistentEntities;
@@ -33,12 +33,12 @@ import org.springframework.validation.Errors;
*
* @author Oliver Gierke
*/
public class ValidationErrorsUnitTests {
class ValidationErrorsUnitTests {
PersistentEntities entities;
@Before
public void setUp() {
@BeforeEach
void setUp() {
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
context.getPersistentEntity(Foo.class);
@@ -47,7 +47,7 @@ public class ValidationErrorsUnitTests {
}
@Test // DATAREST-798
public void exposesNestedViolationsCorrectly() {
void exposesNestedViolationsCorrectly() {
ValidationErrors errors = new ValidationErrors(new Foo(), entities);
@@ -59,12 +59,12 @@ public class ValidationErrorsUnitTests {
}
@Test // DATAREST-801
public void getsTheNestedFieldsValue() {
void getsTheNestedFieldsValue() {
expectedErrorBehavior(new ValidationErrors(new Foo(), entities));
}
@Test // DATAREST-1163
public void returnsNullForPropertyValue() {
void returnsNullForPropertyValue() {
ValidationErrors errors = new ValidationErrors(new Foo(), entities);

View File

@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration.ProjectionDefinition;
/**
@@ -27,40 +27,53 @@ import org.springframework.data.rest.core.config.ProjectionDefinitionConfigurati
*
* @author Oliver Gierke
*/
public class ProjectionDefinitionConfigurationUnitTests {
class ProjectionDefinitionConfigurationUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAREST-221
public void rejectsNullProjectionTypeForAutoConfiguration() {
new ProjectionDefinitionConfiguration().addProjection(null);
}
@Test // DATAREST-221
void rejectsNullProjectionTypeForAutoConfiguration() {
@Test(expected = IllegalArgumentException.class) // DATAREST-221
public void rejectsUnannotatedClassForConfigurationShortcut() {
new ProjectionDefinitionConfiguration().addProjection(String.class);
}
@Test(expected = IllegalArgumentException.class) // DATAREST-221
public void rejectsNullProjectionTypeForManualConfiguration() {
new ProjectionDefinitionConfiguration().addProjection(null, "name", Object.class);
}
@Test(expected = IllegalArgumentException.class) // DATAREST-221
public void rejectsNullNameForManualConfiguration() {
new ProjectionDefinitionConfiguration().addProjection(String.class, (String) null, Object.class);
}
@Test(expected = IllegalArgumentException.class) // DATAREST-221
public void rejectsEmptyNameForManualConfiguration() {
new ProjectionDefinitionConfiguration().addProjection(String.class, "", Object.class);
}
@Test(expected = IllegalArgumentException.class) // DATAREST-221
public void rejectsEmptySourceTypes() {
new ProjectionDefinitionConfiguration().addProjection(String.class, "name", new Class<?>[0]);
assertThatIllegalArgumentException() //
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(null));
}
@Test // DATAREST-221
public void findsRegisteredProjection() {
void rejectsUnannotatedClassForConfigurationShortcut() {
assertThatIllegalArgumentException() //
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(String.class));
}
@Test // DATAREST-221
void rejectsNullProjectionTypeForManualConfiguration() {
assertThatIllegalArgumentException() //
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(null, "name", Object.class));
}
@Test // DATAREST-221
void rejectsNullNameForManualConfiguration() {
assertThatIllegalArgumentException() //
.isThrownBy(
() -> new ProjectionDefinitionConfiguration().addProjection(String.class, (String) null, Object.class));
}
@Test // DATAREST-221
void rejectsEmptyNameForManualConfiguration() {
assertThatIllegalArgumentException() //
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(String.class, "", Object.class));
}
@Test // DATAREST-221
void rejectsEmptySourceTypes() {
assertThatIllegalArgumentException() //
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(String.class, "name", new Class<?>[0]));
}
@Test // DATAREST-221
void findsRegisteredProjection() {
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
configuration.addProjection(Integer.class, "name", String.class);
@@ -69,7 +82,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
}
@Test // DATAREST-221
public void registersAnnotatedProjection() {
void registersAnnotatedProjection() {
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
configuration.addProjection(SampleProjection.class);
@@ -78,7 +91,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
}
@Test // DATAREST-221
public void defaultsNameToSimpleClassNameIfNotAnnotated() {
void defaultsNameToSimpleClassNameIfNotAnnotated() {
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
configuration.addProjection(Default.class);
@@ -87,7 +100,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
}
@Test // DATAREST-221
public void definitionEquals() {
void definitionEquals() {
ProjectionDefinition objectName = ProjectionDefinition.of(Object.class, Object.class, "name");
ProjectionDefinition sameObjectName = ProjectionDefinition.of(Object.class, Object.class, "name");
@@ -108,7 +121,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
}
@Test // DATAREST-385
public void returnsProjectionForParentClass() {
void returnsProjectionForParentClass() {
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
configuration.addProjection(ParentProjection.class);
@@ -119,12 +132,12 @@ public class ProjectionDefinitionConfigurationUnitTests {
}
@Test // DATAREST-221
public void defaultsParamternameToProjection() {
void defaultsParamternameToProjection() {
assertThat(new ProjectionDefinitionConfiguration().getParameterName()).isEqualTo("projection");
}
@Test // DATAREST-747
public void returnsMostConcreteProjectionForSourceType() {
void returnsMostConcreteProjectionForSourceType() {
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
configuration.addProjection(ParentProjection.class);

View File

@@ -20,7 +20,7 @@ import static org.springframework.data.rest.core.support.ResourceMappingUtils.*;
import java.lang.reflect.Method;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
@@ -36,12 +36,12 @@ import org.springframework.hateoas.server.core.EvoInflectorLinkRelationProvider;
* @author Jon Brisbin
*/
@SuppressWarnings("deprecation")
public class ResourceMappingUnitTests {
class ResourceMappingUnitTests {
LinkRelationProvider relProvider = new EvoInflectorLinkRelationProvider();
@Test
public void shouldDetectPathAndRemoveLeadingSlashIfAny() {
void shouldDetectPathAndRemoveLeadingSlashIfAny() {
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(
findRel(AnnotatedWithLeadingSlashPersonRepository.class),
@@ -56,7 +56,7 @@ public class ResourceMappingUnitTests {
}
@Test
public void shouldDetectPathAndRemoveLeadingSlashIfAnyOnMethod() throws Exception {
void shouldDetectPathAndRemoveLeadingSlashIfAnyOnMethod() throws Exception {
Method method = AnnotatedWithLeadingSlashPersonRepository.class.getMethod("findByFirstName", String.class,
Pageable.class);
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(
@@ -70,7 +70,7 @@ public class ResourceMappingUnitTests {
}
@Test
public void shouldReturnDefaultIfPathContainsOnlySlashTextOnMethod() throws Exception {
void shouldReturnDefaultIfPathContainsOnlySlashTextOnMethod() throws Exception {
Method method = AnnotatedWithLeadingSlashPersonRepository.class.getMethod("findByLastName", String.class,
Pageable.class);
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(

View File

@@ -15,10 +15,11 @@
*/
package org.springframework.data.rest.core.context;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -32,7 +33,7 @@ import org.springframework.data.rest.core.domain.PersonBeforeSaveHandler;
import org.springframework.data.rest.core.domain.PersonRepository;
import org.springframework.data.rest.core.event.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Tests around the {@link org.springframework.context.ApplicationEvent} handling abstractions.
@@ -40,9 +41,9 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Jon Brisbin
* @author Oliver Gierke
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration
public class RepositoryEventIntegrationTests {
class RepositoryEventIntegrationTests {
@Configuration
@Import({ RepositoryTestsConfig.class })
@@ -68,58 +69,78 @@ public class RepositoryEventIntegrationTests {
@Autowired PersonRepository people;
Person person;
@Before
public void setup() {
@BeforeEach
void setup() {
person = people.save(new Person("Jane", "Doe"));
}
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
public void shouldDispatchBeforeCreate() throws Exception {
appCtx.publishEvent(new BeforeCreateEvent(person));
@Test // DATAREST-388
void shouldDispatchBeforeCreate() throws Exception {
assertThatExceptionOfType(EventHandlerInvokedException.class) //
.isThrownBy(() -> appCtx.publishEvent(new BeforeCreateEvent(person)));
}
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
public void shouldDispatchAfterCreate() throws Exception {
appCtx.publishEvent(new AfterCreateEvent(person));
@Test // DATAREST-388
void shouldDispatchAfterCreate() throws Exception {
assertThatExceptionOfType(EventHandlerInvokedException.class) //
.isThrownBy(() -> appCtx.publishEvent(new AfterCreateEvent(person)));
}
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
public void shouldDispatchBeforeSave() throws Exception {
appCtx.publishEvent(new BeforeSaveEvent(person));
@Test // DATAREST-388
void shouldDispatchBeforeSave() throws Exception {
assertThatExceptionOfType(EventHandlerInvokedException.class) //
.isThrownBy(() -> appCtx.publishEvent(new BeforeSaveEvent(person)));
}
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
public void shouldDispatchAfterSave() throws Exception {
appCtx.publishEvent(new AfterSaveEvent(person));
@Test // DATAREST-388
void shouldDispatchAfterSave() throws Exception {
assertThatExceptionOfType(EventHandlerInvokedException.class) //
.isThrownBy(() -> appCtx.publishEvent(new AfterSaveEvent(person)));
}
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
public void shouldDispatchBeforeDelete() throws Exception {
appCtx.publishEvent(new BeforeDeleteEvent(person));
@Test // DATAREST-388
void shouldDispatchBeforeDelete() throws Exception {
assertThatExceptionOfType(EventHandlerInvokedException.class) //
.isThrownBy(() -> appCtx.publishEvent(new BeforeDeleteEvent(person)));
}
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
public void shouldDispatchAfterDelete() throws Exception {
appCtx.publishEvent(new AfterDeleteEvent(person));
@Test // DATAREST-388
void shouldDispatchAfterDelete() throws Exception {
assertThatExceptionOfType(EventHandlerInvokedException.class) //
.isThrownBy(() -> appCtx.publishEvent(new AfterDeleteEvent(person)));
}
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
public void shouldDispatchBeforeLinkSave() throws Exception {
appCtx.publishEvent(new BeforeLinkSaveEvent(person, new Object()));
@Test // DATAREST-388
void shouldDispatchBeforeLinkSave() throws Exception {
assertThatExceptionOfType(EventHandlerInvokedException.class) //
.isThrownBy(() -> appCtx.publishEvent(new BeforeLinkSaveEvent(person, new Object())));
}
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
public void shouldDispatchAfterLinkSave() throws Exception {
appCtx.publishEvent(new AfterLinkSaveEvent(person, new Object()));
@Test // DATAREST-388
void shouldDispatchAfterLinkSave() throws Exception {
assertThatExceptionOfType(EventHandlerInvokedException.class) //
.isThrownBy(() -> appCtx.publishEvent(new AfterLinkSaveEvent(person, new Object())));
}
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
public void shouldDispatchBeforeLinkDelete() throws Exception {
appCtx.publishEvent(new BeforeLinkDeleteEvent(person, new Object()));
@Test // DATAREST-388
void shouldDispatchBeforeLinkDelete() throws Exception {
assertThatExceptionOfType(EventHandlerInvokedException.class) //
.isThrownBy(() -> appCtx.publishEvent(new BeforeLinkDeleteEvent(person, new Object())));
}
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
public void shouldDispatchAfterLinkDelete() throws Exception {
appCtx.publishEvent(new AfterLinkDeleteEvent(person, new Object()));
@Test // DATAREST-388
void shouldDispatchAfterLinkDelete() throws Exception {
assertThatExceptionOfType(EventHandlerInvokedException.class) //
.isThrownBy(() -> appCtx.publishEvent(new AfterLinkDeleteEvent(person, new Object())));
}
}

View File

@@ -15,8 +15,10 @@
*/
package org.springframework.data.rest.core.context;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
@@ -33,7 +35,7 @@ import org.springframework.data.rest.core.domain.PersonNameValidator;
import org.springframework.data.rest.core.event.BeforeSaveEvent;
import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Tests to check the {@link org.springframework.validation.Validator} integration.
@@ -41,9 +43,9 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Jon Brisbin
* @author Oliver Gierke
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration
public class ValidatorIntegrationTests {
class ValidatorIntegrationTests {
@Configuration
@Import({ RepositoryTestsConfig.class, JpaRepositoryConfig.class })
@@ -62,12 +64,14 @@ public class ValidatorIntegrationTests {
@Autowired ConfigurableApplicationContext context;
@Autowired KeyValueMappingContext<?, ?> mappingContext;
@Test(expected = RepositoryConstraintViolationException.class)
public void shouldValidateLastName() throws Exception {
@Test
void shouldValidateLastName() throws Exception {
mappingContext.getPersistentEntity(Person.class);
// Empty name should be rejected by PersonNameValidator
context.publishEvent(new BeforeSaveEvent(new Person("Dave", "")));
assertThatExceptionOfType(RepositoryConstraintViolationException.class)
.isThrownBy(() -> context.publishEvent(new BeforeSaveEvent(new Person("Dave", ""))));
}
}

View File

@@ -15,17 +15,7 @@
*/
package org.springframework.data.rest.core.domain;
import org.springframework.data.rest.core.annotation.HandleAfterCreate;
import org.springframework.data.rest.core.annotation.HandleAfterDelete;
import org.springframework.data.rest.core.annotation.HandleAfterLinkDelete;
import org.springframework.data.rest.core.annotation.HandleAfterLinkSave;
import org.springframework.data.rest.core.annotation.HandleAfterSave;
import org.springframework.data.rest.core.annotation.HandleBeforeCreate;
import org.springframework.data.rest.core.annotation.HandleBeforeDelete;
import org.springframework.data.rest.core.annotation.HandleBeforeLinkDelete;
import org.springframework.data.rest.core.annotation.HandleBeforeLinkSave;
import org.springframework.data.rest.core.annotation.HandleBeforeSave;
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
import org.springframework.data.rest.core.annotation.*;
/**
* Sample annotation-based event handler.
@@ -39,26 +29,26 @@ public class AnnotatedPersonEventHandler {
@HandleAfterCreate
@HandleAfterDelete
@HandleAfterSave
public void handleAfter(Person p) {
void handleAfter(Person p) {
throw new EventHandlerInvokedException();
}
@HandleAfterLinkDelete
@HandleAfterLinkSave
public void handleAfterLink(Person p, Object o) {
void handleAfterLink(Person p, Object o) {
throw new EventHandlerInvokedException();
}
@HandleBeforeCreate
@HandleBeforeDelete
@HandleBeforeSave
public void handleBefore(Person p) {
void handleBefore(Person p) {
throw new EventHandlerInvokedException();
}
@HandleBeforeLinkDelete
@HandleBeforeLinkSave
public void handleBeforeLink(Person p, Object o) {
void handleBeforeLink(Person p, Object o) {
throw new EventHandlerInvokedException();
}
}

View File

@@ -26,7 +26,7 @@ import org.springframework.data.annotation.Reference;
* @author Oliver Gierke
*/
@Value
public class Order {
class Order {
@Id UUID id = UUID.randomUUID();
@Reference Person creator;

View File

@@ -10,7 +10,7 @@ import org.springframework.validation.Validator;
/**
* A test {@link Validator} that checks for non-blank names.
*
*
* @author Jon Brisbin
*/
@Component

View File

@@ -24,7 +24,7 @@ import org.springframework.stereotype.Component;
* @author Oliver Gierke
*/
@Component
public class ProfileLoader implements InitializingBean {
class ProfileLoader implements InitializingBean {
@Autowired ProfileRepository profiles;

View File

@@ -24,7 +24,7 @@ import java.util.Map;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.core.annotation.Order;
import org.springframework.data.rest.core.annotation.HandleAfterCreate;
@@ -43,11 +43,11 @@ import org.springframework.util.ReflectionUtils;
* @author Fabian Trampusch
* @author Joseph Valerio
*/
public class AnnotatedEventHandlerInvokerUnitTests {
class AnnotatedEventHandlerInvokerUnitTests {
@Test // DATAREST-582
@SuppressWarnings("unchecked")
public void doesNotDiscoverMethodsOnProxyClasses() {
void doesNotDiscoverMethodsOnProxyClasses() {
ProxyFactory factory = new ProxyFactory();
factory.setTarget(new Sample());
@@ -63,7 +63,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
}
@Test // DATAREST-606
public void invokesPrivateEventHandlerMethods() {
void invokesPrivateEventHandlerMethods() {
SampleWithPrivateHandler sampleHandler = new SampleWithPrivateHandler();
@@ -76,7 +76,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
}
@Test // DATAREST-970
public void invokesEventHandlerInOrderMethods() {
void invokesEventHandlerInOrderMethods() {
SampleOrderEventHandler1 orderHandler1 = new SampleOrderEventHandler1();
SampleOrderEventHandler2 orderHandler2 = new SampleOrderEventHandler2();
@@ -94,7 +94,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
}
@Test // DATAREST-983
public void invokesEventHandlerOnParentClass() {
void invokesEventHandlerOnParentClass() {
FirstEventHandler firstHandler = new FirstEventHandler();
SecondEventHandler secondHandler = new SecondEventHandler();
@@ -111,7 +111,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
}
@Test // DATAREST-1075
public void doesInvokeMethodOnlyOnceForMockitoSpy() {
void doesInvokeMethodOnlyOnceForMockitoSpy() {
EventHandler handler = spy(new EventHandler());
AnnotatedEventHandlerInvoker invoker = new AnnotatedEventHandlerInvoker();
@@ -124,7 +124,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
}
@Test // DATAREST-582
public void invocesInterceptorForProxiedListener() {
void invocesInterceptorForProxiedListener() {
SampleInterceptor interceptor = new SampleInterceptor();
@@ -147,7 +147,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
static class Sample {
@HandleBeforeCreate
public void method(Sample sample) {}
void method(Sample sample) {}
}
@RepositoryEventHandler
@@ -216,7 +216,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
static class EventHandler {
@HandleAfterCreate
public void doAfterCreate(Payload bar) {}
void doAfterCreate(Payload bar) {}
}
static class Payload {}

View File

@@ -23,11 +23,11 @@ import static org.springframework.http.HttpMethod.*;
import java.util.List;
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;
import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.data.annotation.Reference;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
@@ -46,18 +46,18 @@ import org.springframework.http.HttpMethod;
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class CrudMethodsSupportedHttpMethodsUnitTests {
@ExtendWith(MockitoExtension.class)
class CrudMethodsSupportedHttpMethodsUnitTests {
@Mock RepositoryResourceMappings mappings;
@Before
public void setUp() {
@BeforeEach
void setUp() {
when(mappings.exposeMethodsByDefault()).thenReturn(true);
}
@Test // DATACMNS-589, DATAREST-409
public void doesNotSupportAnyHttpMethodForEmptyRepository() {
void doesNotSupportAnyHttpMethodForEmptyRepository() {
SupportedHttpMethods supportedMethods = getSupportedHttpMethodsFor(RawRepository.class);
@@ -69,7 +69,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
}
@Test // DATAREST-217, DATAREST-330, DATACMNS-589, DATAREST-409
public void defaultsSupportedHttpMethodsForItemResource() {
void defaultsSupportedHttpMethodsForItemResource() {
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(SampleRepository.class);
@@ -78,7 +78,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
}
@Test // DATAREST-217, DATAREST-330, DATACMNS-589, DATAREST-409
public void defaultsSupportedHttpMethodsForCollectionResource() {
void defaultsSupportedHttpMethodsForCollectionResource() {
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(SampleRepository.class);
@@ -87,7 +87,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
}
@Test // DATACMNS-589, DATAREST-409
public void doesNotSupportDeleteIfDeleteMethodIsNotExported() {
void doesNotSupportDeleteIfDeleteMethodIsNotExported() {
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(HidesDelete.class);
@@ -95,7 +95,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
}
@Test // DATAREST-523
public void exposesMethodsForProperties() {
void exposesMethodsForProperties() {
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
KeyValuePersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(Entity.class);
@@ -118,17 +118,17 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
}
@Test // DATAREST-825
public void supportsDeleteIfFindOneIsHidden() {
void supportsDeleteIfFindOneIsHidden() {
assertMethodsSupported(getSupportedHttpMethodsFor(HidesFindOne.class), ITEM, true, DELETE, PATCH, PUT, OPTIONS);
}
@Test // DATAREST-825
public void doesNotSupportDeleteIfNoFindOneAvailable() {
void doesNotSupportDeleteIfNoFindOneAvailable() {
assertMethodsSupported(getSupportedHttpMethodsFor(NoFindOne.class), ITEM, false, DELETE);
}
@Test // DATAREST-1176
public void onlyExposesExplicitlyAnnotatedMethodsIfConfigured() {
void onlyExposesExplicitlyAnnotatedMethodsIfConfigured() {
reset(mappings);
when(mappings.exposeMethodsByDefault()).thenReturn(false);

View File

@@ -19,17 +19,17 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.http.HttpMethod.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link ExposureConfiguration}.
*
* @author Oliver Gierke
*/
public class ExposureConfigurationUnitTests {
class ExposureConfigurationUnitTests {
@Test // DATAREST-948
public void appliesTypeBasedCollectionFiltersOnlyForMatchingTypes() {
void appliesTypeBasedCollectionFiltersOnlyForMatchingTypes() {
ExposureConfiguration configuration = new ExposureConfiguration();
@@ -43,7 +43,7 @@ public class ExposureConfigurationUnitTests {
}
@Test // DATAREST-948
public void appliesTypeBasedItemFiltersOnlyForMatchingTypes() {
void appliesTypeBasedItemFiltersOnlyForMatchingTypes() {
ExposureConfiguration configuration = new ExposureConfiguration();
@@ -57,7 +57,7 @@ public class ExposureConfigurationUnitTests {
}
@Test // DATAREST-948
public void appliesTypeSpecificFilterForAggregateSubTypes() {
void appliesTypeSpecificFilterForAggregateSubTypes() {
ExposureConfiguration configuration = new ExposureConfiguration();
configuration.forDomainType(Sample.class).withItemExposure((metadata, methods) -> methods.disable(POST));

View File

@@ -19,9 +19,9 @@ import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.annotation.Reference;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
@@ -34,8 +34,8 @@ import org.springframework.data.rest.core.annotation.RestResource;
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class MappingResourceMetadataUnitTests {
@ExtendWith(MockitoExtension.class)
class MappingResourceMetadataUnitTests {
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
@@ -45,7 +45,7 @@ public class MappingResourceMetadataUnitTests {
MappingResourceMetadata metadata = new MappingResourceMetadata(entity, resourceMappings);
@Test // DATAREST-514
public void allowsLookupOfPropertyByMappedName() {
void allowsLookupOfPropertyByMappedName() {
KeyValuePersistentProperty<?> property = entity.getRequiredPersistentProperty("related");
@@ -57,13 +57,13 @@ public class MappingResourceMetadataUnitTests {
}
@Test // DATAREST-518
public void isNotExportedByDefault() {
void isNotExportedByDefault() {
assertThat(metadata.isExported()).isFalse();
}
@Test // DATAREST-518
public void isExportedIfExplicitlyAnnotated() {
void isExportedIfExplicitlyAnnotated() {
MappingResourceMetadata metadata = new MappingResourceMetadata(context.getRequiredPersistentEntity(Related.class),
resourceMappings);

View File

@@ -17,7 +17,7 @@ package org.springframework.data.rest.core.mapping;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
import org.springframework.data.mapping.context.PersistentEntities;
@@ -26,10 +26,10 @@ import org.springframework.data.mapping.context.PersistentEntities;
*
* @author Oliver Gierke
*/
public class PersistentEntitiesResourceMappingsUnitTests {
class PersistentEntitiesResourceMappingsUnitTests {
@Test // DATAREST-1320
public void doesNotConsiderCachedNullValuesToIndicateMappingAvailable() {
void doesNotConsiderCachedNullValuesToIndicateMappingAvailable() {
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
@@ -41,7 +41,7 @@ public class PersistentEntitiesResourceMappingsUnitTests {
}
@Test // GH-2033
public void transparentlyAddsValueToCacheOnHasMappingRequests() {
void transparentlyAddsValueToCacheOnHasMappingRequests() {
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
context.getPersistentEntity(Sample.class);

View File

@@ -21,9 +21,9 @@ import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.annotation.Reference;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
@@ -42,13 +42,13 @@ import org.springframework.hateoas.LinkRelation;
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class PersistentPropertyResourceMappingUnitTests {
@ExtendWith(MockitoExtension.class)
class PersistentPropertyResourceMappingUnitTests {
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
@Test // DATAREST-175
public void usesPropertyNameAsDefaultResourceMappingRelAndPath() {
void usesPropertyNameAsDefaultResourceMappingRelAndPath() {
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "first");
@@ -59,7 +59,7 @@ public class PersistentPropertyResourceMappingUnitTests {
}
@Test // DATAREST-175
public void considersMappingAnnotationOnDomainClassProperty() {
void considersMappingAnnotationOnDomainClassProperty() {
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "second");
@@ -70,7 +70,7 @@ public class PersistentPropertyResourceMappingUnitTests {
}
@Test // DATAREST-175
public void considersMappingAnnotationOnDomainClassPropertyMethod() {
void considersMappingAnnotationOnDomainClassPropertyMethod() {
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "third");
@@ -81,7 +81,7 @@ public class PersistentPropertyResourceMappingUnitTests {
}
@Test // DATAREST-233
public void returnsDefaultDescriptionKey() {
void returnsDefaultDescriptionKey() {
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "second");
@@ -92,7 +92,7 @@ public class PersistentPropertyResourceMappingUnitTests {
}
@Test // DATAREST-233
public void considersAtDescription() {
void considersAtDescription() {
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "fourth");
@@ -102,7 +102,7 @@ public class PersistentPropertyResourceMappingUnitTests {
}
@Test // #1994
public void doesNotConsiderPropertyExportedIfTargetTypeIsNotMapped() {
void doesNotConsiderPropertyExportedIfTargetTypeIsNotMapped() {
PersistentEntity<?, ?> entity = mappingContext.getRequiredPersistentEntity(Entity.class);
PersistentProperty<?> property = entity.getRequiredPersistentProperty("third");

View File

@@ -17,7 +17,7 @@ package org.springframework.data.rest.core.mapping;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.Repository;
@@ -34,10 +34,10 @@ import org.springframework.hateoas.LinkRelation;
*
* @author Oliver Gierke
*/
public class RepositoryCollectionResourceMappingUnitTests {
class RepositoryCollectionResourceMappingUnitTests {
@Test
public void buildsDefaultMappingForRepository() {
void buildsDefaultMappingForRepository() {
CollectionResourceMapping mapping = getResourceMappingFor(PersonRepository.class);
@@ -48,7 +48,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
}
@Test
public void honorsAnnotatedsMapping() {
void honorsAnnotatedsMapping() {
CollectionResourceMapping mapping = getResourceMappingFor(AnnotatedPersonRepository.class);
@@ -59,7 +59,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
}
@Test
public void repositoryAnnotationTrumpsDomainTypeMapping() {
void repositoryAnnotationTrumpsDomainTypeMapping() {
CollectionResourceMapping mapping = getResourceMappingFor(AnnotatedAnnotatedPersonRepository.class);
@@ -70,19 +70,19 @@ public class RepositoryCollectionResourceMappingUnitTests {
}
@Test
public void doesNotExposeRepositoryForPublicDomainTypeIfRepoIsPackageProtected() {
void doesNotExposeRepositoryForPublicDomainTypeIfRepoIsPackageProtected() {
ResourceMapping mapping = getResourceMappingFor(PackageProtectedRepository.class);
assertThat(mapping.isExported()).isFalse();
}
@Test // DATAREST-229
public void detectsPagingRepository() {
void detectsPagingRepository() {
assertThat(getResourceMappingFor(PersonRepository.class).isPagingResource()).isTrue();
}
@Test
public void discoversCustomizationsUsingRestRepositoryResource() {
void discoversCustomizationsUsingRestRepositoryResource() {
CollectionResourceMapping mapping = getResourceMappingFor(RepositoryAnnotatedRepository.class);
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("foo"));
@@ -90,7 +90,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
}
@Test // DATAREST-445
public void usesDomainTypeFromRepositoryMetadata() {
void usesDomainTypeFromRepositoryMetadata() {
RepositoryMetadata metadata = new DefaultRepositoryMetadata(PersonRepository.class) {
@@ -107,7 +107,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
}
@Test // DATAREST-1401
public void rejectsPathsWithMultipleSegments() {
void rejectsPathsWithMultipleSegments() {
RepositoryMetadata metadata = new DefaultRepositoryMetadata(InvalidPath.class);
@@ -119,7 +119,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
}
@Test // DATAREST-1401
public void exposesProjectionTypeIfConfigured() {
void exposesProjectionTypeIfConfigured() {
assertThat(getResourceMappingFor(WithProjection.class).getExcerptProjection()).hasValue(Object.class);
assertThat(getResourceMappingFor(WithoutProjection.class).getExcerptProjection()).isEmpty();

View File

@@ -22,7 +22,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.data.repository.Repository;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@@ -35,10 +35,10 @@ import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.Re
* @soundtrack Katinka - Ausverkauf
*/
@SuppressWarnings("serial")
public class RepositoryDetectionStrategiesUnitTests {
class RepositoryDetectionStrategiesUnitTests {
@Test // DATAREST-473
public void allExposesAllRepositories() {
void allExposesAllRepositories() {
assertExposures(ALL, new HashMap<Class<?>, Boolean>() {
{
@@ -51,7 +51,7 @@ public class RepositoryDetectionStrategiesUnitTests {
}
@Test // DATAREST-473
public void defaultHonorsVisibilityAndAnnotations() {
void defaultHonorsVisibilityAndAnnotations() {
assertExposures(DEFAULT, new HashMap<Class<?>, Boolean>() {
{
@@ -64,7 +64,7 @@ public class RepositoryDetectionStrategiesUnitTests {
}
@Test // DATAREST-473
public void visibilityHonorsTypeVisibilityOnly() {
void visibilityHonorsTypeVisibilityOnly() {
assertExposures(VISIBILITY, new HashMap<Class<?>, Boolean>() {
{
@@ -77,7 +77,7 @@ public class RepositoryDetectionStrategiesUnitTests {
}
@Test // DATAREST-473
public void annotatedHonorsAnnotationsOnly() {
void annotatedHonorsAnnotationsOnly() {
assertExposures(ANNOTATED, new HashMap<Class<?>, Boolean>() {
{

View File

@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
import java.lang.reflect.Method;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@@ -37,14 +37,14 @@ import org.springframework.hateoas.LinkRelation;
*
* @author Oliver Gierke
*/
public class RepositoryMethodResourceMappingUnitTests {
class RepositoryMethodResourceMappingUnitTests {
RepositoryMetadata metadata = new DefaultRepositoryMetadata(PersonRepository.class);
RepositoryCollectionResourceMapping resourceMapping = new RepositoryCollectionResourceMapping(metadata,
RepositoryDetectionStrategies.DEFAULT);
@Test
public void defaultsMappingToMethodName() throws Exception {
void defaultsMappingToMethodName() throws Exception {
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
ResourceMapping mapping = getMappingFor(method);
@@ -53,7 +53,7 @@ public class RepositoryMethodResourceMappingUnitTests {
}
@Test
public void usesConfiguredNameWithLeadingSlash() throws Exception {
void usesConfiguredNameWithLeadingSlash() throws Exception {
Method method = PersonRepository.class.getMethod("findByFirstname", String.class);
ResourceMapping mapping = getMappingFor(method);
@@ -62,7 +62,7 @@ public class RepositoryMethodResourceMappingUnitTests {
}
@Test // DATAREST-31
public void discoversParametersIfCompiledWithCorrespondingFlag() throws Exception {
void discoversParametersIfCompiledWithCorrespondingFlag() throws Exception {
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
MethodResourceMapping mapping = getMappingFor(method);
@@ -71,7 +71,7 @@ public class RepositoryMethodResourceMappingUnitTests {
}
@Test // DATAREST-31
public void resolvesParameterNamesIfNotAnnotated() throws Exception {
void resolvesParameterNamesIfNotAnnotated() throws Exception {
Method method = PersonRepository.class.getMethod("findByFirstname", String.class);
MethodResourceMapping mapping = getMappingFor(method);
@@ -81,7 +81,7 @@ public class RepositoryMethodResourceMappingUnitTests {
}
@Test // DATAREST-229
public void considersPagingFinderAPagingResource() throws Exception {
void considersPagingFinderAPagingResource() throws Exception {
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
MethodResourceMapping mapping = getMappingFor(method);
@@ -90,7 +90,7 @@ public class RepositoryMethodResourceMappingUnitTests {
}
@Test
public void usesMethodNameAsRelFallbackEvenIfPathIsConfigured() throws Exception {
void usesMethodNameAsRelFallbackEvenIfPathIsConfigured() throws Exception {
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
MethodResourceMapping mapping = getMappingFor(method);
@@ -99,7 +99,7 @@ public class RepositoryMethodResourceMappingUnitTests {
}
@Test // DATAREST-384
public void considersResourceSortableIfSortParameterIsPresent() throws Exception {
void considersResourceSortableIfSortParameterIsPresent() throws Exception {
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Sort.class);
RepositoryMethodResourceMapping mapping = getMappingFor(method);
@@ -113,7 +113,7 @@ public class RepositoryMethodResourceMappingUnitTests {
}
@Test // DATAREST-467
public void returnsDomainTypeAsProjectionSourceType() throws Exception {
void returnsDomainTypeAsProjectionSourceType() throws Exception {
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
MethodResourceMapping mapping = getMappingFor(method);
@@ -122,7 +122,7 @@ public class RepositoryMethodResourceMappingUnitTests {
}
@Test // DATAREST-699
public void doesNotIncludePageableAsParameter() throws Exception {
void doesNotIncludePageableAsParameter() throws Exception {
Method method = PersonRepository.class.getMethod("findByLastname", String.class, Pageable.class);
RepositoryMethodResourceMapping mapping = getMappingFor(method);

View File

@@ -22,9 +22,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
@@ -44,7 +44,7 @@ import org.springframework.data.rest.core.domain.Person;
import org.springframework.data.rest.core.domain.Profile;
import org.springframework.hateoas.LinkRelation;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Integration tests for {@link RepositoryResourceMappings}.
@@ -52,17 +52,17 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Oliver Gierke
* @author Greg Turnquist
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = JpaRepositoryConfig.class)
public class RepositoryResourceMappingsIntegrationTests {
class RepositoryResourceMappingsIntegrationTests {
@Autowired ListableBeanFactory factory;
@Autowired KeyValueMappingContext<?, ?> mappingContext;
ResourceMappings mappings;
@Before
public void setUp() {
@BeforeEach
void setUp() {
mappingContext.getPersistentEntity(Profile.class);
@@ -75,12 +75,12 @@ public class RepositoryResourceMappingsIntegrationTests {
}
@Test
public void detectsAllMappings() {
void detectsAllMappings() {
assertThat(mappings).hasSize(5);
}
@Test
public void exportsResourceAndSearchesForPersons() {
void exportsResourceAndSearchesForPersons() {
ResourceMetadata personMappings = mappings.getMetadataFor(Person.class);
@@ -89,7 +89,7 @@ public class RepositoryResourceMappingsIntegrationTests {
}
@Test
public void doesNotExportAnyMappingsForHiddenRepository() {
void doesNotExportAnyMappingsForHiddenRepository() {
ResourceMetadata creditCardMapping = mappings.getMetadataFor(CreditCard.class);
@@ -98,7 +98,7 @@ public class RepositoryResourceMappingsIntegrationTests {
}
@Test // DATAREST-112
public void usesPropertyNameAsRelForPropertyResourceMapping() {
void usesPropertyNameAsRelForPropertyResourceMapping() {
Repositories repositories = new Repositories(factory);
PersistentEntity<?, ?> entity = repositories.getPersistentEntity(Person.class);
@@ -113,7 +113,7 @@ public class RepositoryResourceMappingsIntegrationTests {
}
@Test // DATAREST-111
public void exposesResourceByPath() {
void exposesResourceByPath() {
assertThat(mappings.exportsTopLevelResourceFor("people")).isTrue();
assertThat(mappings.exportsTopLevelResourceFor("orders")).isTrue();
@@ -126,7 +126,7 @@ public class RepositoryResourceMappingsIntegrationTests {
}
@Test // DATAREST-107
public void skipsSearchMethodsNotExported() {
void skipsSearchMethodsNotExported() {
ResourceMetadata creditCardMetadata = mappings.getMetadataFor(CreditCard.class);
SearchResourceMappings searchResourceMappings = creditCardMetadata.getSearchResourceMappings();
@@ -145,7 +145,7 @@ public class RepositoryResourceMappingsIntegrationTests {
}
@Test // DATAREST-325
public void exposesMethodResourceMappingInPackageProtectedButExportedRepo() {
void exposesMethodResourceMappingInPackageProtectedButExportedRepo() {
ResourceMetadata metadata = mappings.getMetadataFor(Author.class);
assertThat(metadata.isExported()).isTrue();
@@ -163,7 +163,7 @@ public class RepositoryResourceMappingsIntegrationTests {
}
@Test
public void testname() {
void testname() {
ResourceMetadata metadata = mappings.getMetadataFor(Person.class);

View File

@@ -17,7 +17,7 @@ package org.springframework.data.rest.core.mapping;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.rest.core.Path;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.hateoas.LinkRelation;
@@ -27,10 +27,10 @@ import org.springframework.hateoas.LinkRelation;
*
* @author Oliver Gierke
*/
public class TypeBasedCollectionResourceMappingUnitTests {
class TypeBasedCollectionResourceMappingUnitTests {
@Test
public void defaultsMappingsByType() {
void defaultsMappingsByType() {
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(Sample.class);
@@ -41,7 +41,7 @@ public class TypeBasedCollectionResourceMappingUnitTests {
}
@Test
public void usesCustomizedRel() {
void usesCustomizedRel() {
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(CustomizedSample.class);
@@ -52,7 +52,7 @@ public class TypeBasedCollectionResourceMappingUnitTests {
}
@Test // DATAREST-99
public void doesNotExportNonPublicTypesByDefault() {
void doesNotExportNonPublicTypesByDefault() {
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(HiddenSample.class);
@@ -63,7 +63,7 @@ public class TypeBasedCollectionResourceMappingUnitTests {
* @see
*/
@Test
public void usesDefaultDescriptionIfNoAnnotationPresent() {
void usesDefaultDescriptionIfNoAnnotationPresent() {
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(Sample.class);
ResourceDescription description = mapping.getDescription();

View File

@@ -23,11 +23,11 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
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.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
@@ -44,18 +44,18 @@ import org.springframework.hateoas.server.EntityLinks;
* @author Mark Paluch
* @soundtrack Trio Rotation - Triopane
*/
@RunWith(MockitoJUnitRunner.class)
public class DefaultSelfLinkProviderUnitTests {
@ExtendWith(MockitoExtension.class)
class DefaultSelfLinkProviderUnitTests {
SelfLinkProvider provider;
@Mock EntityLinks entityLinks;
@Mock(lenient = true) EntityLinks entityLinks;
PersistentEntities entities;
List<EntityLookup<?>> lookups;
ConversionService conversionService;
@Before
public void setUp() {
@BeforeEach
void setUp() {
when(entityLinks.linkToItemResource(any(Class.class), any(Object.class))).then(invocation -> {
@@ -75,23 +75,29 @@ public class DefaultSelfLinkProviderUnitTests {
this.provider = new DefaultSelfLinkProvider(entities, entityLinks, lookups, conversionService);
}
@Test(expected = IllegalArgumentException.class) // DATAREST-724
public void rejectsNullEntities() {
new DefaultSelfLinkProvider(null, entityLinks, lookups, conversionService);
}
@Test // DATAREST-724
void rejectsNullEntities() {
@Test(expected = IllegalArgumentException.class) // DATAREST-724
public void rejectsNullEntityLinks() {
new DefaultSelfLinkProvider(entities, null, lookups, conversionService);
}
@Test(expected = IllegalArgumentException.class) // DATAREST-724
public void rejectsNullEntityLookups() {
new DefaultSelfLinkProvider(entities, entityLinks, null, conversionService);
assertThatIllegalArgumentException() //
.isThrownBy(() -> new DefaultSelfLinkProvider(null, entityLinks, lookups, conversionService));
}
@Test // DATAREST-724
public void usesEntityIdIfNoLookupDefined() {
void rejectsNullEntityLinks() {
assertThatIllegalArgumentException() //
.isThrownBy(() -> new DefaultSelfLinkProvider(entities, null, lookups, conversionService));
}
@Test // DATAREST-724
void rejectsNullEntityLookups() {
assertThatIllegalArgumentException() //
.isThrownBy(() -> new DefaultSelfLinkProvider(entities, entityLinks, null, conversionService));
}
@Test // DATAREST-724
void usesEntityIdIfNoLookupDefined() {
Profile profile = new Profile("Name", "Type");
Link link = provider.createSelfLinkFor(profile);
@@ -101,7 +107,7 @@ public class DefaultSelfLinkProviderUnitTests {
@Test // DATAREST-724
@SuppressWarnings("unchecked")
public void usesEntityLookupIfDefined() {
void usesEntityLookupIfDefined() {
EntityLookup<Object> lookup = mock(EntityLookup.class);
when(lookup.supports(Profile.class)).thenReturn(true);
@@ -116,7 +122,7 @@ public class DefaultSelfLinkProviderUnitTests {
}
@Test // DATAREST-724, DATAREST-1549
public void rejectsLinkCreationForUnknownEntity() {
void rejectsLinkCreationForUnknownEntity() {
assertThatExceptionOfType(MappingException.class) //
.isThrownBy(() -> provider.createSelfLinkFor(new Object())) //

View File

@@ -17,54 +17,53 @@ package org.springframework.data.rest.core.support;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.Collection;
import lombok.Value;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.util.stream.Stream;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
/**
* Ensures proper detection and removal of leading slash in strings.
*
* @author Florent Biville
*/
@RunWith(Parameterized.class)
public class ResourceStringUtilsTests {
class ResourceStringUtilsTests {
final String actual;
final String expected;
final boolean hasText;
@TestFactory
Stream<DynamicTest> shouldDetectTextPresence() {
public ResourceStringUtilsTests(String testDescription, String actual, String expected, boolean hasText) {
this.actual = actual;
this.expected = expected;
this.hasText = hasText;
return DynamicTest.stream(fixtures(), Fixture::getName, it -> {
assertThat(ResourceStringUtils.hasTextExceptSlash(it.getActual())).isEqualTo(it.hasText);
});
}
@Parameters(name = "{0}")
public static Collection<?> parameters() {
return Arrays
.asList(
new Object[][] { { "empty string has no text and should remain empty", "", "", false },
{ "blank string has no text and should remain as is", " ", " ", false },
{ "string made of only a leading slash has no text and should be returned empty", "/", "", false },
{ "blank string with only slashes has no text and should be returned as is", " / ", " / ",
false },
{ "normal string has text and should be returned as such", "hello", "hello", true },
{ "normal string with leading slash has text and should be returned without leading slash", "/hello",
"hello", true }, });
@TestFactory
Stream<DynamicTest> shouldRemoveLeadingSlashIfAny() {
return DynamicTest.stream(fixtures(), Fixture::getName, it -> {
assertThat(ResourceStringUtils.removeLeadingSlash(it.getActual())).isEqualTo(it.getExpected());
});
}
@Test
public void shouldDetectTextPresence() {
assertThat(ResourceStringUtils.hasTextExceptSlash(actual)).isEqualTo(hasText);
static Stream<Fixture> fixtures() {
return Stream.of(
Fixture.of("empty string has no text and should remain empty", "", "", false),
Fixture.of("blank string has no text and should remain as is", " ", " ", false),
Fixture.of("string made of only a leading slash has no text and should be returned empty", "/", "", false),
Fixture.of("blank string with only slashes has no text and should be returned as is", " / ", " / ",
false),
Fixture.of("normal string has text and should be returned as such", "hello", "hello", true),
Fixture.of("normal string with leading slash has text and should be returned without leading slash", "/hello",
"hello", true));
}
@Test
public void shouldRemoveLeadingSlashIfAny() {
assertThat(ResourceStringUtils.removeLeadingSlash(actual)).isEqualTo(expected);
@Value(staticConstructor = "of")
static class Fixture {
String name, actual, expected;
boolean hasText;
}
}

View File

@@ -20,18 +20,10 @@ import static org.mockito.Mockito.*;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.function.Consumer;
import org.assertj.core.api.AbstractOptionalAssert;
import org.junit.Before;
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.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.repository.support.RepositoryInvoker;
import org.springframework.data.repository.support.RepositoryInvokerFactory;
import org.springframework.data.rest.core.domain.Profile;
@@ -41,8 +33,7 @@ import org.springframework.data.rest.core.domain.Profile;
*
* @author Oliver Gierke
*/
@RunWith(Parameterized.class)
public class UnwrappingRepositoryInvokerFactoryUnitTests {
class UnwrappingRepositoryInvokerFactoryUnitTests {
static final Object REFERENCE = new Object();
@@ -52,11 +43,8 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
RepositoryInvokerFactory factory;
Method method;
public @Parameter(0) Object source;
public @Parameter(1) Consumer<AbstractOptionalAssert<?, Object>> value;
@Before
public void setUp() throws Exception {
@BeforeEach
void setUp() throws Exception {
when(delegate.getInvokerFor(Object.class)).thenReturn(invoker);
@@ -64,21 +52,9 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
this.method = Object.class.getMethod("toString");
}
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { //
{ null, $(it -> it.isEmpty()) }, //
{ Optional.empty(), $(it -> it.isEmpty()) }, //
{ Optional.of(REFERENCE), $(it -> it.hasValue(REFERENCE)) }, //
{ com.google.common.base.Optional.absent(), $(it -> it.isEmpty()) }, //
{ com.google.common.base.Optional.of(REFERENCE), $(it -> it.hasValue(REFERENCE)) } //
});
}
@Test // DATAREST-724, DATAREST-1261
@SuppressWarnings("unchecked")
public void usesRegisteredEntityLookup() {
void usesRegisteredEntityLookup() {
EntityLookup<Object> lookup = mock(EntityLookup.class);
@@ -91,8 +67,4 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
verify(lookup, times(1)).lookupEntity(eq(1L));
verify(invoker, never()).invokeFindById(eq(1L)); // DATAREST-1261
}
private static Consumer<AbstractOptionalAssert<?, Object>> $(Consumer<AbstractOptionalAssert<?, Object>> consumer) {
return consumer;
}
}