diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/AbstractIntegrationTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/AbstractIntegrationTests.java index 71abdd530..8d1a8c1f4 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/AbstractIntegrationTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/AbstractIntegrationTests.java @@ -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")); } } diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/PathUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/PathUnitTests.java index 0700e99ea..a6d5aa95f 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/PathUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/PathUnitTests.java @@ -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(); } } diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryRestConfigurationIntegrationTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryRestConfigurationIntegrationTests.java index 21e4db0a3..455e57310 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryRestConfigurationIntegrationTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryRestConfigurationIntegrationTests.java @@ -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) // diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryRestConfigurationUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryRestConfigurationUnitTests.java index 34ff18a56..520217e0b 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryRestConfigurationUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryRestConfigurationUnitTests.java @@ -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")); } diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/StringToLdapNameConverterUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/StringToLdapNameConverterUnitTests.java index e50bb14c4..e9e5646e3 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/StringToLdapNameConverterUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/StringToLdapNameConverterUnitTests.java @@ -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); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/UriToEntityConverterUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/UriToEntityConverterUnitTests.java index 9b1d7d7d0..703e1e747 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/UriToEntityConverterUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/UriToEntityConverterUnitTests.java @@ -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>(Arrays.asList(Entity.class, NonEntity.class))); @@ -72,7 +72,7 @@ public class UriToEntityConverterUnitTests { } @Test // DATAREST-427 - public void supportsOnlyEntitiesWithIdProperty() { + void supportsOnlyEntitiesWithIdProperty() { Set 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(); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/ValidationErrorsUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/ValidationErrorsUnitTests.java index 5defe5d72..945cf1fa7 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/ValidationErrorsUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/ValidationErrorsUnitTests.java @@ -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); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/config/ProjectionDefinitionConfigurationUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/config/ProjectionDefinitionConfigurationUnitTests.java index 0bdf67c78..23a8335b4 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/config/ProjectionDefinitionConfigurationUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/config/ProjectionDefinitionConfigurationUnitTests.java @@ -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); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/config/ResourceMappingUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/config/ResourceMappingUnitTests.java index 5610b54aa..b0ef89c42 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/config/ResourceMappingUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/config/ResourceMappingUnitTests.java @@ -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( diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/context/RepositoryEventIntegrationTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/context/RepositoryEventIntegrationTests.java index 4740eef45..e409f0ca1 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/context/RepositoryEventIntegrationTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/context/RepositoryEventIntegrationTests.java @@ -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()))); } } diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/context/ValidatorIntegrationTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/context/ValidatorIntegrationTests.java index 4041f99d4..7dbec75c7 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/context/ValidatorIntegrationTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/context/ValidatorIntegrationTests.java @@ -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", "")))); } } diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/AnnotatedPersonEventHandler.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/AnnotatedPersonEventHandler.java index ea4d8dd66..7cb3edbb7 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/AnnotatedPersonEventHandler.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/AnnotatedPersonEventHandler.java @@ -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(); } } diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/Order.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/Order.java index dd64b8821..1bf8090af 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/Order.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/Order.java @@ -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; diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/PersonNameValidator.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/PersonNameValidator.java index 093b86397..afb61b01f 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/PersonNameValidator.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/PersonNameValidator.java @@ -10,7 +10,7 @@ import org.springframework.validation.Validator; /** * A test {@link Validator} that checks for non-blank names. - * + * * @author Jon Brisbin */ @Component diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/ProfileLoader.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/ProfileLoader.java index 703192ca6..5d3aa7f4d 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/ProfileLoader.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/ProfileLoader.java @@ -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; diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/event/AnnotatedEventHandlerInvokerUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/event/AnnotatedEventHandlerInvokerUnitTests.java index 829fc9c5b..9be57b607 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/event/AnnotatedEventHandlerInvokerUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/event/AnnotatedEventHandlerInvokerUnitTests.java @@ -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 {} diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/CrudMethodsSupportedHttpMethodsUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/CrudMethodsSupportedHttpMethodsUnitTests.java index 69275712b..2126c9694 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/CrudMethodsSupportedHttpMethodsUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/CrudMethodsSupportedHttpMethodsUnitTests.java @@ -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); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/ExposureConfigurationUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/ExposureConfigurationUnitTests.java index 660a265ae..12b8ae422 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/ExposureConfigurationUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/ExposureConfigurationUnitTests.java @@ -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)); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/MappingResourceMetadataUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/MappingResourceMetadataUnitTests.java index dc1169eb5..cc93a78ef 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/MappingResourceMetadataUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/MappingResourceMetadataUnitTests.java @@ -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); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappingsUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappingsUnitTests.java index 6258d80ca..e296beb9c 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappingsUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappingsUnitTests.java @@ -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); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMappingUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMappingUnitTests.java index 6ddfc5e96..88de24872 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMappingUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMappingUnitTests.java @@ -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"); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMappingUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMappingUnitTests.java index ef14142b4..5b277eb48 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMappingUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMappingUnitTests.java @@ -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(); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryDetectionStrategiesUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryDetectionStrategiesUnitTests.java index ee5152ebd..9a555f8e6 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryDetectionStrategiesUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryDetectionStrategiesUnitTests.java @@ -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, Boolean>() { { @@ -51,7 +51,7 @@ public class RepositoryDetectionStrategiesUnitTests { } @Test // DATAREST-473 - public void defaultHonorsVisibilityAndAnnotations() { + void defaultHonorsVisibilityAndAnnotations() { assertExposures(DEFAULT, new HashMap, Boolean>() { { @@ -64,7 +64,7 @@ public class RepositoryDetectionStrategiesUnitTests { } @Test // DATAREST-473 - public void visibilityHonorsTypeVisibilityOnly() { + void visibilityHonorsTypeVisibilityOnly() { assertExposures(VISIBILITY, new HashMap, Boolean>() { { @@ -77,7 +77,7 @@ public class RepositoryDetectionStrategiesUnitTests { } @Test // DATAREST-473 - public void annotatedHonorsAnnotationsOnly() { + void annotatedHonorsAnnotationsOnly() { assertExposures(ANNOTATED, new HashMap, Boolean>() { { diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryMethodResourceMappingUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryMethodResourceMappingUnitTests.java index d489f3456..bf3579a55 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryMethodResourceMappingUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryMethodResourceMappingUnitTests.java @@ -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); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryResourceMappingsIntegrationTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryResourceMappingsIntegrationTests.java index 1b67d9a05..3119038c8 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryResourceMappingsIntegrationTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryResourceMappingsIntegrationTests.java @@ -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); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/TypeBasedCollectionResourceMappingUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/TypeBasedCollectionResourceMappingUnitTests.java index de453956e..3f64303dd 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/TypeBasedCollectionResourceMappingUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/TypeBasedCollectionResourceMappingUnitTests.java @@ -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(); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/DefaultSelfLinkProviderUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/DefaultSelfLinkProviderUnitTests.java index 08f978bae..cf07252b6 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/DefaultSelfLinkProviderUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/DefaultSelfLinkProviderUnitTests.java @@ -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> 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 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())) // diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/ResourceStringUtilsTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/ResourceStringUtilsTests.java index 9c87da9ad..5dc5fbe11 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/ResourceStringUtilsTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/ResourceStringUtilsTests.java @@ -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 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 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 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; } } diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactoryUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactoryUnitTests.java index c5eac898e..85d0afe7e 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactoryUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactoryUnitTests.java @@ -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> 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 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 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> $(Consumer> consumer) { - return consumer; - } } diff --git a/spring-data-rest-hal-explorer/src/test/java/org/springframework/data/rest/webmvc/halexplorer/HalExplorerIntegrationTests.java b/spring-data-rest-hal-explorer/src/test/java/org/springframework/data/rest/webmvc/halexplorer/HalExplorerIntegrationTests.java index e31908ae9..4f15ed375 100755 --- a/spring-data-rest-hal-explorer/src/test/java/org/springframework/data/rest/webmvc/halexplorer/HalExplorerIntegrationTests.java +++ b/spring-data-rest-hal-explorer/src/test/java/org/springframework/data/rest/webmvc/halexplorer/HalExplorerIntegrationTests.java @@ -19,9 +19,9 @@ import static org.hamcrest.CoreMatchers.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -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.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -32,7 +32,7 @@ import org.springframework.hateoas.MediaTypes; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -45,10 +45,10 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; * @author Oliver Gierke * @soundtrack Miles Davis - Blue in green (Kind of blue) */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration -public class HalExplorerIntegrationTests { +class HalExplorerIntegrationTests { static final String BASE_PATH = "/api"; static final String EXPLORER_INDEX = "/explorer/index.html"; @@ -69,14 +69,14 @@ public class HalExplorerIntegrationTests { MockMvc mvc; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.mvc = MockMvcBuilders.webAppContextSetup(context).// defaultRequest(get(BASE_PATH).accept(MediaType.TEXT_HTML)).build(); } @Test // DATAREST-293 - public void exposesJsonUnderApiRootByDefault() throws Exception { + void exposesJsonUnderApiRootByDefault() throws Exception { mvc.perform(get(BASE_PATH).accept(MediaType.ALL)).// andExpect(status().isOk()).// @@ -84,7 +84,7 @@ public class HalExplorerIntegrationTests { } @Test // DATAREST-293 - public void redirectsToBrowserForApiRootAndHtml() throws Exception { + void redirectsToBrowserForApiRootAndHtml() throws Exception { mvc.perform(get(BASE_PATH).accept(MediaType.TEXT_HTML)).// andExpect(status().isFound()).// @@ -92,7 +92,7 @@ public class HalExplorerIntegrationTests { } @Test // DATAREST-293 - public void forwardsBrowserToIndexHtml() throws Exception { + void forwardsBrowserToIndexHtml() throws Exception { mvc.perform(get(BASE_PATH.concat("/explorer"))).// andExpect(status().isFound()).// @@ -100,7 +100,7 @@ public class HalExplorerIntegrationTests { } @Test // DATAREST-293 - public void exposesHalBrowser() throws Exception { + void exposesHalBrowser() throws Exception { mvc.perform(get(BASE_PATH.concat("/explorer/index.html"))).// andExpect(status().isOk()).// @@ -108,7 +108,7 @@ public class HalExplorerIntegrationTests { } @Test // DATAREST-293 - public void retrunsApiIfHtmlIsNotExplicitlyListed() throws Exception { + void retrunsApiIfHtmlIsNotExplicitlyListed() throws Exception { mvc.perform(get(BASE_PATH).accept(MediaType.APPLICATION_JSON, MediaType.ALL)).// andExpect(status().isOk()).// diff --git a/spring-data-rest-hal-explorer/src/test/java/org/springframework/data/rest/webmvc/halexplorer/HalExplorerUnitTests.java b/spring-data-rest-hal-explorer/src/test/java/org/springframework/data/rest/webmvc/halexplorer/HalExplorerUnitTests.java index 6965bd4d7..958a5e809 100755 --- a/spring-data-rest-hal-explorer/src/test/java/org/springframework/data/rest/webmvc/halexplorer/HalExplorerUnitTests.java +++ b/spring-data-rest-hal-explorer/src/test/java/org/springframework/data/rest/webmvc/halexplorer/HalExplorerUnitTests.java @@ -23,8 +23,7 @@ import java.util.Collections; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; -import org.junit.Test; - +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; @@ -41,10 +40,10 @@ import org.springframework.web.util.UriComponentsBuilder; * @author Mark Paluch * @soundtrack Nils Wülker - Homeless Diamond (feat. Lauren Flynn) */ -public class HalExplorerUnitTests { +class HalExplorerUnitTests { @Test // DATAREST-565, DATAREST-720 - public void createsContextRelativeRedirectForBrowser() throws Exception { + void createsContextRelativeRedirectForBrowser() throws Exception { MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -64,7 +63,7 @@ public class HalExplorerUnitTests { } @Test // DATAREST-1264 - public void producesProxyRelativeRedirectIfNecessary() throws ServletException, IOException { + void producesProxyRelativeRedirectIfNecessary() throws ServletException, IOException { MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/explorer"); diff --git a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractControllerIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractControllerIntegrationTests.java index fedbe36d9..ac2073728 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractControllerIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractControllerIntegrationTests.java @@ -1,4 +1,3 @@ -package org.springframework.data.rest.tests; /* * Copyright 2013-2021 the original author or authors. * @@ -14,11 +13,12 @@ package org.springframework.data.rest.tests; * See the License for the specific language governing permissions and * limitations under the License. */ +package org.springframework.data.rest.tests; import java.util.Collections; -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.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -41,7 +41,7 @@ import org.springframework.data.rest.webmvc.support.Projector; import org.springframework.hateoas.server.EntityLinks; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.Assert; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -53,7 +53,7 @@ import org.springframework.web.context.request.WebRequest; * * @author Oliver Gierke */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration public abstract class AbstractControllerIntegrationTests { @@ -79,7 +79,7 @@ public abstract class AbstractControllerIntegrationTests { @Autowired RepositoryInvokerFactory invokerFactory; @Autowired ResourceMappings mappings; - @Before + @BeforeEach public void initWebInfrastructure() { TestMvcClient.initWebTest(); } diff --git a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java index 2e449ba04..cc1f08075 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java @@ -20,13 +20,14 @@ import static org.hamcrest.CoreMatchers.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import net.minidev.json.JSONArray; + import java.util.Collections; import java.util.Map; import java.util.Optional; -import net.minidev.json.JSONArray; -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.webmvc.config.RepositoryRestMvcConfiguration; import org.springframework.hateoas.Link; @@ -36,7 +37,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultMatcher; @@ -61,7 +62,7 @@ import com.jayway.jsonpath.JsonPath; * @author Christoph Strobl * @author Ľubomír Varga */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = { RepositoryRestMvcConfiguration.class, DelegatingWebMvcConfiguration.class }) public abstract class AbstractWebIntegrationTests { @@ -74,7 +75,7 @@ public abstract class AbstractWebIntegrationTests { protected TestMvcClient client; protected MockMvc mvc; - @Before + @BeforeEach public void setUp() { setupMockMvc(); this.client = new TestMvcClient(mvc, discoverers); diff --git a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java index 8bec7e094..e33d72650 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java @@ -17,16 +17,17 @@ package org.springframework.data.rest.tests; import static org.assertj.core.api.Assertions.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assume.*; +import static org.junit.jupiter.api.Assumptions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import net.minidev.json.JSONArray; + import java.net.URI; import java.util.List; import java.util.Map; -import net.minidev.json.JSONArray; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.rest.webmvc.RestMediaTypes; import org.springframework.hateoas.IanaLinkRelations; import org.springframework.hateoas.Link; @@ -57,7 +58,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { // Root test cases @Test - public void exposesRootResource() throws Exception { + void exposesRootResource() throws Exception { ResultActions actions = mvc.perform(get("/").accept(TestMvcClient.DEFAULT_MEDIA_TYPE)).andExpect(status().isOk()); @@ -67,7 +68,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-113, DATAREST-638 - public void exposesSchemasForResourcesExposed() throws Exception { + void exposesSchemasForResourcesExposed() throws Exception { MockHttpServletResponse response = client.request("/"); @@ -92,7 +93,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-203 - public void servesHalWhenRequested() throws Exception { + void servesHalWhenRequested() throws Exception { mvc.perform(get("/")). // andExpect(content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)). // @@ -100,7 +101,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-203 - public void servesHalWhenJsonIsRequested() throws Exception { + void servesHalWhenJsonIsRequested() throws Exception { mvc.perform(get("/").accept(MediaType.APPLICATION_JSON)). // andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)). // @@ -108,7 +109,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-203 - public void exposesSearchesForRootResources() throws Exception { + void exposesSearchesForRootResources() throws Exception { MockHttpServletResponse response = client.request("/"); @@ -135,7 +136,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { } @Test - public void nic() throws Exception { + void nic() throws Exception { Map payloads = getPayloadToPost(); assumeFalse(payloads.isEmpty()); @@ -162,7 +163,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-198 - public void accessLinkedResources() throws Exception { + void accessLinkedResources() throws Exception { MockHttpServletResponse rootResource = client.request("/"); @@ -188,7 +189,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-230 - public void exposesDescriptionAsAlpsDocuments() throws Exception { + void exposesDescriptionAsAlpsDocuments() throws Exception { MediaType ALPS_MEDIA_TYPE = MediaType.valueOf("application/alps+json"); @@ -204,14 +205,14 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-448 - public void returnsNotFoundForUriNotBackedByARepository() throws Exception { + void returnsNotFoundForUriNotBackedByARepository() throws Exception { mvc.perform(get("/index.html")).// andExpect(status().isNotFound()); } @Test // DATAREST-658 - public void collectionResourcesExposeLinksAsHeadersForHeadRequest() throws Exception { + void collectionResourcesExposeLinksAsHeadersForHeadRequest() throws Exception { for (LinkRelation rel : expectedRootLinkRels()) { @@ -229,7 +230,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-661 - public void patchToNonExistingResourceReturnsNotFound() throws Exception { + void patchToNonExistingResourceReturnsNotFound() throws Exception { LinkRelation rel = expectedRootLinkRels().iterator().next(); String uri = client.discoverUnique(rel).expand().getHref().concat("/"); @@ -249,7 +250,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-1003 - public void rejectsUnsupportedAcceptTypeForResources() throws Exception { + void rejectsUnsupportedAcceptTypeForResources() throws Exception { for (LinkRelation string : expectedRootLinkRels()) { diff --git a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/TestMvcClient.java b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/TestMvcClient.java index 7dc7a2f80..0f4e29710 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/TestMvcClient.java +++ b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/TestMvcClient.java @@ -15,9 +15,7 @@ */ package org.springframework.data.rest.tests; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -26,10 +24,10 @@ import java.util.Iterator; import java.util.Optional; import org.springframework.hateoas.Link; -import org.springframework.hateoas.client.LinkDiscoverer; -import org.springframework.hateoas.client.LinkDiscoverers; import org.springframework.hateoas.LinkRelation; import org.springframework.hateoas.Links; +import org.springframework.hateoas.client.LinkDiscoverer; +import org.springframework.hateoas.client.LinkDiscoverers; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -85,8 +83,8 @@ public class TestMvcClient { HttpHeaders headers = response.getHeaders(); - assertThat(headers.getAllow(), hasSize(methods.length)); - assertThat(headers.getAllow(), hasItems(methods)); + assertThat(headers.getAllow()).hasSize(methods.length); + assertThat(headers.getAllow()).contains(methods); } /** @@ -356,8 +354,10 @@ public class TestMvcClient { MockHttpServletResponse response = result.getResponse(); String s = response.getContentAsString(); - assertThat("Expected to find link with rel " + rel + " but found none in " + s, // - getDiscoverer(response).findLinkWithRel(rel, s), notNullValue()); + assertThat(getDiscoverer(response).findLinkWithRel(rel, s)) // + .as(() -> "Expected to find link with rel " + rel + " but found none in " + s) // + .isNotNull(); + }; } diff --git a/spring-data-rest-tests/spring-data-rest-tests-geode/src/test/java/org/springframework/data/rest/tests/geode/GeodeRepositoryConfig.java b/spring-data-rest-tests/spring-data-rest-tests-geode/src/test/java/org/springframework/data/rest/tests/geode/GeodeRepositoryConfig.java index 01ec1ead2..6d9d620e2 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-geode/src/test/java/org/springframework/data/rest/tests/geode/GeodeRepositoryConfig.java +++ b/spring-data-rest-tests/spring-data-rest-tests-geode/src/test/java/org/springframework/data/rest/tests/geode/GeodeRepositoryConfig.java @@ -32,7 +32,7 @@ import org.springframework.data.util.AnnotatedTypeScanner; @Configuration @ImportResource("classpath:META-INF/spring/cache-config.xml") @EnableGemfireRepositories -public class GeodeRepositoryConfig { +class GeodeRepositoryConfig { /** * TODO: Remove, once Spring Data Gemfire exposes a mapping context. diff --git a/spring-data-rest-tests/spring-data-rest-tests-geode/src/test/java/org/springframework/data/rest/tests/geode/GeodeWebTests.java b/spring-data-rest-tests/spring-data-rest-tests-geode/src/test/java/org/springframework/data/rest/tests/geode/GeodeWebTests.java index 51fbdfd6f..29bbbe824 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-geode/src/test/java/org/springframework/data/rest/tests/geode/GeodeWebTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-geode/src/test/java/org/springframework/data/rest/tests/geode/GeodeWebTests.java @@ -23,7 +23,7 @@ import org.springframework.test.context.ContextConfiguration; * @author Oliver Gierke */ @ContextConfiguration(classes = GeodeRepositoryConfig.class) -public class GeodeWebTests extends CommonWebTests { +class GeodeWebTests extends CommonWebTests { /* * (non-Javadoc) diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryControllerIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryControllerIntegrationTests.java index 6466e38c6..d2cd31a89 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryControllerIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryControllerIntegrationTests.java @@ -18,7 +18,7 @@ package org.springframework.data.rest.webmvc; import static org.assertj.core.api.Assertions.*; import static org.springframework.data.rest.tests.TestMvcClient.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.rest.tests.AbstractControllerIntegrationTests; import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig; @@ -36,24 +36,24 @@ import org.springframework.transaction.annotation.Transactional; */ @ContextConfiguration(classes = JpaRepositoryConfig.class) @Transactional -public class RepositoryControllerIntegrationTests extends AbstractControllerIntegrationTests { +class RepositoryControllerIntegrationTests extends AbstractControllerIntegrationTests { @Autowired RepositoryController controller; @Test // DATAREST-333 - public void rootResourceExposesGetOnly() { + void rootResourceExposesGetOnly() { HttpEntity response = controller.optionsForRepositories(); assertAllowHeaders(response, HttpMethod.GET); } @Test // DATAREST-333, DATAREST-330 - public void headRequestReturnsNoContent() { + void headRequestReturnsNoContent() { assertThat(controller.headForRepositories().getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); } @Test // DATAREST-160, DATAREST-333, DATAREST-463 - public void exposesLinksToRepositories() { + void exposesLinksToRepositories() { RepositoryLinksResource resource = controller.listRepositories().getBody(); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryEntityControllerIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryEntityControllerIntegrationTests.java index f56e684fe..0562df7d3 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryEntityControllerIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryEntityControllerIntegrationTests.java @@ -23,7 +23,7 @@ import static org.springframework.http.HttpMethod.*; import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -62,7 +62,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException; */ @ContextConfiguration(classes = { ConfigurationCustomizer.class, JpaRepositoryConfig.class }) @Transactional -public class RepositoryEntityControllerIntegrationTests extends AbstractControllerIntegrationTests { +class RepositoryEntityControllerIntegrationTests extends AbstractControllerIntegrationTests { @Autowired RepositoryEntityController controller; @Autowired AddressRepository repository; @@ -82,25 +82,28 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll } } - @Test(expected = HttpRequestMethodNotSupportedException.class) // DATAREST-217 - public void returnsNotFoundForListingEntitiesIfFindAllNotExported() throws Exception { + @Test // DATAREST-217 + void returnsNotFoundForListingEntitiesIfFindAllNotExported() throws Exception { repository.save(new Address()); RootResourceInformation request = getResourceInformation(Address.class); - controller.getCollectionResource(request, null, null, null); + + assertThatExceptionOfType(HttpRequestMethodNotSupportedException.class) // + .isThrownBy(() -> controller.getCollectionResource(request, null, null, null)); } - @Test(expected = HttpRequestMethodNotSupportedException.class) // DATAREST-217 - public void rejectsEntityCreationIfSaveIsNotExported() throws Exception { + @Test // DATAREST-217 + void rejectsEntityCreationIfSaveIsNotExported() throws Exception { RootResourceInformation request = getResourceInformation(Address.class); - controller.postCollectionResource(request, null, null, MediaType.APPLICATION_JSON_VALUE); + assertThatExceptionOfType(HttpRequestMethodNotSupportedException.class) // + .isThrownBy(() -> controller.postCollectionResource(request, null, null, MediaType.APPLICATION_JSON_VALUE)); } @Test // DATAREST-301 - public void setsExpandedSelfUriInLocationHeader() throws Exception { + void setsExpandedSelfUriInLocationHeader() throws Exception { RootResourceInformation information = getResourceInformation(Order.class); @@ -114,20 +117,25 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll } @Test // DATAREST-330 - public void exposesHeadForCollectionResourceIfExported() throws Exception { + void exposesHeadForCollectionResourceIfExported() throws Exception { ResponseEntity entity = controller.headCollectionResource(getResourceInformation(Person.class), new DefaultedPageable(Pageable.unpaged(), false)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); } - @Test(expected = ResourceNotFoundException.class) // DATAREST-330 - public void doesNotExposeHeadForCollectionResourceIfNotExported() throws Exception { - controller.headCollectionResource(getResourceInformation(CreditCard.class), - new DefaultedPageable(Pageable.unpaged(), false)); + @Test // DATAREST-330 + void doesNotExposeHeadForCollectionResourceIfNotExported() throws Exception { + + assertThatExceptionOfType(ResourceNotFoundException.class) // + .isThrownBy(() -> { + + controller.headCollectionResource(getResourceInformation(CreditCard.class), + new DefaultedPageable(Pageable.unpaged(), false)); + }); } @Test // DATAREST-330 - public void exposesHeadForItemResourceIfExported() throws Exception { + void exposesHeadForItemResourceIfExported() throws Exception { Address address = repository.save(new Address()); @@ -137,34 +145,36 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); } - @Test(expected = ResourceNotFoundException.class) // DATAREST-330 - public void doesNotExposeHeadForItemResourceIfNotExisting() throws Exception { - controller.headForItemResource(getResourceInformation(CreditCard.class), 1L, assembler); + @Test // DATAREST-330 + void doesNotExposeHeadForItemResourceIfNotExisting() throws Exception { + + assertThatExceptionOfType(ResourceNotFoundException.class) // + .isThrownBy(() -> controller.headForItemResource(getResourceInformation(CreditCard.class), 1L, assembler)); } @Test // DATAREST-333 - public void doesNotExposeMethodsForOptionsIfNotHttpMethodsSupportedForCollectionResource() { + void doesNotExposeMethodsForOptionsIfNotHttpMethodsSupportedForCollectionResource() { HttpEntity response = controller.optionsForCollectionResource(getResourceInformation(Address.class)); assertAllowHeaders(response, OPTIONS); } @Test // DATAREST-333 - public void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToCollectionResource() { + void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToCollectionResource() { HttpEntity response = controller.optionsForCollectionResource(getResourceInformation(Person.class)); assertAllowHeaders(response, GET, POST, HEAD, OPTIONS); } @Test // DATAREST-333 - public void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToItemResource() { + void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToItemResource() { HttpEntity response = controller.optionsForItemResource(getResourceInformation(Person.class)); assertAllowHeaders(response, GET, PUT, PATCH, DELETE, HEAD, OPTIONS); } @Test // DATAREST-333, DATAREST-348 - public void optionsForItermResourceSetsAllowPatchHeader() { + void optionsForItermResourceSetsAllowPatchHeader() { ResponseEntity entity = controller.optionsForItemResource(getResourceInformation(Person.class)); @@ -176,7 +186,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll } @Test // DATAREST-34 - public void returnsBodyOnPutForUpdateIfAcceptHeaderPresentByDefault() throws Exception { + void returnsBodyOnPutForUpdateIfAcceptHeaderPresentByDefault() throws Exception { RootResourceInformation request = getResourceInformation(Order.class); Order order = request.getInvoker().invokeSave(new Order(new Person())); @@ -189,7 +199,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll } @Test // DATAREST-34 - public void returnsBodyForCreatingPutIfAcceptHeaderPresentByDefault() throws HttpRequestMethodNotSupportedException { + void returnsBodyForCreatingPutIfAcceptHeaderPresentByDefault() throws HttpRequestMethodNotSupportedException { RootResourceInformation request = getResourceInformation(Order.class); PersistentEntityResource persistentEntityResource = PersistentEntityResource @@ -200,7 +210,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll } @Test // DATAREST-34 - public void returnsBodyForPostIfAcceptHeaderIsPresentByDefault() throws Exception { + void returnsBodyForPostIfAcceptHeaderIsPresentByDefault() throws Exception { RootResourceInformation request = getResourceInformation(Order.class); PersistentEntityResource persistentEntityResource = PersistentEntityResource @@ -212,7 +222,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll } @Test // DATAREST-34 - public void doesNotReturnBodyForPostIfNoAcceptHeaderPresentByDefault() throws Exception { + void doesNotReturnBodyForPostIfNoAcceptHeaderPresentByDefault() throws Exception { RootResourceInformation request = getResourceInformation(Order.class); PersistentEntityResource persistentEntityResource = PersistentEntityResource @@ -224,7 +234,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll } @Test // DATAREST-581 - public void createsEtagForProjectedEntityCorrectly() throws Exception { + void createsEtagForProjectedEntityCorrectly() throws Exception { Address address = repository.save(new Address()); @@ -244,7 +254,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll } @Test // DATAREST-724 - public void deletesEntityWithCustomLookupCorrectly() throws Exception { + void deletesEntityWithCustomLookupCorrectly() throws Exception { Address address = repository.save(new Address()); assertThat(repository.findById(address.id)).isNotNull(); @@ -262,7 +272,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll } @Test // DATAREST-948 - public void rejectsPutForCreationIfConfigured() throws HttpRequestMethodNotSupportedException { + void rejectsPutForCreationIfConfigured() throws HttpRequestMethodNotSupportedException { RootResourceInformation request = getResourceInformation(Address.class); PersistentEntityResource persistentEntityResource = PersistentEntityResource diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerIntegrationTests.java index df000227c..5e5ed4cc3 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerIntegrationTests.java @@ -18,9 +18,8 @@ package org.springframework.data.rest.webmvc; 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.beans.factory.annotation.Autowired; import org.springframework.data.rest.tests.AbstractControllerIntegrationTests; import org.springframework.data.rest.webmvc.jpa.Book; @@ -36,7 +35,7 @@ import org.springframework.transaction.annotation.Transactional; */ @ContextConfiguration(classes = JpaRepositoryConfig.class) @Transactional -public class RepositoryPropertyReferenceControllerIntegrationTests extends AbstractControllerIntegrationTests { +class RepositoryPropertyReferenceControllerIntegrationTests extends AbstractControllerIntegrationTests { @Autowired RepositoryPropertyReferenceController controller; @Autowired TestDataPopulator populator; @@ -45,8 +44,8 @@ public class RepositoryPropertyReferenceControllerIntegrationTests extends Abstr PersistentEntityResourceAssembler assembler; RootResourceInformation information; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.assembler = mock(PersistentEntityResourceAssembler.class); this.information = getResourceInformation(Book.class); @@ -54,7 +53,7 @@ public class RepositoryPropertyReferenceControllerIntegrationTests extends Abstr } @Test - public void exposesResourceForCustomizedPropertyResourcePath() throws Exception { + void exposesResourceForCustomizedPropertyResourcePath() throws Exception { Book book = books.findAll().iterator().next(); @@ -62,11 +61,12 @@ public class RepositoryPropertyReferenceControllerIntegrationTests extends Abstr .isEqualTo(HttpStatus.OK); } - @Test(expected = ResourceNotFoundException.class) - public void doesNotExposeOriginalPathIfPropertyResourcePathIsCustomized() throws Exception { + @Test + void doesNotExposeOriginalPathIfPropertyResourcePathIsCustomized() { Book book = books.findAll().iterator().next(); - controller.followPropertyReference(information, book.id, "authors", assembler); + assertThatExceptionOfType(ResourceNotFoundException.class) // + .isThrownBy(() -> controller.followPropertyReference(information, book.id, "authors", assembler)); } } diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java index ae5def0ce..3622af230 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java @@ -18,8 +18,8 @@ package org.springframework.data.rest.webmvc; import static org.assertj.core.api.Assertions.*; import static org.springframework.data.rest.tests.TestMvcClient.*; -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.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; @@ -35,9 +35,9 @@ import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig; import org.springframework.data.rest.webmvc.jpa.Person; import org.springframework.data.rest.webmvc.jpa.TestDataPopulator; import org.springframework.data.rest.webmvc.support.DefaultedPageable; +import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.PagedModel; import org.springframework.hateoas.RepresentationModel; -import org.springframework.hateoas.CollectionModel; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -55,7 +55,7 @@ import org.springframework.util.MultiValueMap; */ @ContextConfiguration(classes = JpaRepositoryConfig.class) @Transactional -public class RepositorySearchControllerIntegrationTests extends AbstractControllerIntegrationTests { +class RepositorySearchControllerIntegrationTests extends AbstractControllerIntegrationTests { static final DefaultedPageable PAGEABLE = new DefaultedPageable(PageRequest.of(0, 10), true); @@ -63,16 +63,16 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll @Autowired RepositorySearchController controller; @Autowired PersistentEntityResourceAssembler assembler; - @Before - public void setUp() { + @BeforeEach + void setUp() { loader.populateRepositories(); } @Test - public void rendersCorrectSearchLinksForPersons() throws Exception { + void rendersCorrectSearchLinksForPersons() throws Exception { RootResourceInformation request = getResourceInformation(Person.class); - RepresentationModel resource = controller.listSearches(request); + RepresentationModel resource = controller.listSearches(request); ResourceTester tester = ResourceTester.of(resource); tester.assertNumberOfLinks(7); // Self link included @@ -86,18 +86,22 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll tester.assertHasLinkEndingWith("findCreatedDateByLastName", "findCreatedDateByLastName{?lastname}"); } - @Test(expected = ResourceNotFoundException.class) - public void returns404ForUnexportedRepository() { - controller.listSearches(getResourceInformation(CreditCard.class)); - } + @Test + void returns404ForUnexportedRepository() { - @Test(expected = ResourceNotFoundException.class) - public void returns404ForRepositoryWithoutSearches() { - controller.listSearches(getResourceInformation(Author.class)); + assertThatExceptionOfType(ResourceNotFoundException.class) // + .isThrownBy(() -> controller.listSearches(getResourceInformation(CreditCard.class))); } @Test - public void executesSearchAgainstRepository() { + void returns404ForRepositoryWithoutSearches() { + + assertThatExceptionOfType(ResourceNotFoundException.class) // + .isThrownBy(() -> controller.listSearches(getResourceInformation(Author.class))); + } + + @Test + void executesSearchAgainstRepository() { RootResourceInformation resourceInformation = getResourceInformation(Person.class); MultiValueMap parameters = new LinkedMultiValueMap(1); @@ -114,43 +118,51 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll tester.withContentResource(new HasSelfLink(BASE.slash(metadata.getPath()).slash("{id}"))); } - @Test(expected = ResourceNotFoundException.class) // DATAREST-330 - public void doesNotExposeHeadForSearchResourceIfResourceDoesnHaveSearches() { - controller.headForSearches(getResourceInformation(Author.class)); - } + @Test // DATAREST-330 + void doesNotExposeHeadForSearchResourceIfResourceDoesnHaveSearches() { - @Test(expected = ResourceNotFoundException.class) // DATAREST-330 - public void exposesHeadForSearchResourceIfResourceIsNotExposed() { - controller.headForSearches(getResourceInformation(CreditCard.class)); + assertThatExceptionOfType(ResourceNotFoundException.class) // + .isThrownBy(() -> controller.headForSearches(getResourceInformation(Author.class))); } @Test // DATAREST-330 - public void exposesHeadForSearchResourceIfResourceIsExposed() { + void exposesHeadForSearchResourceIfResourceIsNotExposed() { + + assertThatExceptionOfType(ResourceNotFoundException.class) // + .isThrownBy(() -> controller.headForSearches(getResourceInformation(CreditCard.class))); + } + + @Test // DATAREST-330 + void exposesHeadForSearchResourceIfResourceIsExposed() { controller.headForSearches(getResourceInformation(Person.class)); } @Test // DATAREST-330 - public void exposesHeadForExistingQueryMethodResource() { + void exposesHeadForExistingQueryMethodResource() { controller.headForSearch(getResourceInformation(Person.class), "findByCreatedUsingISO8601Date"); } - @Test(expected = ResourceNotFoundException.class) // DATAREST-330 - public void doesNotExposeHeadForInvalidQueryMethodResource() { - controller.headForSearch(getResourceInformation(Person.class), "foobar"); + @Test // DATAREST-330 + void doesNotExposeHeadForInvalidQueryMethodResource() { + + assertThatExceptionOfType(ResourceNotFoundException.class) // + .isThrownBy(() -> controller.headForSearch(getResourceInformation(Person.class), "foobar")); } @Test // DATAREST-333 - public void searchResourceSupportsGetOnly() { + void searchResourceSupportsGetOnly() { assertAllowHeaders(controller.optionsForSearches(getResourceInformation(Person.class)), HttpMethod.GET); } - @Test(expected = ResourceNotFoundException.class) // DATAREST-333 - public void returns404ForOptionsForRepositoryWithoutSearches() { - controller.optionsForSearches(getResourceInformation(Address.class)); + @Test // DATAREST-333 + void returns404ForOptionsForRepositoryWithoutSearches() { + + assertThatExceptionOfType(ResourceNotFoundException.class) // + .isThrownBy(() -> controller.optionsForSearches(getResourceInformation(Address.class))); } @Test // DATAREST-333 - public void queryMethodResourceSupportsGetOnly() { + void queryMethodResourceSupportsGetOnly() { RootResourceInformation resourceInformation = getResourceInformation(Person.class); HttpEntity response = controller.optionsForSearch(resourceInformation, "firstname"); @@ -159,7 +171,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll } @Test // DATAREST-502 - public void interpretsUriAsReferenceToRelatedEntity() { + void interpretsUriAsReferenceToRelatedEntity() { MultiValueMap parameters = new LinkedMultiValueMap(1); parameters.add("author", "/author/1"); @@ -173,7 +185,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll } @Test // DATAREST-515 - public void repositorySearchResourceExposesDomainType() { + void repositorySearchResourceExposesDomainType() { RepositorySearchesResource searches = controller.listSearches(getResourceInformation(Person.class)); @@ -181,7 +193,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll } @Test // DATAREST-1121 - public void returnsSimpleResponseEntityForQueryMethod() { + void returnsSimpleResponseEntityForQueryMethod() { MultiValueMap parameters = new LinkedMultiValueMap(); parameters.add("lastname", "Thornton"); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RootResourceInformationIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RootResourceInformationIntegrationTests.java index 51791d91e..6711108c2 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RootResourceInformationIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/RootResourceInformationIntegrationTests.java @@ -19,14 +19,15 @@ import static org.assertj.core.api.Assertions.*; import static org.springframework.data.rest.core.mapping.ResourceType.*; import static org.springframework.http.HttpMethod.*; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.data.rest.core.mapping.ResourceType; import org.springframework.data.rest.core.mapping.SupportedHttpMethods; import org.springframework.data.rest.tests.AbstractControllerIntegrationTests; import org.springframework.data.rest.webmvc.jpa.Address; import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; /** @@ -34,20 +35,20 @@ import org.springframework.transaction.annotation.Transactional; * * @author Oliver Gierke */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = JpaRepositoryConfig.class) @Transactional -public class RootResourceInformationIntegrationTests extends AbstractControllerIntegrationTests { +class RootResourceInformationIntegrationTests extends AbstractControllerIntegrationTests { @Test // DATAREST-217 - public void getIsNotSupportedIfFindAllIsNotExported() { + void getIsNotSupportedIfFindAllIsNotExported() { SupportedHttpMethods supportedMethods = getResourceInformation(Address.class).getSupportedMethods(); assertThat(supportedMethods.getMethodsFor(COLLECTION)).doesNotContain(GET); } @Test // DATAREST-217 - public void postIsNotSupportedIfSaveIsNotExported() { + void postIsNotSupportedIfSaveIsNotExported() { SupportedHttpMethods supportedMethods = getResourceInformation(Address.class).getSupportedMethods(); assertThat(supportedMethods.getMethodsFor(COLLECTION)).doesNotContain(POST); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java index 64a5738d9..2b17f54d9 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java @@ -15,15 +15,16 @@ */ package org.springframework.data.rest.webmvc.alps; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import net.minidev.json.JSONArray; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -48,8 +49,6 @@ import org.springframework.web.context.WebApplicationContext; import com.jayway.jsonpath.JsonPath; -import net.minidev.json.JSONArray; - /** * Integration tests for {@link AlpsController}. * @@ -58,7 +57,7 @@ import net.minidev.json.JSONArray; */ @WebAppConfiguration @ContextConfiguration(classes = { JpaRepositoryConfig.class, AlpsControllerIntegrationTests.Config.class }) -public class AlpsControllerIntegrationTests extends AbstractControllerIntegrationTests { +class AlpsControllerIntegrationTests extends AbstractControllerIntegrationTests { @Autowired WebApplicationContext context; @Autowired LinkDiscoverers discoverers; @@ -81,20 +80,20 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio TestMvcClient client; - @Before - public void setUp() { + @BeforeEach + void setUp() { MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build(); this.client = new TestMvcClient(mvc, this.discoverers); } - @After - public void tearDown() { + @AfterEach + void tearDown() { configuration.setEnableEnumTranslation(false); } @Test // DATAREST-230 - public void exposesAlpsCollectionResources() throws Exception { + void exposesAlpsCollectionResources() throws Exception { Link profileLink = client.discoverUnique("profile"); Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL); @@ -105,7 +104,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio } @Test // DATAREST-638 - public void verifyThatAlpsIsDefaultProfileFormat() throws Exception { + void verifyThatAlpsIsDefaultProfileFormat() throws Exception { Link profileLink = client.discoverUnique("profile"); Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL); @@ -117,7 +116,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio } @Test // DATAREST-463 - public void verifyThatAttributesIgnoredDontAppearInAlps() throws Exception { + void verifyThatAttributesIgnoredDontAppearInAlps() throws Exception { Link profileLink = client.discoverUnique("profile"); Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL); @@ -132,7 +131,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio } @Test // DATAREST-494 - public void linksToJsonSchemaFromRepresentationDescriptor() throws Exception { + void linksToJsonSchemaFromRepresentationDescriptor() throws Exception { Link profileLink = client.discoverUnique("profile"); Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL); @@ -143,11 +142,11 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio String href = JsonPath. read(result, "$.alps.descriptor[?(@.id == 'item-representation')].href").get(0) .toString(); - assertThat(href, endsWith("/profile/items")); + assertThat(href).endsWith("/profile/items"); } @Test // DATAREST-516 - public void referenceToAssociatedEntityDesciptorPointsToRepresentationDescriptor() throws Exception { + void referenceToAssociatedEntityDesciptorPointsToRepresentationDescriptor() throws Exception { Link profileLink = client.discoverUnique("profile"); Link usersLink = client.discoverUnique(profileLink, "people", MediaType.ALL); @@ -164,7 +163,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio } @Test // DATAREST-630 - public void onlyExposesIdAttributesWhenExposedInTheConfiguration() throws Exception { + void onlyExposesIdAttributesWhenExposedInTheConfiguration() throws Exception { Link profileLink = client.discoverUnique("profile"); Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL); @@ -175,7 +174,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio } @Test // DATAREST-683 - public void enumValueListingsAreTranslatedIfEnabled() throws Exception { + void enumValueListingsAreTranslatedIfEnabled() throws Exception { configuration.setEnableEnumTranslation(true); @@ -193,7 +192,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio } @Test // DATAREST-753 - public void alpsCanHandleGroovyDomainObjects() throws Exception { + void alpsCanHandleGroovyDomainObjects() throws Exception { Link profileLink = client.discoverUnique("profile"); Link groovyDomainObjectLink = client.discoverUnique(profileLink, "simulatedGroovyDomainClasses"); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/CorsIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/CorsIntegrationTests.java index 65f2ed791..acb94cacc 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/CorsIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/CorsIntegrationTests.java @@ -20,7 +20,7 @@ import static org.hamcrest.Matchers.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.rest.tests.AbstractWebIntegrationTests; @@ -48,7 +48,7 @@ import org.springframework.web.bind.annotation.RequestMethod; * @soundtrack 2 Unlimited - No Limit */ @ContextConfiguration -public class CorsIntegrationTests extends AbstractWebIntegrationTests { +class CorsIntegrationTests extends AbstractWebIntegrationTests { @Configuration static class CorsConfig extends JpaRepositoryConfig { @@ -81,7 +81,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-573 - public void appliesSelectiveDefaultCorsConfiguration() throws Exception { + void appliesSelectiveDefaultCorsConfiguration() throws Exception { Link findItems = client.discoverUnique(LinkRelation.of("items")); @@ -98,7 +98,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-573 - public void appliesGlobalCorsConfiguration() throws Exception { + void appliesGlobalCorsConfiguration() throws Exception { Link findBooks = client.discoverUnique(LinkRelation.of("books")); @@ -119,7 +119,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests { * @see BooksXmlController */ @Test // DATAREST-573 - public void appliesCorsConfigurationOnCustomControllers() throws Exception { + void appliesCorsConfigurationOnCustomControllers() throws Exception { // Preflight request mvc.perform(options("/books/xml/1234") // @@ -143,7 +143,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests { * @see BooksPdfController */ @Test // DATAREST-573 - public void appliesCorsConfigurationOnCustomControllerMethod() throws Exception { + void appliesCorsConfigurationOnCustomControllerMethod() throws Exception { // Preflight request mvc.perform(options("/books/pdf/1234").header(HttpHeaders.ORIGIN, "http://far.far.example") @@ -156,7 +156,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-573 - public void appliesCorsConfigurationOnRepository() throws Exception { + void appliesCorsConfigurationOnRepository() throws Exception { Link authorsLink = client.discoverUnique(LinkRelation.of("authors")); @@ -170,7 +170,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-573 - public void appliesCorsConfigurationOnRepositoryToCustomControllers() throws Exception { + void appliesCorsConfigurationOnRepositoryToCustomControllers() throws Exception { // Preflight request mvc.perform(options("/authors/pdf/1234").header(HttpHeaders.ORIGIN, "http://not.so.far.example") diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java index 5d713470f..21ca19576 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java @@ -25,10 +25,9 @@ import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.validation.constraints.NotNull; -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.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; @@ -46,7 +45,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -61,9 +60,9 @@ import com.jayway.jsonpath.JsonPath; * * @author Oliver Gierke */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration -public class DataRest262Tests { +class DataRest262Tests { @Configuration @Import({ RepositoryRestMvcConfiguration.class, JpaInfrastructureConfig.class }) @@ -78,8 +77,8 @@ public class DataRest262Tests { ObjectMapper mapper; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.mapper = beanFactory // .getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class) // @@ -90,7 +89,7 @@ public class DataRest262Tests { } @Test // DATAREST-262 - public void deserializesNestedAssociation() throws Exception { + void deserializesNestedAssociation() throws Exception { Airport airport = repository.save(new Airport()); String payload = "{\"orgOrDstFlightPart\":{\"airport\":\"/api/airports/" + airport.id + "\"}}"; @@ -100,7 +99,7 @@ public class DataRest262Tests { } @Test // DATAREST-262 - public void serializesLinksToNestedAssociations() throws Exception { + void serializesLinksToNestedAssociations() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader(HttpHeaders.ACCEPT, MediaTypes.HAL_JSON_VALUE); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest363Tests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest363Tests.java index 6d0033a6b..767393a6d 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest363Tests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest363Tests.java @@ -19,10 +19,9 @@ import static org.hamcrest.Matchers.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -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.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,7 +33,7 @@ import org.springframework.hateoas.client.LinkDiscoverer; import org.springframework.hateoas.client.LinkDiscoverers; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; @@ -47,11 +46,11 @@ import org.springframework.web.context.WebApplicationContext; * @author Greg Turnquist * @author Oliver Gierke */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration( classes = { JpaRepositoryConfig.class, RepositoryRestMvcConfiguration.class, DataRest363Tests.Config.class }) -public class DataRest363Tests { +class DataRest363Tests { private static MediaType MEDIA_TYPE = MediaType.APPLICATION_JSON; @@ -78,8 +77,8 @@ public class DataRest363Tests { } } - @Before - public void setUp() { + @BeforeEach + void setUp() { MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).// defaultRequest(get("/")).build(); @@ -89,7 +88,7 @@ public class DataRest363Tests { } @Test // DATAREST-363 - public void testBasics() throws Exception { + void testBasics() throws Exception { ResultActions frodoActions = testMvcClient.follow("/people/".concat(frodo.getId().toString())); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaDefaultPageableWebTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaDefaultPageableWebTests.java index 52ccf38ea..11cbd17a7 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaDefaultPageableWebTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaDefaultPageableWebTests.java @@ -21,8 +21,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. 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.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -50,7 +50,7 @@ import org.springframework.web.bind.annotation.ResponseBody; * @author Mark Paluch */ @ContextConfiguration -public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests { +class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests { @Configuration @Import({ RepositoryRestMvcConfiguration.class, JpaRepositoryConfig.class }) @@ -87,14 +87,14 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests { @Autowired ApplicationContext context; @Override - @Before + @BeforeEach public void setUp() { loader.populateRepositories(); super.setUp(); } @Test // DATAREST-906 - public void executesSearchThatTakesAMappedSortProperty() throws Exception { + void executesSearchThatTakesAMappedSortProperty() throws Exception { Link findBySortedLink = client.discoverUnique(LinkRelation.of("books"), IanaLinkRelations.SEARCH, LinkRelation.of("find-spring-books-sorted")); @@ -114,7 +114,7 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-906 - public void shouldApplyDefaultPageable() throws Exception { + void shouldApplyDefaultPageable() throws Exception { mvc.perform(get("/books/default-pageable"))// .andExpect(jsonPath("$.content[0].sales").value(0)) // @@ -122,7 +122,7 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests { } @Test // DATAREST-906 - public void shouldOverrideDefaultPageable() throws Exception { + void shouldOverrideDefaultPageable() throws Exception { mvc.perform(get("/books/default-pageable?size=10"))// .andExpect(jsonPath("$.content[0].sales").value(0)) // diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaInfrastructureConfig.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaInfrastructureConfig.java index 4268c5fba..18dbadc2d 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaInfrastructureConfig.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaInfrastructureConfig.java @@ -31,7 +31,7 @@ import org.springframework.transaction.PlatformTransactionManager; * @author Oliver Gierke */ @Configuration -public class JpaInfrastructureConfig { +class JpaInfrastructureConfig { @Bean public DataSource dataSource() { diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java index ac18ac83e..036a12e4e 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java @@ -15,10 +15,9 @@ */ package org.springframework.data.rest.webmvc.jpa; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.data.rest.webmvc.util.TestUtils.*; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*; import static org.springframework.http.HttpHeaders.*; @@ -33,8 +32,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; -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.annotation.Autowired; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; @@ -123,7 +122,7 @@ public class JpaWebTests extends CommonWebTests { * @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#setUp() */ @Override - @Before + @BeforeEach public void setUp() { loader.populateRepositories(); super.setUp(); @@ -162,7 +161,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-99 - public void doesNotExposeCreditCardRepository() throws Exception { + void doesNotExposeCreditCardRepository() throws Exception { mvc.perform(get("/")). // andExpect(status().isOk()). // @@ -170,7 +169,7 @@ public class JpaWebTests extends CommonWebTests { } @Test - public void accessPersons() throws Exception { + void accessPersons() throws Exception { MockHttpServletResponse response = client.request("/people?page=0&size=1"); @@ -187,7 +186,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-169 - public void exposesLinkForRelatedResource() throws Exception { + void exposesLinkForRelatedResource() throws Exception { MockHttpServletResponse response = client.request("/"); Link ordersLink = client.assertHasLinkWithRel(LinkRelation.of("orders"), response); @@ -199,7 +198,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-200 - public void exposesInlinedEntities() throws Exception { + void exposesInlinedEntities() throws Exception { MockHttpServletResponse response = client.request("/"); Link ordersLink = client.assertHasLinkWithRel(LinkRelation.of("orders"), response); @@ -209,7 +208,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-199 - public void createsOrderUsingPut() throws Exception { + void createsOrderUsingPut() throws Exception { mvc.perform(// put("/orders/{id}", 4711).// @@ -218,7 +217,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-117 - public void createPersonThenVerifyIgnoredAttributesDontExist() throws Exception { + void createPersonThenVerifyIgnoredAttributesDontExist() throws Exception { Link peopleLink = client.discoverUnique(LinkRelation.of("people")); ObjectMapper mapper = new ObjectMapper(); @@ -238,7 +237,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-95 - public void createThenPatch() throws Exception { + void createThenPatch() throws Exception { Link peopleLink = client.discoverUnique(LinkRelation.of("people")); @@ -262,7 +261,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-150 - public void createThenPut() throws Exception { + void createThenPut() throws Exception { Link peopleLink = client.discoverUnique(LinkRelation.of("people")); @@ -272,29 +271,29 @@ public class JpaWebTests extends CommonWebTests { Link bilboLink = client.assertHasLinkWithRel(IanaLinkRelations.SELF, bilbo); - assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName"), equalTo("Bilbo")); - assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName"), equalTo("Baggins")); + assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName")).isEqualTo("Bilbo"); + assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName")).isEqualTo("Baggins"); MockHttpServletResponse frodo = putAndGet(bilboLink, // "{ \"firstName\" : \"Frodo\" }", // MediaType.APPLICATION_JSON); - assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName"), equalTo("Frodo")); - assertNull(JsonPath.read(frodo.getContentAsString(), "$.lastName")); + assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName")).isEqualTo("Frodo"); + assertThat(JsonPath. read(frodo.getContentAsString(), "$.lastName")).isNull(); } @Test - public void listsSiblingsWithContentCorrectly() throws Exception { + void listsSiblingsWithContentCorrectly() throws Exception { assertPersonWithNameAndSiblingLink("John"); } @Test - public void listsEmptySiblingsCorrectly() throws Exception { + void listsEmptySiblingsCorrectly() throws Exception { assertPersonWithNameAndSiblingLink("Billy Bob"); } @Test // DATAREST-219 - public void manipulatePropertyCollectionRestfullyWithMultiplePosts() throws Exception { + void manipulatePropertyCollectionRestfullyWithMultiplePosts() throws Exception { List links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins"), // @@ -311,7 +310,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-219 - public void manipulatePropertyCollectionRestfullyWithSinglePost() throws Exception { + void manipulatePropertyCollectionRestfullyWithSinglePost() throws Exception { List links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins"), // @@ -326,7 +325,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-219 - public void manipulatePropertyCollectionRestfullyWithMultiplePuts() throws Exception { + void manipulatePropertyCollectionRestfullyWithMultiplePuts() throws Exception { List links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins"), // @@ -345,7 +344,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-219 - public void manipulatePropertyCollectionRestfullyWithSinglePut() throws Exception { + void manipulatePropertyCollectionRestfullyWithSinglePut() throws Exception { List links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins"), // @@ -369,7 +368,7 @@ public class JpaWebTests extends CommonWebTests { * checks for its first name. Than it sets Pippin Baggins as creator of the Order. Check for first name is done again. */ @Test // DATAREST-1356 - public void associateCreatorToOrderWithSinglePut() throws Exception { + void associateCreatorToOrderWithSinglePut() throws Exception { Link firstCreatorLink = preparePersonResource(new Person("Frodo", "Baggins")); Link secondCreatorLink = preparePersonResource(new Person("Pippin", "Baggins")); @@ -387,7 +386,7 @@ public class JpaWebTests extends CommonWebTests { * will contain "send only 1 link" substring. */ @Test // DATAREST-1356 - public void associateTwoCreatorsToOrderWithSinglePut() throws Exception { + void associateTwoCreatorsToOrderWithSinglePut() throws Exception { Link firstCreatorLink = preparePersonResource(new Person("Frodo", "Baggins")); Link secondCreatorLink = preparePersonResource(new Person("Pippin", "Baggins")); @@ -399,7 +398,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-219 - public void manipulatePropertyCollectionRestfullyWithDelete() throws Exception { + void manipulatePropertyCollectionRestfullyWithDelete() throws Exception { List links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins"), // @@ -419,7 +418,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-50 - public void propertiesCanHaveNulls() throws Exception { + void propertiesCanHaveNulls() throws Exception { Link peopleLink = client.discoverUnique(LinkRelation.of("people")); @@ -436,7 +435,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-238 - public void putShouldWorkDespiteExistingLinks() throws Exception { + void putShouldWorkDespiteExistingLinks() throws Exception { Link peopleLink = client.discoverUnique(LinkRelation.of("people")); @@ -458,7 +457,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-217 - public void doesNotAllowGetToCollectionResourceIfFindAllIsNotExported() throws Exception { + void doesNotAllowGetToCollectionResourceIfFindAllIsNotExported() throws Exception { Link link = client.discoverUnique(LinkRelation.of("addresses")); @@ -467,7 +466,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-217 - public void doesNotAllowPostToCollectionResourceIfSaveIsNotExported() throws Exception { + void doesNotAllowPostToCollectionResourceIfSaveIsNotExported() throws Exception { Link link = client.discoverUnique(LinkRelation.of("addresses")); @@ -481,7 +480,7 @@ public class JpaWebTests extends CommonWebTests { * @see OrderSummary */ @Test // DATAREST-221 - public void returnsProjectionIfRequested() throws Exception { + void returnsProjectionIfRequested() throws Exception { Link orders = client.discoverUnique(LinkRelation.of("orders")); @@ -500,12 +499,12 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-261 - public void relProviderDetectsCustomizedMapping() { + void relProviderDetectsCustomizedMapping() { assertThat(relProvider.getCollectionResourceRelFor(Person.class)).isEqualTo(LinkRelation.of("people")); } @Test // DATAREST-311 - public void onlyLinksShouldAppearWhenExecuteSearchCompact() throws Exception { + void onlyLinksShouldAppearWhenExecuteSearchCompact() throws Exception { Link peopleLink = client.discoverUnique(LinkRelation.of("people")); Person daenerys = new Person("Daenerys", "Targaryen"); @@ -531,7 +530,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-317 - public void rendersExcerptProjectionsCorrectly() throws Exception { + void rendersExcerptProjectionsCorrectly() throws Exception { Link authorsLink = client.discoverUnique("authors"); @@ -554,7 +553,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-353 - public void returns404WhenTryingToDeleteANonExistingResource() throws Exception { + void returns404WhenTryingToDeleteANonExistingResource() throws Exception { Link receiptsLink = client.discoverUnique("receipts"); @@ -563,7 +562,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-384 - public void exectuesSearchThatTakesASort() throws Exception { + void exectuesSearchThatTakesASort() throws Exception { Link booksLink = client.discoverUnique("books"); Link searchLink = client.discoverUnique(booksLink, "search"); @@ -586,7 +585,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-160 - public void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception { + void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception { Link receiptLink = client.discoverUnique("receipts"); @@ -613,7 +612,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-423 - public void invokesCustomControllerAndBindsDomainObjectCorrectly() throws Exception { + void invokesCustomControllerAndBindsDomainObjectCorrectly() throws Exception { MockHttpServletResponse authorsResponse = client.request(client.discoverUnique("authors")); @@ -624,7 +623,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-523 - public void augmentsCollectionAssociationUsingPost() throws Exception { + void augmentsCollectionAssociationUsingPost() throws Exception { List links = preparePersonResources(new Person("Frodo", "Baggins"), // new Person("Bilbo", "Baggins")); @@ -645,7 +644,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-658 - public void returnsLinkHeadersForHeadRequestToItemResource() throws Exception { + void returnsLinkHeadersForHeadRequestToItemResource() throws Exception { MockHttpServletResponse response = client.request(client.discoverUnique(LinkRelation.of("people"))); String personHref = JsonPath.read(response.getContentAsString(), "$._embedded.people[0]._links.self.href"); @@ -660,7 +659,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-883 - public void exectuesSearchThatTakesAMappedSortProperty() throws Exception { + void exectuesSearchThatTakesAMappedSortProperty() throws Exception { Link findBySortedLink = client.discoverUnique("books", "search", "find-by-sorted"); @@ -681,7 +680,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-883 - public void exectuesCustomQuerySearchThatTakesAMappedSortProperty() throws Exception { + void exectuesCustomQuerySearchThatTakesAMappedSortProperty() throws Exception { Link findByLink = client.discoverUnique("books", "search", "find-spring-books-sorted"); @@ -701,14 +700,14 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-910 - public void callUnmappedCustomRepositoryController() throws Exception { + void callUnmappedCustomRepositoryController() throws Exception { mvc.perform(post("/orders/search/sort")).andExpect(status().isOk()); mvc.perform(post("/orders/search/sort?sort=type&page=1&size=10")).andExpect(status().isOk()); } @Test // DATAREST-976 - public void appliesSortByEmbeddedAssociation() throws Exception { + void appliesSortByEmbeddedAssociation() throws Exception { Link booksLink = client.discoverUnique("books"); Link searchLink = client.discoverUnique(booksLink, "search"); @@ -731,7 +730,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-1213 - public void createThenPatchWithProjection() throws Exception { + void createThenPatchWithProjection() throws Exception { Link link = createCategory(); String payload = "{ \"name\" : \"patched\" }"; @@ -744,7 +743,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // DATAREST-1213 - public void createThenPutWithProjection() throws Exception { + void createThenPutWithProjection() throws Exception { Link link = createCategory(); String payload = "{ \"name\" : \"put\" }"; @@ -757,7 +756,7 @@ public class JpaWebTests extends CommonWebTests { } @Test // #1991 - public void answersToHalFormsRequests() throws Exception { + void answersToHalFormsRequests() throws Exception { mvc.perform(get("/") .accept(MediaTypes.HAL_FORMS_JSON)) diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/LocalConfigCorsIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/LocalConfigCorsIntegrationTests.java index 74ce9023a..222632316 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/LocalConfigCorsIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/LocalConfigCorsIntegrationTests.java @@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Bean; import org.springframework.data.rest.tests.AbstractWebIntegrationTests; import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping; @@ -37,7 +37,7 @@ import org.springframework.test.context.ContextConfiguration; * @soundtrack RFLKTD - Liquid Crystals */ @ContextConfiguration -public class LocalConfigCorsIntegrationTests extends AbstractWebIntegrationTests { +class LocalConfigCorsIntegrationTests extends AbstractWebIntegrationTests { static class CorsConfig extends JpaRepositoryConfig { @@ -51,7 +51,7 @@ public class LocalConfigCorsIntegrationTests extends AbstractWebIntegrationTests * @see ItemRepository */ @Test // DATAREST-1397 - public void appliesRepositoryCorsConfiguration() throws Exception { + void appliesRepositoryCorsConfiguration() throws Exception { Link findItems = client.discoverUnique(LinkRelation.of("items")); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java index 47688860f..703a60164 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java @@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.*; import static org.hamcrest.Matchers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -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.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -49,7 +49,7 @@ import org.springframework.web.context.WebApplicationContext; */ @WebAppConfiguration @ContextConfiguration(classes = { JpaRepositoryConfig.class, ProfileIntegrationTests.Config.class }) -public class ProfileIntegrationTests extends AbstractControllerIntegrationTests { +class ProfileIntegrationTests extends AbstractControllerIntegrationTests { @Autowired WebApplicationContext context; @Autowired LinkDiscoverers discoverers; @@ -67,15 +67,15 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests TestMvcClient client; - @Before - public void setUp() { + @BeforeEach + void setUp() { MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build(); this.client = new TestMvcClient(mvc, this.discoverers); } @Test // DATAREST-230, DATAREST-638 - public void exposesProfileLink() throws Exception { + void exposesProfileLink() throws Exception { client.follow(ROOT_URI)// .andExpect(status().is2xxSuccessful())// @@ -83,7 +83,7 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests } @Test // DATAREST-230, DATAREST-638 - public void profileRootLinkContainsMetadataForEachRepo() throws Exception { + void profileRootLinkContainsMetadataForEachRepo() throws Exception { Link profileLink = client.discoverUnique(Link.of(ROOT_URI), ProfileResourceProcessor.PROFILE_REL); @@ -99,7 +99,7 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests } @Test // DATAREST-638 - public void profileLinkOnCollectionResourceLeadsToRepositorySpecificMetadata() throws Exception { + void profileLinkOnCollectionResourceLeadsToRepositorySpecificMetadata() throws Exception { Link peopleLink = client.discoverUnique(Link.of(ROOT_URI), "people"); Link profileLink = client.discoverUnique(peopleLink, ProfileResourceProcessor.PROFILE_REL); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClass.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClass.java index 7f1e8da00..2b9f53f70 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClass.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClass.java @@ -29,7 +29,7 @@ import javax.persistence.Id; * @author Oliver Gierke */ @Entity -public class SimulatedGroovyDomainClass implements GroovyObject { +class SimulatedGroovyDomainClass implements GroovyObject { private @Id @GeneratedValue Long id; private String name; @@ -38,7 +38,7 @@ public class SimulatedGroovyDomainClass implements GroovyObject { return id; } - public void setId(Long id) { + void setId(Long id) { this.id = id; } @@ -46,7 +46,7 @@ public class SimulatedGroovyDomainClass implements GroovyObject { return name; } - public void setName(String name) { + void setName(String name) { this.name = name; } diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClassRepository.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClassRepository.java index 42f5b7da5..2c62bc4a1 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClassRepository.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClassRepository.java @@ -16,7 +16,6 @@ package org.springframework.data.rest.webmvc.jpa.groovy; import org.springframework.data.repository.CrudRepository; -import org.springframework.data.rest.webmvc.jpa.groovy.SimulatedGroovyDomainClass; /** * Simulates a repository built on a Groovy domain object. diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/Jackson2DatatypeHelperIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/Jackson2DatatypeHelperIntegrationTests.java index 5ee1ca99b..b32d9a689 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/Jackson2DatatypeHelperIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/Jackson2DatatypeHelperIntegrationTests.java @@ -19,9 +19,9 @@ import static org.assertj.core.api.Assertions.*; import javax.persistence.EntityManager; -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.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.mapping.PersistentEntity; @@ -36,7 +36,7 @@ import org.springframework.data.rest.webmvc.jpa.Person; import org.springframework.data.rest.webmvc.jpa.PersonRepository; import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; import com.fasterxml.jackson.databind.ObjectMapper; @@ -46,10 +46,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; * * @author Oliver Gierke */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { JpaRepositoryConfig.class, RepositoryRestMvcConfiguration.class }) @Transactional -public class Jackson2DatatypeHelperIntegrationTests { +class Jackson2DatatypeHelperIntegrationTests { @Autowired PersistentEntities entities; @Autowired ApplicationContext context; @@ -62,8 +62,8 @@ public class Jackson2DatatypeHelperIntegrationTests { Order order; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.order = orders.save(new Order(people.save(new Person("Dave", "Matthews")))); this.objectMapper = context.getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class) @@ -75,7 +75,7 @@ public class Jackson2DatatypeHelperIntegrationTests { } @Test // DATAREST-500 - public void configuresHibernate4ModuleToLoadLazyLoadingProxies() throws Exception { + void configuresHibernate4ModuleToLoadLazyLoadingProxies() throws Exception { PersistentEntity entity = entities.getRequiredPersistentEntity(Order.class); PersistentProperty property = entity.getRequiredPersistentProperty("creator"); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java index 699982630..5fb18aafc 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java @@ -22,9 +22,9 @@ import java.io.StringWriter; 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.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -48,7 +48,7 @@ import org.springframework.hateoas.server.core.EmbeddedWrapper; import org.springframework.hateoas.server.core.EmbeddedWrappers; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletWebRequest; @@ -65,10 +65,10 @@ import com.jayway.jsonpath.JsonPath; * @author Oliver Gierke * @author Alex Leigh */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { JpaRepositoryConfig.class, PersistentEntitySerializationTests.TestConfig.class }) @Transactional -public class PersistentEntitySerializationTests { +class PersistentEntitySerializationTests { private static final String PERSON_JSON_IN = "{\"firstName\": \"John\",\"lastName\": \"Doe\"}"; @@ -94,8 +94,8 @@ public class PersistentEntitySerializationTests { LinkDiscoverer discoverer; ProjectionFactory projectionFactory; - @Before - public void setUp() { + @BeforeEach + void setUp() { RequestContextHolder.setRequestAttributes(new ServletWebRequest(new MockHttpServletRequest())); @@ -104,7 +104,7 @@ public class PersistentEntitySerializationTests { } @Test - public void deserializesPersonEntity() throws IOException { + void deserializesPersonEntity() throws IOException { Person p = mapper.readValue(PERSON_JSON_IN, Person.class); @@ -114,7 +114,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-238 - public void deserializePersonWithLinks() throws IOException { + void deserializePersonWithLinks() throws IOException { String bilbo = "{\n" + " \"_links\" : {\n" + " \"self\" : {\n" + " \"href\" : \"http://localhost/people/4\"\n" + " },\n" + " \"siblings\" : {\n" @@ -129,7 +129,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-238 - public void serializesPersonEntity() throws IOException, InterruptedException { + void serializesPersonEntity() throws IOException, InterruptedException { PersistentEntity persistentEntity = repositories.getPersistentEntity(Person.class); Person person = people.save(new Person("John", "Doe")); @@ -154,7 +154,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-248 - public void deserializesPersonWithLinkToOtherPersonCorrectly() throws Exception { + void deserializesPersonWithLinkToOtherPersonCorrectly() throws Exception { Person father = people.save(new Person("John", "Doe")); @@ -165,7 +165,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-248 - public void deserializesPersonWithLinkToOtherPersonsCorrectly() throws Exception { + void deserializesPersonWithLinkToOtherPersonsCorrectly() throws Exception { Person firstSibling = people.save(new Person("John", "Doe")); Person secondSibling = people.save(new Person("Dave", "Doe")); @@ -178,7 +178,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-248 - public void deserializesEmbeddedAssociationsCorrectly() throws Exception { + void deserializesEmbeddedAssociationsCorrectly() throws Exception { String content = TestUtils.readFileFromClasspath("order.json"); @@ -187,7 +187,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-250 - public void serializesReferencesWithinPagedResourceCorrectly() throws Exception { + void serializesReferencesWithinPagedResourceCorrectly() throws Exception { Person creator = new Person("Dave", "Matthews"); @@ -209,7 +209,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-521 - public void serializesLinksForExcerpts() throws Exception { + void serializesLinksForExcerpts() throws Exception { Person dave = new Person("Dave", "Matthews"); dave.setId(1L); @@ -232,7 +232,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-521 - public void rendersAdditionalLinksRegisteredWithResource() throws Exception { + void rendersAdditionalLinksRegisteredWithResource() throws Exception { Person dave = new Person("Dave", "Matthews"); @@ -248,7 +248,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-697 - public void rendersProjectionWithinSimpleResourceCorrectly() throws Exception { + void rendersProjectionWithinSimpleResourceCorrectly() throws Exception { Person person = new Person("Dave", "Matthews"); person.setId(1L); @@ -262,7 +262,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-880 - public void unwrapsNestedTypeCorrectly() throws Exception { + void unwrapsNestedTypeCorrectly() throws Exception { CreditCard creditCard = new CreditCard(new CreditCard.CCN("1234123412341234")); @@ -270,7 +270,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-872 - public void serializesInheritance() throws Exception { + void serializesInheritance() throws Exception { Suite suite = new Suite(); suite.setSuiteCode("Suite 42"); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/RepositoryTestsConfig.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/RepositoryTestsConfig.java index 06f71630f..a8feb817e 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/RepositoryTestsConfig.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/RepositoryTestsConfig.java @@ -72,7 +72,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; */ @Configuration @SuppressWarnings("deprecation") -public class RepositoryTestsConfig { +class RepositoryTestsConfig { @Autowired ApplicationContext appCtx; @Autowired(required = false) List> mappingContexts = Collections.emptyList(); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/BackendIdConverterHandlerMethodArgumentResolverIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/BackendIdConverterHandlerMethodArgumentResolverIntegrationTests.java index 6e5e33f73..3b63d445d 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/BackendIdConverterHandlerMethodArgumentResolverIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/BackendIdConverterHandlerMethodArgumentResolverIntegrationTests.java @@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*; import java.io.Serializable; import java.lang.reflect.Method; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.MethodParameter; import org.springframework.data.rest.tests.AbstractControllerIntegrationTests; @@ -38,13 +38,13 @@ import org.springframework.web.context.request.ServletWebRequest; * @author Oliver Gierke */ @ContextConfiguration(classes = JpaRepositoryConfig.class) -public class BackendIdConverterHandlerMethodArgumentResolverIntegrationTests +class BackendIdConverterHandlerMethodArgumentResolverIntegrationTests extends AbstractControllerIntegrationTests { @Autowired BackendIdHandlerMethodArgumentResolver resolver; @Test // DATAREST-155 - public void translatesUriToBackendId() throws Exception { + void translatesUriToBackendId() throws Exception { Method method = ReflectionUtils.findMethod(SampleController.class, "resolveId", Serializable.class); MethodParameter parameter = new MethodParameter(method, 0); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/ExceptionHandlingCustomizationIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/ExceptionHandlingCustomizationIntegrationTests.java index d5cd226f8..673604b2a 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/ExceptionHandlingCustomizationIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/ExceptionHandlingCustomizationIntegrationTests.java @@ -18,7 +18,7 @@ package org.springframework.data.rest.webmvc.support; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.Ordered; @@ -41,7 +41,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; * @author Oliver Gierke */ @ContextConfiguration -public class ExceptionHandlingCustomizationIntegrationTests extends AbstractWebIntegrationTests { +class ExceptionHandlingCustomizationIntegrationTests extends AbstractWebIntegrationTests { @Configuration @Import(JpaRepositoryConfig.class) @@ -63,7 +63,7 @@ public class ExceptionHandlingCustomizationIntegrationTests extends AbstractWebI } @Test - public void httpRequestMethodNotSupportedExceptionShouldNowReturnHttpStatus500Over405() throws Exception { + void httpRequestMethodNotSupportedExceptionShouldNowReturnHttpStatus500Over405() throws Exception { Link link = client.discoverUnique("addresses"); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java index e8fcfbe87..6d6d469a7 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java @@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc.support; 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.domain.PageRequest; import org.springframework.data.domain.Sort; @@ -40,13 +40,13 @@ import org.springframework.web.util.UriComponentsBuilder; * @author Oliver Gierke */ @ContextConfiguration(classes = JpaRepositoryConfig.class) -public class RepositoryEntityLinksIntegrationTests extends AbstractControllerIntegrationTests { +class RepositoryEntityLinksIntegrationTests extends AbstractControllerIntegrationTests { @Autowired RepositoryRestConfiguration configuration; @Autowired RepositoryEntityLinks entityLinks; @Test - public void returnsLinkToSingleResource() { + void returnsLinkToSingleResource() { Link link = entityLinks.linkToItemResource(Person.class, 1); @@ -55,7 +55,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt } @Test - public void returnsTemplatedLinkForPagingResource() { + void returnsTemplatedLinkForPagingResource() { Link link = entityLinks.linkToCollectionResource(Person.class); @@ -65,7 +65,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt } @Test // DATAREST-221 - public void returnsLinkWithProjectionTemplateVariableIfProjectionIsDefined() { + void returnsLinkWithProjectionTemplateVariableIfProjectionIsDefined() { Link link = entityLinks.linkToItemResource(Order.class, 1); @@ -74,14 +74,14 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt } @Test // DATAREST-155 - public void usesCustomGeneratedBackendId() { + void usesCustomGeneratedBackendId() { Link link = entityLinks.linkToItemResource(Book.class, 7L); assertThat(link.expand().getHref()).endsWith("/7-7-7-7-7-7-7"); } @Test // DATAREST-317 - public void adaptsToExistingPageable() { + void adaptsToExistingPageable() { Link link = entityLinks.linkToPagedResource(Person.class, PageRequest.of(0, 10)); @@ -91,7 +91,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt } @Test // DATAREST-467 - public void returnsLinksToSearchResources() { + void returnsLinksToSearchResources() { Links links = entityLinks.linksToSearchResources(Person.class); @@ -103,7 +103,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt } @Test // DATAREST-467 - public void returnsLinkToSearchResource() { + void returnsLinkToSearchResource() { Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("firstname")); @@ -113,7 +113,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt } @Test // DATAREST-467, DATAREST-519 - public void prepopulatesPaginationInformationForSearchResourceLink() { + void prepopulatesPaginationInformationForSearchResourceLink() { Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("firstname"), PageRequest.of(0, 10)); @@ -127,7 +127,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt } @Test // DATAREST-467 - public void returnsTemplatedLinkForSortedSearchResource() { + void returnsTemplatedLinkForSortedSearchResource() { Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("lastname")); @@ -136,7 +136,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt } @Test // DATAREST-467, DATAREST-519 - public void prepopulatesSortInformationForSearchResourceLink() { + void prepopulatesSortInformationForSearchResourceLink() { Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("lastname"), Sort.by("firstname")); @@ -150,7 +150,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt } @Test // DATAREST-668, DATAREST-519, DATAREST-467 - public void addsProjectVariableToSearchResourceIfAvailable() { + void addsProjectVariableToSearchResourceIfAvailable() { for (Link link : entityLinks.linksToSearchResources(Book.class)) { assertThat(link.getVariableNames()).contains("projection"); @@ -158,7 +158,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt } @Test // #1980 - public void considersIdConverterInLinkForItemResource() { + void considersIdConverterInLinkForItemResource() { Link link = entityLinks.linkForItemResource(Book.class, 7L).withSelfRel(); diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/tests/mongodb/MongoWebTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/tests/mongodb/MongoWebTests.java index 767c68ae7..6c00ac700 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/tests/mongodb/MongoWebTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/tests/mongodb/MongoWebTests.java @@ -30,9 +30,9 @@ import java.util.Map; import java.util.stream.Stream; import org.assertj.core.api.Condition; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.rest.tests.CommonWebTests; import org.springframework.data.rest.tests.TestMatchers; @@ -62,7 +62,7 @@ import com.jayway.jsonpath.JsonPath; * @author Greg Turnquist */ @ContextConfiguration(classes = MongoDbRepositoryConfig.class) -public class MongoWebTests extends CommonWebTests { +class MongoWebTests extends CommonWebTests { private static final MediaType TEXT_URI_LIST = MediaType.parseMediaType("text/uri-list"); @@ -72,8 +72,8 @@ public class MongoWebTests extends CommonWebTests { ObjectMapper mapper = new ObjectMapper(); - @Before - public void populateProfiles() { + @BeforeEach + void populateProfiles() { mapper.setSerializationInclusion(Include.NON_NULL); @@ -122,8 +122,8 @@ public class MongoWebTests extends CommonWebTests { } - @After - public void cleanUp() { + @AfterEach + void cleanUp() { repository.deleteAll(); userRepository.deleteAll(); } @@ -138,7 +138,7 @@ public class MongoWebTests extends CommonWebTests { } @Test - public void foo() throws Exception { + void foo() throws Exception { Link profileLink = client.discoverUnique("profiles"); client.follow(profileLink).// @@ -146,7 +146,7 @@ public class MongoWebTests extends CommonWebTests { } @Test - public void rendersEmbeddedDocuments() throws Exception { + void rendersEmbeddedDocuments() throws Exception { Link usersLink = client.discoverUnique("users"); Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink)); @@ -155,7 +155,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-247 - public void executeQueryMethodWithPrimitiveReturnType() throws Exception { + void executeQueryMethodWithPrimitiveReturnType() throws Exception { Link profiles = client.discoverUnique("profiles"); Link profileSearches = client.discoverUnique(profiles, "search"); @@ -169,7 +169,7 @@ public class MongoWebTests extends CommonWebTests { } @Test - public void testname() throws Exception { + void testname() throws Exception { Link usersLink = client.discoverUnique("users"); Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink)); @@ -183,7 +183,7 @@ public class MongoWebTests extends CommonWebTests { } @Test - public void testname2() throws Exception { + void testname2() throws Exception { Link usersLink = client.discoverUnique("users"); Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink)); @@ -199,7 +199,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-160 - public void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception { + void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception { Link receiptLink = client.discoverUnique("receipts"); @@ -226,7 +226,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-471 - public void auditableResourceHasLastModifiedHeaderSet() throws Exception { + void auditableResourceHasLastModifiedHeaderSet() throws Exception { Profile profile = repository.findAll().iterator().next(); @@ -237,7 +237,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-482 - public void putDoesNotRemoveAssociations() throws Exception { + void putDoesNotRemoveAssociations() throws Exception { Link usersLink = client.discoverUnique("users"); Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink)); @@ -260,7 +260,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-482 - public void emptiesAssociationForEmptyUriList() throws Exception { + void emptiesAssociationForEmptyUriList() throws Exception { Link usersLink = client.discoverUnique("users"); Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink)); @@ -274,7 +274,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-491 - public void updatesMapPropertyCorrectly() throws Exception { + void updatesMapPropertyCorrectly() throws Exception { Link profilesLink = client.discoverUnique("profiles"); Link profileLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(profilesLink)); @@ -288,7 +288,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-506 - public void supportsConditionalGetsOnItemResource() throws Exception { + void supportsConditionalGetsOnItemResource() throws Exception { Receipt receipt = new Receipt(); receipt.amount = new BigDecimal(50); @@ -313,7 +313,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-511 - public void invokesQueryResourceReturningAnOptional() throws Exception { + void invokesQueryResourceReturningAnOptional() throws Exception { Profile profile = repository.findAll().iterator().next(); @@ -324,7 +324,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-517 - public void returnsNotFoundIfQueryExecutionDoesNotReturnResult() throws Exception { + void returnsNotFoundIfQueryExecutionDoesNotReturnResult() throws Exception { Link link = client.discoverUnique("profiles", "search", "findProfileById"); @@ -333,7 +333,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-712 - public void invokesQueryMethodTakingAReferenceCorrectly() throws Exception { + void invokesQueryMethodTakingAReferenceCorrectly() throws Exception { Link link = client.discoverUnique("users", "search", "findByColleaguesContains"); @@ -346,7 +346,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-835 - public void exposesETagHeaderForSearchResourceYieldingItemResource() throws Exception { + void exposesETagHeaderForSearchResourceYieldingItemResource() throws Exception { Link link = client.discoverUnique("profiles", "search", "findProfileById"); @@ -358,7 +358,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-835 - public void doesNotAddETagHeaderForCollectionQueryResource() throws Exception { + void doesNotAddETagHeaderForCollectionQueryResource() throws Exception { Link link = client.discoverUnique("profiles", "search", "findByType"); @@ -370,7 +370,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-1458 - public void accessCollectionAssociationResourceAsUriList() throws Exception { + void accessCollectionAssociationResourceAsUriList() throws Exception { Link usersLink = client.discoverUnique("users"); Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink)); @@ -383,7 +383,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-1458 - public void accessAssociationResourceAsUriList() throws Exception { + void accessAssociationResourceAsUriList() throws Exception { Link usersLink = client.discoverUnique("users"); Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink)); @@ -395,7 +395,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-1458 - public void accessMapCollectionAssociationResourceAsUriList() throws Exception { + void accessMapCollectionAssociationResourceAsUriList() throws Exception { Link usersLink = client.discoverUnique("users"); Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink)); @@ -409,7 +409,7 @@ public class MongoWebTests extends CommonWebTests { } @Test // DATAREST-762 - public void paginatedLinksContainQuerydslPropertyReferences() throws Exception { + void paginatedLinksContainQuerydslPropertyReferences() throws Exception { Map parameters = new HashMap<>(); parameters.put("page", "0"); diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceAssemblerIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceAssemblerIntegrationTests.java index 16b77a067..d56b9e8ac 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceAssemblerIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceAssemblerIntegrationTests.java @@ -22,7 +22,7 @@ import static org.mockito.Mockito.*; import java.math.BigInteger; import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.internal.stubbing.answers.ReturnsArgumentAt; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.convert.ConversionService; @@ -46,14 +46,14 @@ import org.springframework.test.context.ContextConfiguration; * @author Oliver Gierke */ @ContextConfiguration(classes = { TestConfiguration.class, MongoDbRepositoryConfig.class }) -public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractControllerIntegrationTests { +class PersistentEntityResourceAssemblerIntegrationTests extends AbstractControllerIntegrationTests { @Autowired PersistentEntities entities; @Autowired EntityLinks entityLinks; @Autowired Associations associations; @Test // DATAREST-609 - public void addsSelfAndSingleResourceLinkToResourceByDefault() throws Exception { + void addsSelfAndSingleResourceLinkToResourceByDefault() throws Exception { Projector projector = mock(Projector.class); diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingIntegrationTests.java index f16d804c5..7429ca1b4 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingIntegrationTests.java @@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc; 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.rest.tests.AbstractControllerIntegrationTests; import org.springframework.data.rest.tests.mongodb.MongoDbRepositoryConfig; @@ -34,12 +34,12 @@ import org.springframework.web.servlet.HandlerMapping; * @soundtrack Elephants Crossing - Echo (Irrelephant) */ @ContextConfiguration(classes = MongoDbRepositoryConfig.class) -public class RepositoryRestHandlerMappingIntegrationTests extends AbstractControllerIntegrationTests { +class RepositoryRestHandlerMappingIntegrationTests extends AbstractControllerIntegrationTests { @Autowired HandlerMapping mapping; @Test // DATAREST-617 - public void usesMethodsWithoutProducesClauseForGeneralJsonRequests() throws Exception { + void usesMethodsWithoutProducesClauseForGeneralJsonRequests() throws Exception { MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "/users"); mockRequest.addHeader("Accept", "application/*+json"); diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/AbstractRepositoryRestMvcConfigurationIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/AbstractRepositoryRestMvcConfigurationIntegrationTests.java index f1e108a64..be7c63f74 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/AbstractRepositoryRestMvcConfigurationIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/AbstractRepositoryRestMvcConfigurationIntegrationTests.java @@ -15,10 +15,10 @@ */ package org.springframework.data.rest.webmvc.config; -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.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -29,15 +29,15 @@ import org.springframework.web.context.WebApplicationContext; * * @author Oliver Gierke */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration public abstract class AbstractRepositoryRestMvcConfigurationIntegrationTests { @Autowired WebApplicationContext context; protected MockMvc mvc; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.mvc = MockMvcBuilders.webAppContextSetup(context).build(); } } diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/JsonPatchHandlerUnitTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/JsonPatchHandlerUnitTests.java index 12b3ddc8b..ce3c80311 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/JsonPatchHandlerUnitTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/JsonPatchHandlerUnitTests.java @@ -22,13 +22,11 @@ import static org.springframework.data.rest.tests.mongodb.TestUtils.*; import java.util.ArrayList; import java.util.Arrays; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -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.mapping.context.PersistentEntities; import org.springframework.data.mongodb.core.mapping.MongoMappingContext; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; @@ -47,17 +45,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; * * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class JsonPatchHandlerUnitTests { +@ExtendWith(MockitoExtension.class) +class JsonPatchHandlerUnitTests { JsonPatchHandler handler; User user; @Mock ResourceMappings mappings; - public @Rule ExpectedException exception = ExpectedException.none(); - @Before - public void setUp() { + @BeforeEach + void setUp() { MongoMappingContext context = new MongoMappingContext(); context.getPersistentEntity(User.class); @@ -79,7 +76,7 @@ public class JsonPatchHandlerUnitTests { } @Test // DATAREST-348 - public void appliesRemoveOperationCorrectly() throws Exception { + void appliesRemoveOperationCorrectly() throws Exception { String input = "[{ \"op\": \"replace\", \"path\": \"/address/zipCode\", \"value\": \"ZIP\" }," + "{ \"op\": \"remove\", \"path\": \"/lastname\" }]"; @@ -91,7 +88,7 @@ public class JsonPatchHandlerUnitTests { } @Test // DATAREST-348 - public void appliesMergePatchCorrectly() throws Exception { + void appliesMergePatchCorrectly() throws Exception { String input = "{ \"address\" : { \"zipCode\" : \"ZIP\"}, \"lastname\" : null }"; @@ -105,7 +102,7 @@ public class JsonPatchHandlerUnitTests { * DATAREST-537 */ @Test - public void removesArrayItemCorrectly() throws Exception { + void removesArrayItemCorrectly() throws Exception { User thomas = new User(); thomas.firstname = "Thomas"; @@ -124,11 +121,10 @@ public class JsonPatchHandlerUnitTests { } @Test // DATAREST-609 - public void hintsToMediaTypeIfBodyCantBeRead() throws Exception { + void hintsToMediaTypeIfBodyCantBeRead() throws Exception { - exception.expect(HttpMessageNotReadableException.class); - exception.expectMessage(RestMediaTypes.JSON_PATCH_JSON.toString()); - - handler.applyPatch(asStream("{ \"foo\" : \"bar\" }"), new User()); + assertThatExceptionOfType(HttpMessageNotReadableException.class) + .isThrownBy(() -> handler.applyPatch(asStream("{ \"foo\" : \"bar\" }"), new User())) + .withMessageContaining(RestMediaTypes.JSON_PATCH_JSON.toString()); } } diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUnitTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUnitTests.java index 612cbe8a9..bc0e17e0e 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUnitTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/config/QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUnitTests.java @@ -23,12 +23,12 @@ import java.util.Collections; import java.util.Map; 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.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.MethodParameter; import org.springframework.data.querydsl.QuerydslPredicateExecutor; import org.springframework.data.querydsl.QuerydslRepositoryInvokerAdapter; @@ -54,23 +54,23 @@ import com.querydsl.core.types.Predicate; * * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUnitTests { +@ExtendWith(MockitoExtension.class) +class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUnitTests { static final Map NO_PARAMETERS = Collections.emptyMap(); @Mock Repositories repositories; @Mock RepositoryInvokerFactory invokerFactory; @Mock ResourceMetadataHandlerMethodArgumentResolver resourceMetadataResolver; - @Mock QuerydslPredicateBuilder builder; + @Mock(lenient = true) QuerydslPredicateBuilder builder; @Mock RepositoryInvoker invoker; @Mock MethodParameter parameter; QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver resolver; - @Before - public void setUp() { + @BeforeEach + void setUp() { QuerydslBindingsFactory factory = new QuerydslBindingsFactory(SimpleEntityPathResolver.INSTANCE); ReflectionTestUtils.setField(factory, "repositories", Optional.of(repositories)); @@ -83,7 +83,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn } @Test // DATAREST-616 - public void returnsInvokerIfRepositoryIsNotQuerydslAware() { + void returnsInvokerIfRepositoryIsNotQuerydslAware() { ReceiptRepository repository = mock(ReceiptRepository.class); when(repositories.getRepositoryFor(Receipt.class)).thenReturn(Optional.of(repository)); @@ -94,7 +94,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn } @Test // DATAREST-616 - public void wrapsInvokerInQuerydslAdapter() { + void wrapsInvokerInQuerydslAdapter() { Object repository = mock(QuerydslUserRepository.class); when(repositories.getRepositoryFor(User.class)).thenReturn(Optional.of(repository)); @@ -105,7 +105,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn } @Test // DATAREST-616 - public void invokesCustomizationOnRepositoryIfItImplementsCustomizer() { + void invokesCustomizationOnRepositoryIfItImplementsCustomizer() { QuerydslCustomizingUserRepository repository = mock(QuerydslCustomizingUserRepository.class); when(repositories.getRepositoryFor(User.class)).thenReturn(Optional.of(repository)); diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java index 5f285a0af..06f17693e 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java @@ -20,9 +20,9 @@ import static org.assertj.core.api.Assertions.*; import java.util.Arrays; import java.util.HashMap; -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.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -45,7 +45,7 @@ import org.springframework.hateoas.mediatype.MessageResolver; import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletWebRequest; @@ -60,10 +60,10 @@ import com.jayway.jsonpath.ReadContext; * @author Greg Turnquist * @author Oliver Gierke */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { MongoDbRepositoryConfig.class, RepositoryTestsConfig.class, PersistentEntitySerializationTests.TestConfig.class }) -public class PersistentEntitySerializationTests { +class PersistentEntitySerializationTests { @Autowired ObjectMapper mapper; @Autowired Repositories repositories; @@ -86,8 +86,8 @@ public class PersistentEntitySerializationTests { LinkDiscoverer linkDiscoverer; ProjectionFactory projectionFactory; - @Before - public void setUp() { + @BeforeEach + void setUp() { RequestContextHolder.setRequestAttributes(new ServletWebRequest(new MockHttpServletRequest())); @@ -96,7 +96,7 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-250 - public void serializesEmbeddedReferencesCorrectly() throws Exception { + void serializesEmbeddedReferencesCorrectly() throws Exception { User user = new User(); user.address = new Address(); @@ -116,12 +116,12 @@ public class PersistentEntitySerializationTests { } @Test // DATAREST-654 - public void deserializesTranslatedEnumProperty() throws Exception { + void deserializesTranslatedEnumProperty() throws Exception { assertThat(mapper.readValue("{ \"gender\" : \"Male\" }", User.class).gender).isEqualTo(Gender.MALE); } @Test // DATAREST-864 - public void createsNestedResourceForMap() throws Exception { + void createsNestedResourceForMap() throws Exception { User dave = users.save(new User()); dave.colleaguesMap = new HashMap(); diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java index 1b6309e82..93eaef24d 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java @@ -15,18 +15,18 @@ */ package org.springframework.data.rest.webmvc.json; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; import static org.mockito.Mockito.*; import java.util.ArrayList; import java.util.List; import org.hamcrest.Matcher; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.hamcrest.MatcherAssert; +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.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -48,7 +48,7 @@ import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaCon import org.springframework.data.rest.webmvc.mapping.Associations; import org.springframework.hateoas.mediatype.MessageResolver; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -59,9 +59,9 @@ import com.jayway.jsonpath.PathNotFoundException; * @author Oliver Gierke * @author Greg Turnquist */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { MongoDbRepositoryConfig.class, TestConfiguration.class }) -public class PersistentEntityToJsonSchemaConverterUnitTests { +class PersistentEntityToJsonSchemaConverterUnitTests { @Autowired MessageResolver resolver; @Autowired RepositoryRestConfiguration configuration; @@ -89,8 +89,8 @@ public class PersistentEntityToJsonSchemaConverterUnitTests { PersistentEntityToJsonSchemaConverter converter; - @Before - public void setUp() { + @BeforeEach + void setUp() { TestMvcClient.initWebTest(); @@ -101,7 +101,7 @@ public class PersistentEntityToJsonSchemaConverterUnitTests { } @Test // DATAREST-631, DATAREST-632 - public void fulfillsConstraintsForProfile() { + void fulfillsConstraintsForProfile() { List constraints = new ArrayList(); constraints.add(new Constraint("$.properties.id", is(notNullValue()), "Has descriptor for id property")); @@ -114,7 +114,7 @@ public class PersistentEntityToJsonSchemaConverterUnitTests { } @Test // DATAREST-632 - public void fulfillsConstraintsForUser() throws Exception { + void fulfillsConstraintsForUser() throws Exception { List constraints = new ArrayList(); constraints.add(new Constraint("$.properties.id", is(nullValue()), "Does NOT have descriptor for id property")); @@ -166,7 +166,7 @@ public class PersistentEntityToJsonSchemaConverterUnitTests { } @Test // DATAREST-754 - public void handlesGroovyDomainObjects() { + void handlesGroovyDomainObjects() { List constraints = new ArrayList(); constraints.add(new Constraint("$.properties.name", is(notNullValue()), "Has descriptor for name property")); @@ -182,11 +182,12 @@ public class PersistentEntityToJsonSchemaConverterUnitTests { for (Constraint constraint : constraints) { try { - assertThat(constraint.description, JsonPath.read(writeSchemaFor, constraint.selector), constraint.matcher); + MatcherAssert.assertThat(constraint.description, JsonPath.read(writeSchemaFor, constraint.selector), + constraint.matcher); } catch (PathNotFoundException e) { assertThat(constraint.matcher.matches(null)).isTrue(); } catch (RuntimeException e) { - assertThat(e, constraint.matcher); + MatcherAssert.assertThat(e, constraint.matcher); } } } diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryLinkBuildUnitTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryLinkBuildUnitTests.java index 96725b11b..d6bfc5523 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryLinkBuildUnitTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryLinkBuildUnitTests.java @@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.mapping.context.PersistentEntities; import org.springframework.data.mongodb.core.mapping.MongoMappingContext; import org.springframework.data.rest.core.mapping.PersistentEntitiesResourceMappings; @@ -34,12 +34,12 @@ import org.springframework.hateoas.Link; * * @author Oliver Gierke */ -public class RepositoryLinkBuildUnitTests { +class RepositoryLinkBuildUnitTests { MongoMappingContext context = new MongoMappingContext(); @Test // DATAREST-292 - public void usesCurrentRequestsUriBaseForRelativeBaseUri() { + void usesCurrentRequestsUriBaseForRelativeBaseUri() { TestMvcClient.initWebTest(); @@ -47,7 +47,7 @@ public class RepositoryLinkBuildUnitTests { } @Test // DATAREST-292, DATAREST-296 - public void usesBaseUriOnlyIfItIsAbsolute() { + void usesBaseUriOnlyIfItIsAbsolute() { assertRootUriFor("http://foobar/api", "http://foobar/api/profile"); } diff --git a/spring-data-rest-tests/spring-data-rest-tests-security/src/test/java/org/springframework/data/rest/tests/security/SecurityConfiguration.java b/spring-data-rest-tests/spring-data-rest-tests-security/src/test/java/org/springframework/data/rest/tests/security/SecurityConfiguration.java index da45c24d1..d7588b3d6 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-security/src/test/java/org/springframework/data/rest/tests/security/SecurityConfiguration.java +++ b/spring-data-rest-tests/spring-data-rest-tests-security/src/test/java/org/springframework/data/rest/tests/security/SecurityConfiguration.java @@ -28,10 +28,10 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur @Configuration // <1> @EnableWebSecurity @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) // <2> -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { // <3> +class SecurityConfiguration extends WebSecurityConfigurerAdapter { // <3> // end::code[] @Autowired - public void configureAuth(AuthenticationManagerBuilder auth) throws Exception { + void configureAuth(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser("user").password("user").roles("USER").and() diff --git a/spring-data-rest-tests/spring-data-rest-tests-security/src/test/java/org/springframework/data/rest/tests/security/SecurityIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-security/src/test/java/org/springframework/data/rest/tests/security/SecurityIntegrationTests.java index e8de19ecc..4b56335b5 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-security/src/test/java/org/springframework/data/rest/tests/security/SecurityIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-security/src/test/java/org/springframework/data/rest/tests/security/SecurityIntegrationTests.java @@ -20,9 +20,9 @@ import static org.springframework.security.test.web.servlet.setup.SecurityMockMv import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -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.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.data.map.repository.config.EnableMapRepositories; @@ -36,7 +36,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -48,10 +48,10 @@ import org.springframework.web.context.WebApplicationContext; * @author Greg Turnquist * @author Rob Winch */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { SecurityIntegrationTests.Config.class, SecurityConfiguration.class, RepositoryRestMvcConfiguration.class }) -public class SecurityIntegrationTests extends AbstractWebIntegrationTests { +class SecurityIntegrationTests extends AbstractWebIntegrationTests { @Autowired WebApplicationContext context; @Autowired MethodSecurityInterceptor methodSecurityInterceptor; @@ -63,7 +63,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { @EnableMapRepositories static class Config {} - @Before + @BeforeEach @Override public void setUp() { @@ -96,7 +96,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-327 - public void deletePersonAccessDeniedForNoCredentials() throws Exception { + void deletePersonAccessDeniedForNoCredentials() throws Exception { // Getting the collection is not tested here. This is to get the URI that will later be tested for DELETE final String people = client.discoverUnique("people").expand().getHref(); @@ -113,7 +113,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-327 - public void deletePersonAccessDeniedForUsers() throws Exception { + void deletePersonAccessDeniedForUsers() throws Exception { MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("people").expand().getHref()).// with(user("user").roles("USER"))).// @@ -128,7 +128,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-327 - public void deletePersonAccessGrantedForAdmins() throws Exception { + void deletePersonAccessGrantedForAdmins() throws Exception { MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("people").expand().getHref()).// with(user("user").roles("USER", "ADMIN"))).// @@ -143,14 +143,14 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-327 - public void findAllPeopleAccessDeniedForNoCredentials() throws Throwable { + void findAllPeopleAccessDeniedForNoCredentials() throws Throwable { mvc.perform(get(client.discoverUnique("people").expand().getHref())).// andExpect(status().isUnauthorized()); } @Test // DATAREST-327 - public void findAllPeopleAccessGrantedForUsers() throws Throwable { + void findAllPeopleAccessGrantedForUsers() throws Throwable { mvc.perform(get(client.discoverUnique("people").expand().getHref()).// with(user("user").roles("USER"))).// @@ -158,7 +158,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-327 - public void findAllPeopleAccessGrantedForAdmins() throws Throwable { + void findAllPeopleAccessGrantedForAdmins() throws Throwable { mvc.perform(get(client.discoverUnique("people").expand().getHref()).// with(user("user").roles("USER", "ADMIN"))).// @@ -166,7 +166,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-327 - public void deleteOrderAccessDeniedForNoCredentials() throws Exception { + void deleteOrderAccessDeniedForNoCredentials() throws Exception { // Getting the collection is not tested here. This is to get the URI that will later be tested for DELETE MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).// @@ -181,7 +181,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-327 - public void deleteOrderAccessDeniedForUsers() throws Exception { + void deleteOrderAccessDeniedForUsers() throws Exception { MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).// with(user("user").roles("USER"))).// @@ -193,7 +193,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-327 - public void deleteOrderAccessGrantedForAdmins() throws Exception { + void deleteOrderAccessGrantedForAdmins() throws Exception { MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).// with(user("user").roles("USER"))).// @@ -208,14 +208,14 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-327 - public void findAllOrdersAccessDeniedForNoCredentials() throws Throwable { + void findAllOrdersAccessDeniedForNoCredentials() throws Throwable { mvc.perform(get(client.discoverUnique("orders").expand().getHref())).// andExpect(status().isUnauthorized()); } @Test // DATAREST-327 - public void findAllOrdersAccessGrantedForUsers() throws Throwable { + void findAllOrdersAccessGrantedForUsers() throws Throwable { mvc.perform(get(client.discoverUnique("orders").expand().getHref()).// with(user("user").roles("USER"))).// @@ -223,7 +223,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-327 - public void findAllOrdersAccessGrantedForAdmins() throws Throwable { + void findAllOrdersAccessGrantedForAdmins() throws Throwable { mvc.perform(get(client.discoverUnique("orders").expand().getHref()).// with(user("user").roles("USER", "ADMIN"))).// diff --git a/spring-data-rest-tests/spring-data-rest-tests-shop/src/test/java/org/springframework/data/rest/tests/shop/ShopConfiguration.java b/spring-data-rest-tests/spring-data-rest-tests-shop/src/test/java/org/springframework/data/rest/tests/shop/ShopConfiguration.java index 50a3a1879..4f12c0a30 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-shop/src/test/java/org/springframework/data/rest/tests/shop/ShopConfiguration.java +++ b/spring-data-rest-tests/spring-data-rest-tests-shop/src/test/java/org/springframework/data/rest/tests/shop/ShopConfiguration.java @@ -36,7 +36,7 @@ import org.springframework.hateoas.server.RepresentationModelProcessor; */ @Configuration @EnableMapRepositories -public class ShopConfiguration { +class ShopConfiguration { @Autowired CustomerRepository customers; @Autowired OrderRepository orders; @@ -77,7 +77,7 @@ public class ShopConfiguration { } @PostConstruct - public void init() { + void init() { LineItemType lineItemType = lineItemTypes.save(new LineItemType("good")); diff --git a/spring-data-rest-tests/spring-data-rest-tests-shop/src/test/java/org/springframework/data/rest/tests/shop/ShopIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-shop/src/test/java/org/springframework/data/rest/tests/shop/ShopIntegrationTests.java index 068db1547..fa7d75c2a 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-shop/src/test/java/org/springframework/data/rest/tests/shop/ShopIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-shop/src/test/java/org/springframework/data/rest/tests/shop/ShopIntegrationTests.java @@ -21,12 +21,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. 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.springframework.data.rest.tests.AbstractWebIntegrationTests; import org.springframework.hateoas.Link; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.ResultActions; import com.jayway.jsonpath.JsonPath; @@ -37,12 +37,12 @@ import com.jayway.jsonpath.JsonPath; * @author Oliver Gierke * @author Craig Andrews */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = ShopConfiguration.class) -public class ShopIntegrationTests extends AbstractWebIntegrationTests { +class ShopIntegrationTests extends AbstractWebIntegrationTests { @Test - public void rendersRepresentationCorrectly() throws Exception { + void rendersRepresentationCorrectly() throws Exception { Link ordersLink = client.discoverUnique("orders"); String selfLink = JsonPath.parse(client.request(ordersLink).getContentAsString()) @@ -63,7 +63,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-221 - public void renderProductNameOnlyProjection() throws Exception { + void renderProductNameOnlyProjection() throws Exception { Map arguments = Collections.singletonMap("projection", "nameOnly"); @@ -74,7 +74,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-221 - public void renderProductNameOnlyProjectionResourceProcessor() throws Exception { + void renderProductNameOnlyProjectionResourceProcessor() throws Exception { Map arguments = Collections.singletonMap("projection", "nameOnly"); @@ -84,7 +84,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests { } @Test // DATAREST-221 - public void renderOrderItemsOnlyProjectionResourceProcessor() throws Exception { + void renderOrderItemsOnlyProjectionResourceProcessor() throws Exception { Map arguments = Collections.singletonMap("projection", "itemsOnly"); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AssociationLinksUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AssociationLinksUnitTests.java index 55a7aee22..d3483af0b 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AssociationLinksUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AssociationLinksUnitTests.java @@ -21,11 +21,13 @@ import static org.mockito.Mockito.*; 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.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.annotation.Reference; import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; import org.springframework.data.mapping.PersistentEntity; @@ -47,8 +49,9 @@ import org.springframework.hateoas.Link; * @author Oliver Gierke * @author Haroun Pacquee */ -@RunWith(MockitoJUnitRunner.class) -public class AssociationLinksUnitTests { +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +class AssociationLinksUnitTests { Associations links; @@ -60,8 +63,8 @@ public class AssociationLinksUnitTests { @Mock RepositoryRestConfiguration config; @Mock ProjectionDefinitionConfiguration projectionDefinitionConfig; - @Before - public void setUp() { + @BeforeEach + void setUp() { doReturn(projectionDefinitionConfig).when(config).getProjectionConfiguration(); @@ -71,18 +74,22 @@ public class AssociationLinksUnitTests { this.links = new Associations(mappings, config); } - @Test(expected = IllegalArgumentException.class) // DATAREST-262 - public void rejectsNullMappings() { - new Associations(null, mock(RepositoryRestConfiguration.class)); + @Test // DATAREST-262 + void rejectsNullMappings() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new Associations(null, mock(RepositoryRestConfiguration.class))); } - @Test(expected = IllegalArgumentException.class) - public void rejectsNullConfiguration() { - new Associations(mappings, null); + @Test + void rejectsNullConfiguration() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new Associations(mappings, null)); } @Test // DATAREST-262 - public void rejectsNullPropertyForIsLinkable() { + void rejectsNullPropertyForIsLinkable() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { links.isLinkableAssociation((PersistentProperty) null); @@ -90,12 +97,12 @@ public class AssociationLinksUnitTests { } @Test // DATAREST-262 - public void consideredHiddenPropertyUnlinkable() { + void consideredHiddenPropertyUnlinkable() { assertThat(links.isLinkableAssociation(entity.getRequiredPersistentProperty("hiddenProperty"))).isFalse(); } @Test // DATAREST-262 - public void createsLinkToAssociationProperty() { + void createsLinkToAssociationProperty() { PersistentProperty property = entity.getRequiredPersistentProperty("property"); List associationLinks = links.getLinksFor(property.getRequiredAssociation(), new Path("/base")); @@ -105,14 +112,14 @@ public class AssociationLinksUnitTests { } @Test // DATAREST-262 - public void doesNotCreateLinksForHiddenProperty() { + void doesNotCreateLinksForHiddenProperty() { PersistentProperty property = entity.getRequiredPersistentProperty("hiddenProperty"); assertThat(links.getLinksFor(property.getRequiredAssociation(), new Path("/sample"))).hasSize(0); } @Test - public void detectsLookupTypes() { + void detectsLookupTypes() { doReturn(true).when(config).isLookupType(Property.class); @@ -120,7 +127,7 @@ public class AssociationLinksUnitTests { } @Test - public void delegatesResourceMetadataLookupToMappings() { + void delegatesResourceMetadataLookupToMappings() { assertThat(links.getMetadataFor(Property.class)).isEqualTo(mappings.getMetadataFor(Property.class)); } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AugmentingHandlerMappingUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AugmentingHandlerMappingUnitTests.java index 8508df8be..752d6fb8b 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AugmentingHandlerMappingUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AugmentingHandlerMappingUnitTests.java @@ -20,7 +20,7 @@ import static org.mockito.Mockito.*; import java.util.Map; -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; @@ -39,7 +39,7 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfo; * @author Oliver Gierke * @author Greg Turnquist */ -public class AugmentingHandlerMappingUnitTests { +class AugmentingHandlerMappingUnitTests { @Configuration static class Config { @@ -51,7 +51,7 @@ public class AugmentingHandlerMappingUnitTests { } @Test - public void augmentsRequestMappingsWithBaseUriFromConfiguration() { + void augmentsRequestMappingsWithBaseUriFromConfiguration() { RepositoryRestConfiguration configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(), new MetadataConfiguration(), mock(EnumTranslationConfiguration.class)); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BasePathAwareHandlerMappingUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BasePathAwareHandlerMappingUnitTests.java index 6853c4c4a..8ed0cd1e6 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BasePathAwareHandlerMappingUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BasePathAwareHandlerMappingUnitTests.java @@ -20,8 +20,8 @@ import static org.mockito.Mockito.*; import java.net.URI; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.support.AopUtils; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; @@ -33,12 +33,12 @@ import org.springframework.web.bind.annotation.RequestMapping; * * @author Oliver Gierke */ -public class BasePathAwareHandlerMappingUnitTests { +class BasePathAwareHandlerMappingUnitTests { HandlerMappingStub mapping; - @Before - public void setUp() { + @BeforeEach + void setUp() { RepositoryRestConfiguration configuration = mock(RepositoryRestConfiguration.class); doReturn(URI.create("")).when(configuration).getBasePath(); @@ -47,7 +47,7 @@ public class BasePathAwareHandlerMappingUnitTests { } @Test // DATAREST-1132 - public void detectsAnnotationsOnProxies() { + void detectsAnnotationsOnProxies() { Class type = createProxy(new SomeController()); @@ -55,7 +55,7 @@ public class BasePathAwareHandlerMappingUnitTests { } @Test // DATAREST-1132 - public void doesNotConsiderMetaAnnotation() { + void doesNotConsiderMetaAnnotation() { Class type = createProxy(new RepositoryController()); @@ -63,7 +63,7 @@ public class BasePathAwareHandlerMappingUnitTests { } @Test // #1342, #1628, #1686, #1946 - public void rejectsAtRequestMappingOnCustomController() { + void rejectsAtRequestMappingOnCustomController() { assertThatIllegalStateException() .isThrownBy(() -> { @@ -73,7 +73,7 @@ public class BasePathAwareHandlerMappingUnitTests { } @Test // #1342, #1628, #1686, #1946 - public void doesNotRejectAtRequestMappingOnStandardMvcController() { + void doesNotRejectAtRequestMappingOnStandardMvcController() { assertThatNoException() .isThrownBy(() -> mapping.isHandler(ValidController.class)); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BaseUriUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BaseUriUnitTests.java index c01ddb539..5a4c28d86 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BaseUriUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BaseUriUnitTests.java @@ -19,24 +19,24 @@ import static org.assertj.core.api.Assertions.*; import java.net.URI; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link BaseUri}. * * @author Oliver Gierke */ -public class BaseUriUnitTests { +class BaseUriUnitTests { @Test // DATAREST-276 - public void doesNotMatchNonOverlap() { + void doesNotMatchNonOverlap() { assertThat(new BaseUri(URI.create("foo")).getRepositoryLookupPath("/bar")).isNull(); assertThat(new BaseUri(URI.create("http://localhost:8080/foo/")).getRepositoryLookupPath("/bar")).isNull(); } @Test // DATAREST-276 - public void matchesSimpleBaseUri() { + void matchesSimpleBaseUri() { BaseUri uri = new BaseUri(URI.create("foo")); @@ -44,7 +44,7 @@ public class BaseUriUnitTests { } @Test // DATAREST-276 - public void ignoresTrailingSlash() { + void ignoresTrailingSlash() { BaseUri uri = new BaseUri(URI.create("foo/")); @@ -53,7 +53,7 @@ public class BaseUriUnitTests { } @Test // DATAREST-276 - public void ignoresLeadingSlash() { + void ignoresLeadingSlash() { BaseUri uri = new BaseUri(URI.create("/foo")); @@ -62,7 +62,7 @@ public class BaseUriUnitTests { } @Test // DATAREST-276 - public void matchesAbsoluteBaseUriOnOverlap() { + void matchesAbsoluteBaseUriOnOverlap() { BaseUri uri = new BaseUri(URI.create("http://localhost:8080/foo/")); @@ -73,7 +73,7 @@ public class BaseUriUnitTests { } @Test // DATAREST-674, SPR-13455 - public void repositoryLookupPathHandlesDoubleSlashes() { + void repositoryLookupPathHandlesDoubleSlashes() { assertThat(BaseUri.NONE.getRepositoryLookupPath("/books//1")).isEqualTo("/books/1"); } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/CustomAcceptHeaderHttpServletRequestUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/CustomAcceptHeaderHttpServletRequestUnitTests.java index 1d4a5c4af..ad694d6f5 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/CustomAcceptHeaderHttpServletRequestUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/CustomAcceptHeaderHttpServletRequestUnitTests.java @@ -23,8 +23,7 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; -import org.junit.Test; - +import org.junit.jupiter.api.Test; import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.CustomAcceptHeaderHttpServletRequest; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -37,12 +36,12 @@ import org.springframework.util.StringUtils; * @author Oliver Gierke * @soundtrack Spring engineering team meeting @ SpringOne Platform 2016 */ -public class CustomAcceptHeaderHttpServletRequestUnitTests { +class CustomAcceptHeaderHttpServletRequestUnitTests { HttpServletRequest request = new MockHttpServletRequest(); @Test // DATAREST-863 - public void returnsRegisterdHeadersOnAccessForMultipleOnes() { + void returnsRegisterdHeadersOnAccessForMultipleOnes() { List mediaTypes = Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_ATOM_XML); HttpServletRequest servletRequest = new CustomAcceptHeaderHttpServletRequest(request, mediaTypes); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/IncomingRequestUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/IncomingRequestUnitTests.java index 52445e567..2bf29d832 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/IncomingRequestUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/IncomingRequestUnitTests.java @@ -17,8 +17,8 @@ package org.springframework.data.rest.webmvc; 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.http.server.ServletServerHttpRequest; import org.springframework.mock.web.MockHttpServletRequest; @@ -27,17 +27,17 @@ import org.springframework.mock.web.MockHttpServletRequest; * * @author Oliver Gierke */ -public class IncomingRequestUnitTests { +class IncomingRequestUnitTests { MockHttpServletRequest request; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.request = new MockHttpServletRequest("PATCH", "/"); } @Test // DATAREST-498 - public void identifiesJsonPatchRequestForRequestWithContentTypeParameters() { + void identifiesJsonPatchRequestForRequestWithContentTypeParameters() { request.addHeader("Content-Type", "application/json-patch+json;charset=UTF-8"); @@ -48,7 +48,7 @@ public class IncomingRequestUnitTests { } @Test // DATAREST-498 - public void identifiesJsonMergePatchRequestForRequestWithContentTypeParameters() { + void identifiesJsonMergePatchRequestForRequestWithContentTypeParameters() { request.addHeader("Content-Type", "application/merge-patch+json;charset=UTF-8"); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceUnitTests.java index d04e7d9a0..5de7ff614 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceUnitTests.java @@ -19,11 +19,11 @@ import static org.assertj.core.api.Assertions.*; 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.data.mapping.PersistentEntity; import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.Link; @@ -36,8 +36,8 @@ import org.springframework.hateoas.server.core.EmbeddedWrappers; * * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class PersistentEntityResourceUnitTests { +@ExtendWith(MockitoExtension.class) +class PersistentEntityResourceUnitTests { @Mock Object payload; @Mock PersistentEntity entity; @@ -45,26 +45,30 @@ public class PersistentEntityResourceUnitTests { CollectionModel resources; Link link = Link.of("http://localhost", "foo"); - @Before - public void setUp() { + @BeforeEach + void setUp() { EmbeddedWrappers wrappers = new EmbeddedWrappers(false); EmbeddedWrapper wrapper = wrappers.wrap("Embedded", LinkRelation.of("foo")); this.resources = CollectionModel.of(Collections.singleton(wrapper)); } - @Test(expected = IllegalArgumentException.class) // DATAREST-317 - public void rejectsNullPayload() { - PersistentEntityResource.build(null, entity); - } + @Test // DATAREST-317 + void rejectsNullPayload() { - @Test(expected = IllegalArgumentException.class) // DATAREST-317 - public void rejectsNullPersistentEntity() { - PersistentEntityResource.build(payload, null); + assertThatIllegalArgumentException() // + .isThrownBy(() -> PersistentEntityResource.build(null, entity)); } @Test // DATAREST-317 - public void defaultsEmbeddedsToEmptyResources() { + void rejectsNullPersistentEntity() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> PersistentEntityResource.build(payload, null)); + } + + @Test // DATAREST-317 + void defaultsEmbeddedsToEmptyResources() { PersistentEntityResource resource = PersistentEntityResource.build(payload, entity).build(); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryCorsConfigurationAccessorUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryCorsConfigurationAccessorUnitTests.java index 469cce37b..9d907bb84 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryCorsConfigurationAccessorUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryCorsConfigurationAccessorUnitTests.java @@ -20,11 +20,11 @@ import static org.mockito.Mockito.*; 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.repository.support.Repositories; import org.springframework.data.rest.core.mapping.ResourceMappings; import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.NoOpStringValueResolver; @@ -41,22 +41,22 @@ import org.springframework.web.cors.CorsConfiguration; * @soundtrack Aso Mamiko - Drive Me Crazy (Club Mix) * @since 2.6 */ -@RunWith(MockitoJUnitRunner.class) -public class RepositoryCorsConfigurationAccessorUnitTests { +@ExtendWith(MockitoExtension.class) +class RepositoryCorsConfigurationAccessorUnitTests { RepositoryCorsConfigurationAccessor accessor; @Mock ResourceMappings mappings; @Mock Repositories repositories; - @Before - public void before() throws Exception { + @BeforeEach + void before() throws Exception { accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE, Optional.of(repositories)); } @Test // DATAREST-573 - public void createConfigurationShouldConstructCorsConfiguration() { + void createConfigurationShouldConstructCorsConfiguration() { CorsConfiguration configuration = accessor.createConfiguration(AnnotatedRepository.class); @@ -71,7 +71,7 @@ public class RepositoryCorsConfigurationAccessorUnitTests { } @Test // DATAREST-573 - public void createConfigurationShouldConstructFullCorsConfiguration() { + void createConfigurationShouldConstructFullCorsConfiguration() { CorsConfiguration configuration = accessor.createConfiguration(FullyConfiguredCorsRepository.class); @@ -87,7 +87,7 @@ public class RepositoryCorsConfigurationAccessorUnitTests { } @Test // DATAREST-994 - public void returnsNoCorsConfigurationWithNoRepositories() { + void returnsNoCorsConfigurationWithNoRepositories() { accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE, Optional.empty()); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryEntityControllerTest.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryEntityControllerTest.java index 1be54c526..68df9827a 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryEntityControllerTest.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryEntityControllerTest.java @@ -20,10 +20,10 @@ 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.keyvalue.core.mapping.KeyValuePersistentEntity; import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; import org.springframework.data.mapping.context.PersistentEntities; @@ -41,8 +41,8 @@ import org.springframework.data.web.PagedResourcesAssembler; * * @author Jeroen Reijn */ -@RunWith(MockitoJUnitRunner.class) -public class RepositoryEntityControllerTest { +@ExtendWith(MockitoExtension.class) +class RepositoryEntityControllerTest { @Mock Repositories repositories; @Mock RepositoryRestConfiguration restConfiguration; @@ -54,7 +54,7 @@ public class RepositoryEntityControllerTest { KeyValueMappingContext mappingContext = new KeyValueMappingContext<>(); @Test // DATAREST-1143 - public void testUnknownItemThrowsResourceNotFound() throws Exception { + void testUnknownItemThrowsResourceNotFound() throws Exception { KeyValuePersistentEntity entity = mappingContext .getRequiredPersistentEntity(RepositoryPropertyReferenceControllerUnitTests.Sample.class); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java index 7303c9e5d..bde552dc2 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java @@ -23,10 +23,10 @@ import java.util.Collections; import java.util.List; 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.context.ApplicationEventPublisher; import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity; import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; @@ -53,8 +53,8 @@ import org.springframework.http.HttpMethod; * * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class RepositoryPropertyReferenceControllerUnitTests { +@ExtendWith(MockitoExtension.class) +class RepositoryPropertyReferenceControllerUnitTests { @Mock Repositories repositories; @Mock PagedResourcesAssembler assembler; @@ -65,7 +65,7 @@ public class RepositoryPropertyReferenceControllerUnitTests { KeyValueMappingContext mappingContext = new KeyValueMappingContext<>(); @Test // DATAREST-791 - public void usesRepositoryInvokerToLookupRelatedInstance() throws Exception { + void usesRepositoryInvokerToLookupRelatedInstance() throws Exception { KeyValuePersistentEntity entity = mappingContext.getRequiredPersistentEntity(Sample.class); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandlerUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandlerUnitTests.java index cf3147036..aa73db50f 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandlerUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandlerUnitTests.java @@ -20,9 +20,9 @@ import static org.assertj.core.api.Assertions.*; import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.slf4j.LoggerFactory; import org.springframework.context.support.StaticMessageSource; import org.springframework.dao.DataIntegrityViolationException; @@ -37,14 +37,14 @@ import org.springframework.mock.http.MockHttpInputMessage; * * @author Oliver Gierke */ -public class RepositoryRestExceptionHandlerUnitTests { +class RepositoryRestExceptionHandlerUnitTests { static final RepositoryRestExceptionHandler HANDLER = new RepositoryRestExceptionHandler(new StaticMessageSource()); static Logger logger; static Level logLevel; - @BeforeClass + @BeforeAll public static void silenceLog() { logger = (Logger) LoggerFactory.getLogger(RepositoryRestExceptionHandler.class); @@ -52,13 +52,13 @@ public class RepositoryRestExceptionHandlerUnitTests { logger.setLevel(Level.OFF); } - @AfterClass + @AfterAll public static void enableLogging() { logger.setLevel(logLevel); } @Test // DATAREST-427 - public void handlesHttpMessageNotReadableException() { + void handlesHttpMessageNotReadableException() { ResponseEntity result = HANDLER .handleNotReadable(new HttpMessageNotReadableException("Message!", new MockHttpInputMessage(new byte[0]))); @@ -67,7 +67,7 @@ public class RepositoryRestExceptionHandlerUnitTests { } @Test // DATAREST-507 - public void handlesConflictCorrectly() { + void handlesConflictCorrectly() { ResponseEntity result = HANDLER.handleConflict(new DataIntegrityViolationException("Message!")); @@ -75,7 +75,7 @@ public class RepositoryRestExceptionHandlerUnitTests { } @Test // DATAREST-706 - public void forwardsExceptionForMiscellaneousFailure() { + void forwardsExceptionForMiscellaneousFailure() { String message = "My Message!"; diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingUnitTests.java index f4da2663d..ab2cb4bd4 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingUnitTests.java @@ -25,11 +25,11 @@ import java.util.function.Supplier; import javax.servlet.http.HttpServletRequest; -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.aop.framework.ProxyFactory; import org.springframework.aop.support.AopUtils; import org.springframework.data.domain.Sort; @@ -57,8 +57,8 @@ import org.springframework.web.util.pattern.PathPattern; * @author Greg Turnquist * @author Mark Paluch */ -@RunWith(MockitoJUnitRunner.Silent.class) -public class RepositoryRestHandlerMappingUnitTests { +@ExtendWith(MockitoExtension.class) +class RepositoryRestHandlerMappingUnitTests { static final AnnotationConfigWebApplicationContext CONTEXT = new AnnotationConfigWebApplicationContext(); @@ -68,8 +68,8 @@ public class RepositoryRestHandlerMappingUnitTests { CONTEXT.refresh(); } - @Mock ResourceMappings mappings; - @Mock ResourceMetadata resourceMetadata; + @Mock(lenient = true) ResourceMappings mappings; + @Mock(lenient = true) ResourceMetadata resourceMetadata; @Mock Repositories repositories; RepositoryRestConfiguration configuration; @@ -77,8 +77,8 @@ public class RepositoryRestHandlerMappingUnitTests { MockHttpServletRequest mockRequest; Method listEntitiesMethod, rootHandlerMethod; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(), new MetadataConfiguration(), mock(EnumTranslationConfiguration.class)); @@ -99,23 +99,27 @@ public class RepositoryRestHandlerMappingUnitTests { rootHandlerMethod = RepositoryController.class.getMethod("listRepositories"); } - @Test(expected = IllegalArgumentException.class) - public void rejectsNullMappings() { - new RepositoryRestHandlerMapping(null, configuration); + @Test + void rejectsNullMappings() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new RepositoryRestHandlerMapping(null, configuration)); } - @Test(expected = IllegalArgumentException.class) - public void rejectsNullConfiguration() { - new RepositoryRestHandlerMapping(mappings, null); + @Test + void rejectsNullConfiguration() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new RepositoryRestHandlerMapping(mappings, null)); } @Test // DATAREST-111 - public void returnsNullForUriNotMapped() throws Exception { + void returnsNullForUriNotMapped() throws Exception { assertThat(handlerMapping.get().getHandler(mockRequest)).isNull(); } @Test // DATAREST-111 - public void looksUpRepositoryEntityControllerMethodCorrectly() throws Exception { + void looksUpRepositoryEntityControllerMethodCorrectly() throws Exception { when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true); mockRequest = new MockHttpServletRequest("GET", "/people"); @@ -127,7 +131,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-292 - public void returnsRepositoryHandlerMethodWithBaseUriConfigured() throws Exception { + void returnsRepositoryHandlerMethodWithBaseUriConfigured() throws Exception { when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true); mockRequest = new MockHttpServletRequest("GET", "/base/people"); @@ -141,7 +145,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-292 - public void returnsRootHandlerMethodWithBaseUriConfigured() throws Exception { + void returnsRootHandlerMethodWithBaseUriConfigured() throws Exception { mockRequest = new MockHttpServletRequest("GET", "/base"); @@ -154,7 +158,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-276 - public void returnsRepositoryHandlerMethodForAbsoluteBaseUri() throws Exception { + void returnsRepositoryHandlerMethodForAbsoluteBaseUri() throws Exception { when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true); mockRequest = new MockHttpServletRequest("GET", "/base/people/"); @@ -168,7 +172,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-276 - public void returnsRepositoryHandlerMethodForAbsoluteBaseUriWithServletMapping() throws Exception { + void returnsRepositoryHandlerMethodForAbsoluteBaseUriWithServletMapping() throws Exception { when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true); mockRequest = new MockHttpServletRequest("GET", "/base/people"); @@ -183,7 +187,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-276 - public void refrainsFromMappingIfTheRequestDoesNotPointIntoAbsolutelyDefinedUriSpace() throws Exception { + void refrainsFromMappingIfTheRequestDoesNotPointIntoAbsolutelyDefinedUriSpace() throws Exception { mockRequest = new MockHttpServletRequest("GET", "/servlet-path"); mockRequest.setServletPath("/servlet-path"); @@ -196,7 +200,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-276 - public void refrainsFromMappingWhenUrisDontMatch() throws Exception { + void refrainsFromMappingWhenUrisDontMatch() throws Exception { String baseUri = "foo"; String uri = baseUri.concat("/people"); @@ -213,7 +217,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-609 - public void rejectsUnexpandedUriTemplateWithNotFound() throws Exception { + void rejectsUnexpandedUriTemplateWithNotFound() throws Exception { when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true); @@ -223,7 +227,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-1019 - public void resolvesCorsConfigurationFromRequestUri() { + void resolvesCorsConfigurationFromRequestUri() { String uri = "/people"; @@ -240,7 +244,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-1019 - public void stripsBaseUriForCorsConfigurationResolution() { + void stripsBaseUriForCorsConfigurationResolution() { String baseUri = "/foo"; String uri = baseUri.concat("/people"); @@ -260,12 +264,12 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-994 - public void twoArgumentConstructorDoesNotThrowException() { + void twoArgumentConstructorDoesNotThrowException() { new RepositoryRestHandlerMapping(mappings, configuration); } @Test // DATAREST-1132 - public void detectsAnnotationsOnProxies() { + void detectsAnnotationsOnProxies() { Class type = createProxy(new SomeController()); @@ -278,7 +282,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-1294 - public void exposesEffectiveRepositoryLookupPathAsRequestAttribute() throws Exception { + void exposesEffectiveRepositoryLookupPathAsRequestAttribute() throws Exception { when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true); @@ -293,7 +297,7 @@ public class RepositoryRestHandlerMappingUnitTests { } @Test // DATAREST-1332 - public void handlesCorsPreflightRequestsProperly() throws Exception { + void handlesCorsPreflightRequestsProperly() throws Exception { when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchesResourceUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchesResourceUnitTests.java index 3c3e1eef0..0f771c0a9 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchesResourceUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchesResourceUnitTests.java @@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc; import static org.assertj.core.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link RepositorySearchesResource} @@ -25,15 +25,17 @@ import org.junit.Test; * @author Oliver Gierke * @soundtrack Bakkushan - Gefahr (Bakkushan) */ -public class RepositorySearchesResourceUnitTests { +class RepositorySearchesResourceUnitTests { - @Test(expected = IllegalArgumentException.class) // DATAREST-515 - public void rejectsNullDomainType() { - new RepositorySearchesResource(null); + @Test // DATAREST-515 + void rejectsNullDomainType() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new RepositorySearchesResource(null)); } @Test // DATAREST-515 - public void returnsConfiguredDomainType() { + void returnsConfiguredDomainType() { assertThat(new RepositorySearchesResource(String.class).getDomainType()).isAssignableFrom(String.class); } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/ResourceStatusUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/ResourceStatusUnitTests.java index fa05212f8..78f178c6d 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/ResourceStatusUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/ResourceStatusUnitTests.java @@ -24,13 +24,13 @@ import lombok.Value; import java.util.Date; import java.util.function.Supplier; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -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.annotation.Version; import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity; import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; @@ -43,8 +43,9 @@ import org.springframework.http.HttpStatus; * * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class ResourceStatusUnitTests { +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +class ResourceStatusUnitTests { ResourceStatus status; KeyValuePersistentEntity entity; @@ -52,10 +53,8 @@ public class ResourceStatusUnitTests { @Mock HttpHeadersPreparer preparer; @Mock Supplier supplier; - public @Rule ExpectedException exception = ExpectedException.none(); - - @Before - public void setUp() { + @BeforeEach + void setUp() { this.status = ResourceStatus.of(preparer); @@ -65,18 +64,20 @@ public class ResourceStatusUnitTests { doReturn(new HttpHeaders()).when(preparer).prepareHeaders(eq(entity), any()); } - @Test(expected = IllegalArgumentException.class) // DATAREST-835 - public void rejectsNullPreparer() { - ResourceStatus.of(null); + @Test // DATAREST-835 + void rejectsNullPreparer() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> ResourceStatus.of(null)); } @Test // DATAREST-835 - public void returnsModifiedIfNoHeadersGiven() { + void returnsModifiedIfNoHeadersGiven() { assertModified(status.getStatusAndHeaders(new HttpHeaders(), new Sample(0), entity)); } @Test // DATAREST-835 - public void returnsNotModifiedForEntityWithRequestedETag() { + void returnsNotModifiedForEntityWithRequestedETag() { HttpHeaders headers = new HttpHeaders(); headers.setIfNoneMatch("\"1\""); @@ -85,7 +86,7 @@ public class ResourceStatusUnitTests { } @Test // DATAREST-835 - public void returnsNotModifiedIfEntityIsStillConsideredValid() { + void returnsNotModifiedIfEntityIsStillConsideredValid() { doReturn(true).when(preparer).isObjectStillValid(any(), any(HttpHeaders.class)); @@ -93,12 +94,11 @@ public class ResourceStatusUnitTests { } @Test // DATAREST-1121 - public void rejectsInvalidPersistentEntityDomainObjectCombination() { + void rejectsInvalidPersistentEntityDomainObjectCombination() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage(entity.getType().getName()); - - assertModified(status.getStatusAndHeaders(new HttpHeaders(), new Date(), entity)); + assertThatIllegalArgumentException() // + .isThrownBy(() -> assertModified(status.getStatusAndHeaders(new HttpHeaders(), new Date(), entity))) + .withMessageContaining(entity.getType().getName()); } private void assertModified(StatusAndHeaders statusAndHeaders) { diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RootResourceInformationUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RootResourceInformationUnitTests.java index d0c19589d..2a09b5030 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RootResourceInformationUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RootResourceInformationUnitTests.java @@ -15,21 +15,22 @@ */ package org.springframework.data.rest.webmvc; +import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -import static org.springframework.data.rest.core.mapping.ResourceType.*; import static org.springframework.http.HttpMethod.*; -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.Mockito; import org.mockito.invocation.InvocationOnMock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.repository.support.RepositoryInvoker; import org.springframework.data.rest.core.mapping.ResourceMetadata; +import org.springframework.data.rest.core.mapping.ResourceType; import org.springframework.web.HttpRequestMethodNotSupportedException; /** @@ -37,8 +38,8 @@ import org.springframework.web.HttpRequestMethodNotSupportedException; * * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class RootResourceInformationUnitTests { +@ExtendWith(MockitoExtension.class) +class RootResourceInformationUnitTests { @Mock ResourceMetadata metadata; @Mock PersistentEntity entity; @@ -46,18 +47,21 @@ public class RootResourceInformationUnitTests { RootResourceInformation information; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.invoker = mock(RepositoryInvoker.class, new DefaultBooleanToTrue()); this.information = new RootResourceInformation(metadata, entity, invoker); } - @Test(expected = ResourceNotFoundException.class) // DATAREST-330 - public void throwsExceptionOnVerificationIfResourceIsNotExported() throws HttpRequestMethodNotSupportedException { + @Test // DATAREST-330 + void throwsExceptionOnVerificationIfResourceIsNotExported() throws HttpRequestMethodNotSupportedException { when(metadata.isExported()).thenReturn(false); - information.verifySupportedMethod(HEAD, COLLECTION); + + assertThatExceptionOfType(ResourceNotFoundException.class) // + .isThrownBy(() -> information.verifySupportedMethod(HEAD, ResourceType.COLLECTION)); + } /** diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/ArgumentResolverPagingAndSortingTemplateVariablesUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/ArgumentResolverPagingAndSortingTemplateVariablesUnitTests.java index d28a9eaab..8b3a2f47a 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/ArgumentResolverPagingAndSortingTemplateVariablesUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/ArgumentResolverPagingAndSortingTemplateVariablesUnitTests.java @@ -19,11 +19,11 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; 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.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.MethodParameter; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -39,25 +39,29 @@ import org.springframework.web.util.UriComponentsBuilder; * * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests { +@ExtendWith(MockitoExtension.class) +class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests { @Mock HateoasPageableHandlerMethodArgumentResolver pageableResolver; @Mock HateoasSortHandlerMethodArgumentResolver sortResolver; @Mock UriComponentsBuilder builder; - @Test(expected = IllegalArgumentException.class) // DATAREST-467 - public void rejectsNullArgumentResolverForPageable() { - new ArgumentResolverPagingAndSortingTemplateVariables(null, sortResolver); - } + @Test // DATAREST-467 + void rejectsNullArgumentResolverForPageable() { - @Test(expected = IllegalArgumentException.class) // DATAREST-467 - public void rejectsNullArgumentResolverForSort() { - new ArgumentResolverPagingAndSortingTemplateVariables(pageableResolver, null); + assertThatIllegalArgumentException() // + .isThrownBy(() -> new ArgumentResolverPagingAndSortingTemplateVariables(null, sortResolver)); } @Test // DATAREST-467 - public void supportsPageableAndSortMethodParameters() { + void rejectsNullArgumentResolverForSort() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new ArgumentResolverPagingAndSortingTemplateVariables(pageableResolver, null)); + } + + @Test // DATAREST-467 + void supportsPageableAndSortMethodParameters() { PagingAndSortingTemplateVariables variables = new ArgumentResolverPagingAndSortingTemplateVariables( pageableResolver, sortResolver); @@ -68,12 +72,12 @@ public class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests { } @Test // DATAREST-467 - public void forwardsEnhanceRequestForPageable() { + void forwardsEnhanceRequestForPageable() { assertForwardsEnhanceFor(PageRequest.of(0, 10), pageableResolver, sortResolver); } @Test // DATAREST-467 - public void forwardsEnhanceRequestForSort() { + void forwardsEnhanceRequestForSort() { assertForwardsEnhanceFor(Sort.by("property"), sortResolver, pageableResolver); } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/DelegatingHandlerMappingUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/DelegatingHandlerMappingUnitTests.java index 9d55a9ff5..ec79bb369 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/DelegatingHandlerMappingUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/DelegatingHandlerMappingUnitTests.java @@ -15,8 +15,7 @@ */ package org.springframework.data.rest.webmvc.config; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -24,11 +23,11 @@ import java.util.Arrays; import javax.servlet.http.HttpServletRequest; -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.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.HttpMediaTypeNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException; @@ -43,14 +42,14 @@ import org.springframework.web.servlet.handler.RequestMatchResult; * @author Oliver Gierke * @soundtrack Benny Greb - Stabila (Moving Parts) */ -@RunWith(MockitoJUnitRunner.Silent.class) -public class DelegatingHandlerMappingUnitTests { +@ExtendWith(MockitoExtension.class) +class DelegatingHandlerMappingUnitTests { @Mock HandlerMapping first, second; @Mock HttpServletRequest request; @Test // DATAREST-490, DATAREST-522, DATAREST-1387 - public void consultsAllHandlerMappingsAndThrowsExceptionEventually() throws Exception { + void consultsAllHandlerMappingsAndThrowsExceptionEventually() throws Exception { DelegatingHandlerMapping mapping = new DelegatingHandlerMapping(Arrays.asList(first, second), null); @@ -61,11 +60,11 @@ public class DelegatingHandlerMappingUnitTests { } @Test // DATAREST-1193 - public void exposesMatchabilityOfSelectedMapping() { + void exposesMatchabilityOfSelectedMapping() { // Given: // A matching mapping that doesn't get selected - MatchableHandlerMapping third = mock(MatchableHandlerMapping.class); + MatchableHandlerMapping third = mock(MatchableHandlerMapping.class, withSettings().lenient()); doReturn(mock(RequestMatchResult.class)).when(third).match(any(), any(String.class)); // A matching mapping that gets selected @@ -83,16 +82,10 @@ public class DelegatingHandlerMappingUnitTests { when(first.getHandler(request)).thenThrow(type); - try { + assertThatExceptionOfType(type) + .isThrownBy(() -> mapping.getHandler(request)); - mapping.getHandler(request); - fail(String.format("Expected %s!", type.getSimpleName())); - - } catch (Exception o_O) { - assertThat(o_O).isInstanceOf(type); - verify(second, times(1)).getHandler(request); - } finally { - reset(first, second); - } + verify(second, times(1)).getHandler(request); + reset(first, second); } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/HalFormsAdaptingResponseBodyAdviceTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/HalFormsAdaptingResponseBodyAdviceTests.java index 04d507cd4..bff2427b3 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/HalFormsAdaptingResponseBodyAdviceTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/HalFormsAdaptingResponseBodyAdviceTests.java @@ -45,7 +45,7 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException; * @author Oliver Drotbohm */ @ExtendWith(MockitoExtension.class) -public class HalFormsAdaptingResponseBodyAdviceTests> { +class HalFormsAdaptingResponseBodyAdviceTests> { HalFormsAdaptingResponseBodyAdvice advice = new HalFormsAdaptingResponseBodyAdvice<>(); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/PersistentEntityResourceHandlerMethodArgumentResolverUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/PersistentEntityResourceHandlerMethodArgumentResolverUnitTests.java index 81e8a3a76..f654d0bb6 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/PersistentEntityResourceHandlerMethodArgumentResolverUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/PersistentEntityResourceHandlerMethodArgumentResolverUnitTests.java @@ -24,8 +24,8 @@ import java.util.Optional; import javax.servlet.http.HttpServletRequest; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.core.MethodParameter; import org.springframework.data.annotation.Id; @@ -53,15 +53,15 @@ import org.springframework.web.method.support.ModelAndViewContainer; * * @author Oliver Gierke */ -public class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests { +class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests { HttpMessageConverter converter; RootResourceInformationHandlerMethodArgumentResolver rootResourceResolver; BackendIdHandlerMethodArgumentResolver backendIdResolver; DomainObjectReader reader; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { this.converter = mock(HttpMessageConverter.class); when(this.converter.canRead((Class) any(), (MediaType) any())).thenReturn(true); @@ -75,7 +75,7 @@ public class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests { @Test // DATAREST-1050 @SuppressWarnings("unchecked") - public void returnsAggregateInstanceWithIdentifierPopulatedForPutRequests() throws Exception { + void returnsAggregateInstanceWithIdentifierPopulatedForPutRequests() throws Exception { PersistentEntityResourceHandlerMethodArgumentResolver argumentResolver = new PersistentEntityResourceHandlerMethodArgumentResolver( Arrays.> asList(converter), rootResourceResolver, backendIdResolver, reader, @@ -95,7 +95,7 @@ public class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests { @Test // DATAREST-1304 @SuppressWarnings("unchecked") - public void setsLookupPropertyForEntitiesWithCustomLookup() throws Exception { + void setsLookupPropertyForEntitiesWithCustomLookup() throws Exception { EntityLookup lookup = mock(EntityLookup.class); doReturn(Optional.of("name")).when(lookup).getLookupProperty(); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java index 0013e697d..466faabdb 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java @@ -25,9 +25,9 @@ import java.util.List; import javax.naming.Name; import javax.naming.ldap.LdapName; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -70,16 +70,16 @@ import com.jayway.jsonpath.JsonPath; * @author Mark Paluch * @author Greg Turnquist */ -public class RepositoryRestMvConfigurationIntegrationTests { +class RepositoryRestMvConfigurationIntegrationTests { static AbstractApplicationContext context; - @BeforeClass + @BeforeAll public static void setUp() { context = new AnnotationConfigApplicationContext(ExtendingConfiguration.class); } - @AfterClass + @AfterAll public static void tearDown() { if (context != null) { context.close(); @@ -87,14 +87,14 @@ public class RepositoryRestMvConfigurationIntegrationTests { } @Test // DATAREST-210 - public void assertEnableHypermediaSupportWorkingCorrectly() { + void assertEnableHypermediaSupportWorkingCorrectly() { assertThat(context.getBean("entityLinksPluginRegistry")).isNotNull(); assertThat(context.getBean(LinkDiscoverers.class)).isNotNull(); } @Test - public void assertBeansBeingSetUp() throws Exception { + void assertBeansBeingSetUp() throws Exception { context.getBean(PageableHandlerMethodArgumentResolver.class); @@ -103,7 +103,7 @@ public class RepositoryRestMvConfigurationIntegrationTests { } @Test // DATAREST-271 - public void assetConsidersPaginationCustomization() { + void assetConsidersPaginationCustomization() { HateoasPageableHandlerMethodArgumentResolver resolver = context .getBean(HateoasPageableHandlerMethodArgumentResolver.class); @@ -121,7 +121,7 @@ public class RepositoryRestMvConfigurationIntegrationTests { } @Test // DATAREST-336 DATAREST-1509 - public void objectMapperRendersDatesInIsoByDefault() throws Exception { + void objectMapperRendersDatesInIsoByDefault() throws Exception { Sample sample = new Sample(); sample.date = new Date(); @@ -135,13 +135,15 @@ public class RepositoryRestMvConfigurationIntegrationTests { .or(suffix("+00:00")), "ISO-8601-TZ1, ISO-8601-TZ2, or ISO-8601-TZ3"); } - @Test(expected = NoSuchBeanDefinitionException.class) // DATAREST-362 - public void doesNotExposePersistentEntityJackson2ModuleAsBean() { - context.getBean(PersistentEntityJackson2Module.class); + @Test // DATAREST-362 + void doesNotExposePersistentEntityJackson2ModuleAsBean() { + + assertThatExceptionOfType(NoSuchBeanDefinitionException.class) // + .isThrownBy(() -> context.getBean(PersistentEntityJackson2Module.class)); } @Test // DATAREST-362 - public void registeredHttpMessageConvertersAreTypeConstrained() { + void registeredHttpMessageConvertersAreTypeConstrained() { Collection converters = context .getBeansOfType(MappingJackson2HttpMessageConverter.class).values(); @@ -153,7 +155,7 @@ public class RepositoryRestMvConfigurationIntegrationTests { } @Test // DATAREST-424 - public void halHttpMethodConverterIsRegisteredBeforeTheGeneralOne() { + void halHttpMethodConverterIsRegisteredBeforeTheGeneralOne() { CollectingComponent component = context.getBean(CollectingComponent.class); List> converters = component.converters; @@ -163,7 +165,7 @@ public class RepositoryRestMvConfigurationIntegrationTests { } @Test // DATAREST-424 - public void halHttpMethodConverterIsRegisteredAfterTheGeneralOneIfHalIsDisabledAsDefaultMediaType() { + void halHttpMethodConverterIsRegisteredAfterTheGeneralOneIfHalIsDisabledAsDefaultMediaType() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NonHalConfiguration.class); CollectingComponent component = context.getBean(CollectingComponent.class); @@ -176,7 +178,7 @@ public class RepositoryRestMvConfigurationIntegrationTests { } @Test // DATAREST-431, DATACMNS-626 - public void hasConvertersForPointAndDistance() { + void hasConvertersForPointAndDistance() { ConversionService service = context.getBean("defaultConversionService", ConversionService.class); @@ -187,7 +189,7 @@ public class RepositoryRestMvConfigurationIntegrationTests { } @Test // DATAREST-1198 - public void hasConvertersForNamAndLdapName() { + void hasConvertersForNamAndLdapName() { ConversionService service = context.getBean("defaultConversionService", ConversionService.class); @@ -197,7 +199,7 @@ public class RepositoryRestMvConfigurationIntegrationTests { @Test // #1995 @SuppressWarnings("unchecked") - public void registersRepositoryRestConfigurersInDeclaredOrder() { + void registersRepositoryRestConfigurersInDeclaredOrder() { RepositoryRestMvcConfiguration configuration = context.getBean(RepositoryRestMvcConfiguration.class); ExtendingConfiguration userConfig = context.getBean(ExtendingConfiguration.class); @@ -278,7 +280,7 @@ public class RepositoryRestMvConfigurationIntegrationTests { List> converters; @Autowired - public void setConverters(List> converters) { + void setConverters(List> converters) { this.converters = converters; } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/ResourceMetadataHandlerMethodArgumentResolverUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/ResourceMetadataHandlerMethodArgumentResolverUnitTests.java index 28e3019a7..be215e94d 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/ResourceMetadataHandlerMethodArgumentResolverUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/ResourceMetadataHandlerMethodArgumentResolverUnitTests.java @@ -18,7 +18,7 @@ package org.springframework.data.rest.webmvc.config; import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; import org.springframework.data.repository.support.Repositories; import org.springframework.data.rest.core.mapping.ResourceMappings; @@ -31,10 +31,10 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; * * @author Oliver Gierke */ -public class ResourceMetadataHandlerMethodArgumentResolverUnitTests { +class ResourceMetadataHandlerMethodArgumentResolverUnitTests { @Test // DATAREST-1250 - public void supportsResourceMetadataParameterType() { + void supportsResourceMetadataParameterType() { HandlerMethodArgumentResolver resolver = new ResourceMetadataHandlerMethodArgumentResolver(mock(Repositories.class), mock(ResourceMappings.class), BaseUri.NONE); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/AggregateReferenceResolvingModuleUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/AggregateReferenceResolvingModuleUnitTests.java index 51c66d390..7147aa938 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/AggregateReferenceResolvingModuleUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/AggregateReferenceResolvingModuleUnitTests.java @@ -36,7 +36,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; * @author Oliver Drotbohm */ @ExtendWith(MockitoExtension.class) -public class AggregateReferenceResolvingModuleUnitTests { +class AggregateReferenceResolvingModuleUnitTests { @Mock UriToEntityConverter uriToEntityConverter; @@ -60,7 +60,7 @@ public class AggregateReferenceResolvingModuleUnitTests { public static class SomeType { - public void setSomeProperty(Other other) {} + void setSomeProperty(Other other) {} } @RestResource diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java index 8e938f566..644c37b56 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java @@ -31,12 +31,12 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.*; -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.ArgumentMatchers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Immutable; @@ -75,16 +75,16 @@ import com.fasterxml.jackson.databind.node.ObjectNode; * @author Ken Dombeck * @author Thomas Mrozinski */ -@RunWith(MockitoJUnitRunner.class) -public class DomainObjectReaderUnitTests { +@ExtendWith(MockitoExtension.class) +class DomainObjectReaderUnitTests { @Mock ResourceMappings mappings; DomainObjectReader reader; PersistentEntities entities; - @Before - public void setUp() { + @BeforeEach + void setUp() { KeyValueMappingContext mappingContext = new KeyValueMappingContext<>(); mappingContext.getPersistentEntity(SampleUser.class); @@ -111,7 +111,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-461 - public void doesNotConsiderIgnoredProperties() throws Exception { + void doesNotConsiderIgnoredProperties() throws Exception { SampleUser user = new SampleUser("firstname", "password"); JsonNode node = new ObjectMapper().readTree("{}"); @@ -123,7 +123,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-556 - public void considersMappedFieldNamesWhenApplyingNodeToDomainObject() throws Exception { + void considersMappedFieldNamesWhenApplyingNodeToDomainObject() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); @@ -137,7 +137,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-605 - public void mergesMapCorrectly() throws Exception { + void mergesMapCorrectly() throws Exception { SampleUser user = new SampleUser("firstname", "password"); user.relatedUsers = Collections.singletonMap("parent", new SampleUser("firstname", "password")); @@ -154,7 +154,7 @@ public class DomainObjectReaderUnitTests { @Test // DATAREST-701 @SuppressWarnings("unchecked") - public void mergesNestedMapWithoutTypeInformation() throws Exception { + void mergesNestedMapWithoutTypeInformation() throws Exception { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree("{\"map\" : {\"a\": \"1\", \"b\": {\"c\": \"2\"}}}"); @@ -172,17 +172,18 @@ public class DomainObjectReaderUnitTests { assertThat(((Map) object).get("c")).isEqualTo("2"); } - @Test(expected = JsonMappingException.class) // DATAREST-701 - public void rejectsMergingUnknownDomainObject() throws Exception { + @Test // DATAREST-701 + void rejectsMergingUnknownDomainObject() throws Exception { ObjectMapper mapper = new ObjectMapper(); ObjectNode node = (ObjectNode) mapper.readTree("{}"); - reader.readPut(node, "", mapper); + assertThatExceptionOfType(JsonMappingException.class) // + .isThrownBy(() -> reader.readPut(node, "", mapper)); } @Test // DATAREST-705 - public void doesNotWipeIdAndVersionPropertyForPut() throws Exception { + void doesNotWipeIdAndVersionPropertyForPut() throws Exception { VersionedType type = new VersionedType(); type.id = 1L; @@ -201,7 +202,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-1006 - public void doesNotWipeReadOnlyJsonPropertyForPut() throws Exception { + void doesNotWipeReadOnlyJsonPropertyForPut() throws Exception { SampleUser sampleUser = new SampleUser("name", "password"); sampleUser.lastLogin = new Date(); @@ -217,7 +218,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-873 - public void doesNotApplyInputToReadOnlyFields() throws Exception { + void doesNotApplyInputToReadOnlyFields() throws Exception { ObjectMapper mapper = new ObjectMapper(); ObjectNode node = (ObjectNode) mapper.readTree("{}"); @@ -231,7 +232,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-931 - public void readsPatchForEntityNestedInCollection() throws Exception { + void readsPatchForEntityNestedInCollection() throws Exception { Phone phone = new Phone(); phone.creationDate = new GregorianCalendar(); @@ -249,7 +250,7 @@ public class DomainObjectReaderUnitTests { @Test // DATAREST-919 @SuppressWarnings("unchecked") - public void readsComplexNestedMapsAndArrays() throws Exception { + void readsComplexNestedMapsAndArrays() throws Exception { Map childMap = new HashMap(); childMap.put("child1", "ok"); @@ -286,7 +287,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-938 - public void nestedEntitiesAreUpdated() throws Exception { + void nestedEntitiesAreUpdated() throws Exception { Inner inner = new Inner(); inner.name = "inner name"; @@ -309,7 +310,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-937 - public void considersTransientProperties() throws Exception { + void considersTransientProperties() throws Exception { SampleWithTransient sample = new SampleWithTransient(); sample.name = "name"; @@ -324,7 +325,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-953 - public void writesArrayForPut() throws Exception { + void writesArrayForPut() throws Exception { Child inner = new Child(); inner.items = new ArrayList(); @@ -341,7 +342,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-956 - public void writesArrayWithAddedItemForPut() throws Exception { + void writesArrayWithAddedItemForPut() throws Exception { Child inner = new Child(); inner.items = new ArrayList(); @@ -362,7 +363,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-956 - public void writesArrayWithRemovedItemForPut() throws Exception { + void writesArrayWithRemovedItemForPut() throws Exception { Child inner = new Child(); inner.items = new ArrayList(); @@ -382,7 +383,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-959 - public void addsElementToPreviouslyEmptyCollection() throws Exception { + void addsElementToPreviouslyEmptyCollection() throws Exception { Parent source = new Parent(); source.inner = new Child(); @@ -398,7 +399,7 @@ public class DomainObjectReaderUnitTests { @Test // DATAREST-959 @SuppressWarnings("unchecked") - public void turnsObjectIntoCollection() throws Exception { + void turnsObjectIntoCollection() throws Exception { Parent source = new Parent(); source.inner = new Child(); @@ -419,7 +420,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-965 - public void writesObjectWithRemovedItemsForPut() throws Exception { + void writesObjectWithRemovedItemsForPut() throws Exception { Child inner = new Child(); inner.items = new ArrayList(); @@ -438,7 +439,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-965 - public void writesArrayWithRemovedObjectForPut() throws Exception { + void writesArrayWithRemovedObjectForPut() throws Exception { Child inner = new Child(); inner.object = "value"; @@ -456,7 +457,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-986 - public void readsComplexMap() throws Exception { + void readsComplexMap() throws Exception { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree( @@ -469,7 +470,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-987 - public void handlesTransientPropertyWithoutFieldProperly() throws Exception { + void handlesTransientPropertyWithoutFieldProperly() throws Exception { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree("{ \"name\" : \"Foo\" }"); @@ -478,7 +479,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-977 - public void readsCollectionOfComplexEnum() throws Exception { + void readsCollectionOfComplexEnum() throws Exception { CollectionOfEnumWithMethods sample = new CollectionOfEnumWithMethods(); sample.enums.add(SampleEnum.FIRST); @@ -493,7 +494,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-944 - public void mergesAssociations() { + void mergesAssociations() { List originalCollection = Arrays.asList(new Nested(2, 3)); SampleWithReference source = new SampleWithReference(Arrays.asList(new Nested(1, 2), new Nested(2, 3))); @@ -506,7 +507,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-944 - public void mergesAssociationsAndKeepsMutableCollection() { + void mergesAssociationsAndKeepsMutableCollection() { ArrayList originalCollection = new ArrayList(Arrays.asList(new Nested(2, 3))); SampleWithReference source = new SampleWithReference( @@ -520,7 +521,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-1030 - public void patchWithReferenceToRelatedEntityIsResolvedCorrectly() throws Exception { + void patchWithReferenceToRelatedEntityIsResolvedCorrectly() throws Exception { Associations associations = mock(Associations.class); PersistentProperty any = ArgumentMatchers.any(PersistentProperty.class); @@ -549,7 +550,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-1249 - public void mergesIntoUninitializedCollection() throws Exception { + void mergesIntoUninitializedCollection() throws Exception { ObjectMapper mapper = new ObjectMapper(); ObjectNode source = (ObjectNode) mapper.readTree("{ \"strings\" : [ \"value\" ] }"); @@ -560,7 +561,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-1383 - public void doesNotWipeReadOnlyPropertyForPatch() throws Exception { + void doesNotWipeReadOnlyPropertyForPatch() throws Exception { SampleUser user = new SampleUser("name", "password"); user.lastLogin = new Date(); @@ -577,7 +578,7 @@ public class DomainObjectReaderUnitTests { } @Test // DATAREST-1068 - public void arraysCanBeResizedDuringMerge() throws Exception { + void arraysCanBeResizedDuringMerge() throws Exception { ObjectMapper mapper = new ObjectMapper(); ArrayHolder target = new ArrayHolder(new String[] {}); JsonNode node = mapper.readTree("{ \"array\" : [ \"new\" ] }"); @@ -724,7 +725,7 @@ public class DomainObjectReaderUnitTests { return null; } - public void setName(String name) {} + void setName(String name) {} } // DATAREST-977 diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/EnumTranslatorUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/EnumTranslatorUnitTests.java index 6d75e95fe..6002245bc 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/EnumTranslatorUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/EnumTranslatorUnitTests.java @@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.*; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.support.StaticMessageSource; import org.springframework.hateoas.mediatype.MessageResolver; @@ -30,13 +30,13 @@ import org.springframework.hateoas.mediatype.MessageResolver; * * @author Oliver Gierke */ -public class EnumTranslatorUnitTests { +class EnumTranslatorUnitTests { StaticMessageSource messageSource; EnumTranslator configuration; - @Before - public void setUp() { + @BeforeEach + void setUp() { LocaleContextHolder.setLocale(Locale.US); @@ -46,28 +46,30 @@ public class EnumTranslatorUnitTests { this.configuration = new EnumTranslator(MessageResolver.of(messageSource)); } - @Test(expected = IllegalArgumentException.class) // DATAREST-654 - public void rejectsNullMessageSourceAccessor() { - new EnumTranslator(null); + @Test // DATAREST-654 + void rejectsNullMessageSourceAccessor() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new EnumTranslator(null)); } @Test // DATAREST-654 - public void parsesNullForNullSource() { + void parsesNullForNullSource() { assertThat(configuration.fromText(MyEnum.class, null)).isNull(); } @Test // DATAREST-654 - public void parsesNullForEmptySource() { + void parsesNullForEmptySource() { assertThat(configuration.fromText(MyEnum.class, null)).isNull(); } @Test // DATAREST-654 - public void parsesNullForUnknownValue() { + void parsesNullForUnknownValue() { assertThat(configuration.fromText(MyEnum.class, "Foobar")).isNull(); } @Test // DATAREST-654 - public void returnsEnumNameIfDefaultTranslationIsDisabled() { + void returnsEnumNameIfDefaultTranslationIsDisabled() { configuration.setEnableDefaultTranslation(false); @@ -75,13 +77,13 @@ public class EnumTranslatorUnitTests { } @Test // DATAREST-654 - public void returnsDefaultTranslationByDefault() { + void returnsDefaultTranslationByDefault() { assertThat(configuration.asText(MyEnum.SECOND_VALUE)).isEqualTo("Second value"); } @Test // DATAREST-654 - public void parsesEnumNameIfDefaultTranslationIsDisabled() { + void parsesEnumNameIfDefaultTranslationIsDisabled() { configuration.setEnableDefaultTranslation(false); @@ -89,14 +91,14 @@ public class EnumTranslatorUnitTests { } @Test // DATAREST-654 - public void parsesStandardTranslationAndEnumNameByDefault() { + void parsesStandardTranslationAndEnumNameByDefault() { assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE")).isEqualTo(MyEnum.FIRST_VALUE); assertThat(configuration.fromText(MyEnum.class, "Second value")).isEqualTo(MyEnum.SECOND_VALUE); } @Test // DATAREST-654 - public void translatesEnumName() { + void translatesEnumName() { LocaleContextHolder.setLocale(Locale.US); @@ -107,7 +109,7 @@ public class EnumTranslatorUnitTests { } @Test // DATAREST-654 - public void parsesEnumNameByDefaultEvenIfMessageDefined() { + void parsesEnumNameByDefaultEvenIfMessageDefined() { // Parses resolved message and enum name assertThat(configuration.fromText(MyEnum.class, "Translated")).isEqualTo(MyEnum.FIRST_VALUE); @@ -122,7 +124,7 @@ public class EnumTranslatorUnitTests { } @Test // DATAREST-654 - public void parsesEnumWithDefaultTranslationDisabled() { + void parsesEnumWithDefaultTranslationDisabled() { configuration.setEnableDefaultTranslation(false); @@ -132,7 +134,7 @@ public class EnumTranslatorUnitTests { } @Test - public void doesNotResolveEnumNameAsFallbackIfConfigured() { + void doesNotResolveEnumNameAsFallbackIfConfigured() { configuration.setParseEnumNameAsFallback(false); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonMetadataUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonMetadataUnitTests.java index ce90503df..785161092 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonMetadataUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonMetadataUnitTests.java @@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.*; import java.io.IOException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; @@ -42,13 +42,13 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer; * @author Oliver Gierke * @soundtrack Four Sided Cube - Bad Day's Remembrance (Bunch of Sides) */ -public class JacksonMetadataUnitTests { +class JacksonMetadataUnitTests { MappingContext context; ObjectMapper mapper; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.context = new KeyValueMappingContext<>(); @@ -57,7 +57,7 @@ public class JacksonMetadataUnitTests { } @Test // DATAREST-644 - public void detectsReadOnlyProperty() { + void detectsReadOnlyProperty() { JacksonMetadata metadata = new JacksonMetadata(mapper, User.class); @@ -69,7 +69,7 @@ public class JacksonMetadataUnitTests { } @Test // DATAREST-644 - public void reportsConstructorArgumentAsJacksonWritable() { + void reportsConstructorArgumentAsJacksonWritable() { JacksonMetadata metadata = new JacksonMetadata(mapper, Value.class); @@ -80,7 +80,7 @@ public class JacksonMetadataUnitTests { } @Test // DATAREST-644 - public void detectsCustomSerializerFortType() { + void detectsCustomSerializerFortType() { JsonSerializer serializer = new JacksonMetadata(new ObjectMapper(), SomeBean.class) .getTypeSerializer(SomeBean.class); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonSerializersUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonSerializersUnitTests.java index 32b9f3ddc..a2e5de267 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonSerializersUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonSerializersUnitTests.java @@ -21,9 +21,8 @@ import static org.mockito.Mockito.*; import java.util.Collection; import java.util.Map; -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.webmvc.json.JacksonSerializersUnitTests.Sample.SampleEnum; import com.fasterxml.jackson.databind.ObjectMapper; @@ -34,12 +33,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; * @author Oliver Gierke * @soundtrack James Bay - Move Together (Chaos And The Calm) */ -public class JacksonSerializersUnitTests { +class JacksonSerializersUnitTests { ObjectMapper mapper; - @Before - public void setUp() { + @BeforeEach + void setUp() { EnumTranslator translator = mock(EnumTranslator.class); doReturn(SampleEnum.VALUE).when(translator).fromText(SampleEnum.class, "value"); @@ -49,7 +48,7 @@ public class JacksonSerializersUnitTests { } @Test // DATAREST-929 - public void translatesPlainEnumCorrectly() throws Exception { + void translatesPlainEnumCorrectly() throws Exception { Sample result = mapper.readValue("{ \"property\" : \"value\"}", Sample.class); @@ -57,7 +56,7 @@ public class JacksonSerializersUnitTests { } @Test // DATAREST-929 - public void translatesCollectionOfEnumsCorrectly() throws Exception { + void translatesCollectionOfEnumsCorrectly() throws Exception { Sample result = mapper.readValue("{ \"collection\" : [ \"value\" ] }", Sample.class); @@ -65,7 +64,7 @@ public class JacksonSerializersUnitTests { } @Test // DATAREST-929 - public void translatesEnumArraysCorrectly() throws Exception { + void translatesEnumArraysCorrectly() throws Exception { Sample result = mapper.readValue("{ \"array\" : [ \"value\" ] }", Sample.class); @@ -73,7 +72,7 @@ public class JacksonSerializersUnitTests { } @Test // DATAREST-929 - public void translatesMapEnumValueCorrectly() throws Exception { + void translatesMapEnumValueCorrectly() throws Exception { Sample result = mapper.readValue("{ \"mapToEnum\" : { \"foo\" : \"value\" } }", Sample.class); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java index e4023f707..03d4f1a4d 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java @@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc.json; import static org.assertj.core.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.rest.webmvc.json.JsonSchema.JsonSchemaProperty; 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 JsonSchemaUnitTests { +class JsonSchemaUnitTests { static final TypeInformation type = ClassTypeInformation.from(Sample.class); @Test // DATAREST-492 - public void considersNumberPrimitivesJsonSchemaNumbers() { + void considersNumberPrimitivesJsonSchemaNumbers() { JsonSchemaProperty property = new JsonSchemaProperty("foo", null, "bar", false); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappedPropertiesUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappedPropertiesUnitTests.java index ed24ff4ab..e3c7c7c34 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappedPropertiesUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappedPropertiesUnitTests.java @@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc.json; import static org.assertj.core.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.annotation.ReadOnlyProperty; import org.springframework.data.annotation.Transient; import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; @@ -34,7 +34,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; * * @author Oliver Gierke */ -public class MappedPropertiesUnitTests { +class MappedPropertiesUnitTests { ObjectMapper mapper = new ObjectMapper(); KeyValueMappingContext context = new KeyValueMappingContext<>(); @@ -42,28 +42,28 @@ public class MappedPropertiesUnitTests { MappedProperties properties = MappedProperties.forDeserialization(entity, mapper); @Test // DATAREST-575 - public void doesNotExposeMappedPropertyForNonSpringDataPersistentProperty() { + void doesNotExposeMappedPropertyForNonSpringDataPersistentProperty() { assertThat(properties.hasPersistentPropertyForField("notExposedBySpringData")).isFalse(); assertThat(properties.getPersistentProperty("notExposedBySpringData")).isNull(); } @Test // DATAREST-575 - public void doesNotExposeMappedPropertyForNonJacksonProperty() { + void doesNotExposeMappedPropertyForNonJacksonProperty() { assertThat(properties.hasPersistentPropertyForField("notExposedByJackson")).isFalse(); assertThat(properties.getPersistentProperty("notExposedByJackson")).isNull(); } @Test // DATAREST-575 - public void exposesProperty() { + void exposesProperty() { assertThat(properties.hasPersistentPropertyForField("exposedProperty")).isTrue(); assertThat(properties.getPersistentProperty("exposedProperty")).isNotNull(); } @Test // DATAREST-575 - public void exposesRenamedPropertyByExternalName() { + void exposesRenamedPropertyByExternalName() { assertThat(properties.hasPersistentPropertyForField("email")).isTrue(); assertThat(properties.getPersistentProperty("email")).isNotNull(); @@ -71,14 +71,14 @@ public class MappedPropertiesUnitTests { } @Test // DATAREST-1006 - public void doesNotExposeIgnoredPropertyViaJsonProperty() { + void doesNotExposeIgnoredPropertyViaJsonProperty() { assertThat(properties.hasPersistentPropertyForField("readOnlyProperty")).isFalse(); assertThat(properties.getPersistentProperty("readOnlyProperty")).isNull(); } @Test // DATAREST-1248 - public void doesNotExcludeReadOnlyPropertiesForSerialization() { + void doesNotExcludeReadOnlyPropertiesForSerialization() { MappedProperties properties = MappedProperties.forSerialization(entity, mapper); @@ -87,7 +87,7 @@ public class MappedPropertiesUnitTests { } @Test // DATAREST-1383 - public void doesNotRegardReadOnlyPropertyForDeserialization() { + void doesNotRegardReadOnlyPropertyForDeserialization() { MappedProperties properties = MappedProperties.forDeserialization(entity, mapper); @@ -101,7 +101,7 @@ public class MappedPropertiesUnitTests { } @Test // DATAREST-1440 - public void exposesExistanceOfCatchAllMethod() { + void exposesExistanceOfCatchAllMethod() { PersistentEntity entity = context.getRequiredPersistentEntity(SampleWithJsonAnySetter.class); @@ -132,6 +132,6 @@ public class MappedPropertiesUnitTests { public @ReadOnlyProperty String anotherReadOnlyProperty; @JsonAnySetter - public void set(String key, String value) {} + void set(String key, String value) {} } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappingAwarePageableArgumentResolverUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappingAwarePageableArgumentResolverUnitTests.java index cdfca48b1..c1b50dfc9 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappingAwarePageableArgumentResolverUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappingAwarePageableArgumentResolverUnitTests.java @@ -18,11 +18,11 @@ package org.springframework.data.rest.webmvc.json; 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.springframework.core.MethodParameter; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -39,8 +39,8 @@ import org.springframework.web.method.support.ModelAndViewContainer; * @author Mark Paluch * @author Oliver Drotbohm */ -@RunWith(MockitoJUnitRunner.class) -public class MappingAwarePageableArgumentResolverUnitTests { +@ExtendWith(MockitoExtension.class) +class MappingAwarePageableArgumentResolverUnitTests { @Mock JacksonMappingAwareSortTranslator translator; @Mock PageableHandlerMethodArgumentResolver delegate; @@ -51,13 +51,13 @@ public class MappingAwarePageableArgumentResolverUnitTests { MappingAwarePageableArgumentResolver resolver; - @Before - public void setUp() { + @BeforeEach + void setUp() { resolver = new MappingAwarePageableArgumentResolver(translator, delegate); } @Test // DATAREST-906 - public void resolveArgumentShouldReturnTranslatedPageable() throws Exception { + void resolveArgumentShouldReturnTranslatedPageable() throws Exception { Sort translated = Sort.by("world"); Pageable pageable = PageRequest.of(0, 1, Direction.ASC, "hello"); @@ -73,7 +73,7 @@ public class MappingAwarePageableArgumentResolverUnitTests { } @Test // DATAREST-906 - public void resolveArgumentShouldReturnPageableWithoutSort() throws Exception { + void resolveArgumentShouldReturnPageableWithoutSort() throws Exception { Pageable pageable = PageRequest.of(0, 1); @@ -87,7 +87,7 @@ public class MappingAwarePageableArgumentResolverUnitTests { } @Test // DATAREST-906 - public void resolveArgumentShouldReturnUnpagedPageable() throws Exception { + void resolveArgumentShouldReturnUnpagedPageable() throws Exception { when(delegate.resolveArgument(parameter, modelAndViewContainer, webRequest, binderFactory)) .thenReturn(Pageable.unpaged()); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2ModuleUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2ModuleUnitTests.java index d5d5af6a5..73e1ae188 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2ModuleUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2ModuleUnitTests.java @@ -28,11 +28,13 @@ import java.util.Arrays; import java.util.Collections; 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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.springframework.core.convert.TypeDescriptor; import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; import org.springframework.data.mapping.PersistentProperty; @@ -70,8 +72,9 @@ import com.jayway.jsonpath.JsonPath; * @author Oliver Gierke * @author Valentin Rentschler */ -@RunWith(MockitoJUnitRunner.class) -public class PersistentEntityJackson2ModuleUnitTests { +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +class PersistentEntityJackson2ModuleUnitTests { @Mock Associations associations; @Mock UriToEntityConverter converter; @@ -83,8 +86,8 @@ public class PersistentEntityJackson2ModuleUnitTests { PersistentEntities persistentEntities; ObjectMapper mapper; - @Before - public void setUp() { + @BeforeEach + void setUp() { KeyValueMappingContext mappingContext = new KeyValueMappingContext<>(); mappingContext.getPersistentEntity(Sample.class); @@ -111,7 +114,7 @@ public class PersistentEntityJackson2ModuleUnitTests { } @Test // DATAREST-328, DATAREST-320 - public void doesNotDropPropertiesWithCustomizedNames() throws Exception { + void doesNotDropPropertiesWithCustomizedNames() throws Exception { Sample sample = new Sample(); sample.name = "bar"; @@ -122,7 +125,7 @@ public class PersistentEntityJackson2ModuleUnitTests { } @Test // DATAREST-340 - public void rendersAdditionalJsonPropertiesNotBackedByAPersistentField() throws Exception { + void rendersAdditionalJsonPropertiesNotBackedByAPersistentField() throws Exception { SampleWithAdditionalGetters sample = new SampleWithAdditionalGetters(); @@ -132,7 +135,7 @@ public class PersistentEntityJackson2ModuleUnitTests { } @Test // DATAREST-662 - public void resolvesReferenceToSubtypeCorrectly() throws IOException { + void resolvesReferenceToSubtypeCorrectly() throws IOException { PersistentProperty property = persistentEntities.getRequiredPersistentEntity(PetOwner.class) .getRequiredPersistentProperty("pet"); @@ -148,7 +151,7 @@ public class PersistentEntityJackson2ModuleUnitTests { } @Test // DATAREST-1321 - public void allowsNumericIdsForLookupTypes() throws Exception { + void allowsNumericIdsForLookupTypes() throws Exception { RepositoryInvoker invoker = mock(RepositoryInvoker.class); when(invoker.invokeFindById(any(Long.class))).thenReturn(Optional.of(new Home())); @@ -167,7 +170,7 @@ public class PersistentEntityJackson2ModuleUnitTests { } @Test // DATAREST-1321 - public void serializesNonStringLookupValues() throws Exception { + void serializesNonStringLookupValues() throws Exception { // Given Pet defined as lookup type PersistentProperty property = persistentEntities.getRequiredPersistentEntity(PetOwner.class) @@ -186,7 +189,7 @@ public class PersistentEntityJackson2ModuleUnitTests { } @Test // DATAREST-1393 - public void customizesDeserializerForCreatorProperties() throws Exception { + void customizesDeserializerForCreatorProperties() throws Exception { PersistentProperty property = persistentEntities // .getRequiredPersistentEntity(Immutable.class) // @@ -201,7 +204,7 @@ public class PersistentEntityJackson2ModuleUnitTests { } @Test // GH-1926 - public void doesNotWrapJsonValueTypesIntoEntityModel() throws Exception { + void doesNotWrapJsonValueTypesIntoEntityModel() throws Exception { Wrapper wrapper = new Wrapper(); wrapper.value = new ValueType(); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/ProjectionJacksonIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/ProjectionJacksonIntegrationTests.java index a2a2629e4..3666926d1 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/ProjectionJacksonIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/ProjectionJacksonIntegrationTests.java @@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.*; import java.util.Arrays; 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.projection.ProjectionFactory; import org.springframework.data.projection.SpelAwareProxyProjectionFactory; import org.springframework.hateoas.CollectionModel; @@ -40,13 +40,13 @@ import com.jayway.jsonpath.JsonPath; * * @author Oliver Gierke */ -public class ProjectionJacksonIntegrationTests { +class ProjectionJacksonIntegrationTests { ObjectMapper mapper; ProjectionFactory factory = new SpelAwareProxyProjectionFactory(); - @Before - public void setUp() { + @BeforeEach + void setUp() { this.mapper = new ObjectMapper(); this.mapper.registerModule(new Jackson2HalModule()); @@ -55,7 +55,7 @@ public class ProjectionJacksonIntegrationTests { } @Test // DATAREST-221 - public void considersJacksonAnnotationsOnProjectionInterfaces() throws Exception { + void considersJacksonAnnotationsOnProjectionInterfaces() throws Exception { Customer customer = new Customer(); customer.firstname = "Dave"; @@ -69,7 +69,7 @@ public class ProjectionJacksonIntegrationTests { } @Test // DATAREST-221 - public void rendersHalContentCorrectly() throws Exception { + void rendersHalContentCorrectly() throws Exception { Customer customer = new Customer(); customer.firstname = "Dave"; diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java index 67b9ac76a..6fe866573 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java @@ -21,8 +21,8 @@ import static org.mockito.Mockito.*; 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.data.annotation.Reference; import org.springframework.data.domain.Sort; import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; @@ -45,15 +45,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; * @author Oliver Gierke * @soundtrack dkn - Out Of This World (original version) */ -public class SortTranslatorUnitTests { +class SortTranslatorUnitTests { ObjectMapper objectMapper = new ObjectMapper(); KeyValueMappingContext mappingContext; PersistentEntities persistentEntities; SortTranslator sortTranslator; - @Before - public void setUp() { + @BeforeEach + void setUp() { mappingContext = new KeyValueMappingContext<>(); mappingContext.getPersistentEntity(Plain.class); @@ -68,7 +68,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-883 - public void shouldMapKnownProperties() { + void shouldMapKnownProperties() { Sort translatedSort = sortTranslator.translateSort(Sort.by("hello", "name"), mappingContext.getRequiredPersistentEntity(Plain.class)); @@ -78,7 +78,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-883 - public void returnsNullSortIfNoPropertiesMatch() { + void returnsNullSortIfNoPropertiesMatch() { Sort translatedSort = sortTranslator.translateSort(Sort.by("hello", "world"), mappingContext.getRequiredPersistentEntity(Plain.class)); @@ -87,7 +87,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-883 - public void shouldMapKnownPropertiesWithJsonProperty() { + void shouldMapKnownPropertiesWithJsonProperty() { Sort translatedSort = sortTranslator.translateSort(Sort.by("hello", "foo"), mappingContext.getRequiredPersistentEntity(WithJsonProperty.class)); @@ -97,7 +97,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-883 - public void shouldJacksonFieldNameForMapping() { + void shouldJacksonFieldNameForMapping() { Sort translatedSort = sortTranslator.translateSort(Sort.by("name"), mappingContext.getRequiredPersistentEntity(WithJsonProperty.class)); @@ -106,7 +106,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-910 - public void shouldMapKnownNestedProperties() { + void shouldMapKnownNestedProperties() { Sort translatedSort = sortTranslator.translateSort( Sort.by("embedded.name", "embedded.collection", "embedded.someInterface"), @@ -118,7 +118,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-910 - public void shouldSkipWrongNestedProperties() { + void shouldSkipWrongNestedProperties() { Sort translatedSort = sortTranslator.translateSort(Sort.by("embedded.unknown"), mappingContext.getRequiredPersistentEntity(Plain.class)); @@ -127,7 +127,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-910, DATAREST-976 - public void shouldSkipKnownAssociationProperties() { + void shouldSkipKnownAssociationProperties() { Sort translatedSort = sortTranslator.translateSort(Sort.by("association.name"), mappingContext.getRequiredPersistentEntity(Plain.class)); @@ -136,7 +136,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-976 - public void shouldMapEmbeddableAssociationProperties() { + void shouldMapEmbeddableAssociationProperties() { Sort translatedSort = sortTranslator.translateSort(Sort.by("refEmbedded.name"), mappingContext.getRequiredPersistentEntity(Plain.class)); @@ -145,7 +145,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-910 - public void shouldJacksonFieldNameForNestedFieldMapping() { + void shouldJacksonFieldNameForNestedFieldMapping() { Sort translatedSort = sortTranslator.translateSort(Sort.by("em.foo"), mappingContext.getRequiredPersistentEntity(WithJsonProperty.class)); @@ -154,7 +154,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-910 - public void shouldTranslatePathForSingleLevelJsonUnwrappedObject() { + void shouldTranslatePathForSingleLevelJsonUnwrappedObject() { Sort translatedSort = sortTranslator.translateSort(Sort.by("un-name"), mappingContext.getRequiredPersistentEntity(UnwrapEmbedded.class)); @@ -163,7 +163,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-910 - public void shouldTranslatePathForMultiLevelLevelJsonUnwrappedObject() { + void shouldTranslatePathForMultiLevelLevelJsonUnwrappedObject() { Sort translatedSort = sortTranslator.translateSort(Sort.by("un-name", "burrito.un-name"), mappingContext.getRequiredPersistentEntity(MultiUnwrapped.class)); @@ -173,7 +173,7 @@ public class SortTranslatorUnitTests { } @Test // DATAREST-1248 - public void allowsSortingByReadOnlyProperty() { + void allowsSortingByReadOnlyProperty() { Sort sort = sortTranslator.translateSort(Sort.by("readOnly"), mappingContext.getRequiredPersistentEntity(Plain.class)); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/UriStringDeserializerUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/UriStringDeserializerUnitTests.java index bcd8fc23b..cbbea2ced 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/UriStringDeserializerUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/UriStringDeserializerUnitTests.java @@ -21,14 +21,12 @@ import static org.mockito.Mockito.*; import java.net.URI; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -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.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.convert.TypeDescriptor; import org.springframework.data.rest.core.UriToEntityConverter; import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.UriStringDeserializer; @@ -44,10 +42,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; * * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class UriStringDeserializerUnitTests { - - public @Rule ExpectedException exception = ExpectedException.none(); +@ExtendWith(MockitoExtension.class) +class UriStringDeserializerUnitTests { @Mock UriToEntityConverter converter; @@ -56,8 +52,8 @@ public class UriStringDeserializerUnitTests { UriStringDeserializer deserializer; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.deserializer = new UriStringDeserializer(Object.class, converter); @@ -67,29 +63,28 @@ public class UriStringDeserializerUnitTests { } @Test // DATAREST-316 - public void extractsUriToForwardToConverter() throws Exception { + void extractsUriToForwardToConverter() throws Exception { assertConverterInvokedWithUri("/foo/32", URI.create("/foo/32")); } @Test // DATAREST-316 - public void extractsUriFromTemplateToForwardToConverter() throws Exception { + void extractsUriFromTemplateToForwardToConverter() throws Exception { assertConverterInvokedWithUri("/foo/32{?projection}", URI.create("/foo/32")); } @Test // DATAREST-377 - public void returnsNullUriIfSourceIsEmptyOrNull() throws Exception { + void returnsNullUriIfSourceIsEmptyOrNull() throws Exception { assertThat(invokeConverterWith("")).isNull(); assertThat(invokeConverterWith(null)).isNull(); } @Test // DATAREST-377 - public void rejectsNonUriValue() throws Exception { + void rejectsNonUriValue() throws Exception { - exception.expect(JsonMappingException.class); - exception.expectMessage("managed domain type"); - - invokeConverterWith("{ \"foo\" : \"bar\" }"); + assertThatExceptionOfType(JsonMappingException.class) // + .isThrownBy(() -> invokeConverterWith("{ \"foo\" : \"bar\" }")) + .withMessageContaining("managed domain type"); } private Object invokeConverterWith(String source) throws Exception { diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/WrappedPropertiesUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/WrappedPropertiesUnitTests.java index 6ae36fb7f..b88be8e32 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/WrappedPropertiesUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/WrappedPropertiesUnitTests.java @@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.*; 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.data.keyvalue.core.mapping.context.KeyValueMappingContext; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; @@ -39,15 +39,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; * * @author Mark Paluch */ -public class WrappedPropertiesUnitTests { +class WrappedPropertiesUnitTests { static final ObjectMapper MAPPER = new ObjectMapper(); KeyValueMappingContext mappingContext; PersistentEntities persistentEntities; - @Before - public void setUp() { + @BeforeEach + void setUp() { mappingContext = new KeyValueMappingContext<>(); mappingContext.getPersistentEntity(MultiLevelNesting.class); @@ -57,7 +57,7 @@ public class WrappedPropertiesUnitTests { } @Test // DATAREST-910 - public void wrappedPropertiesShouldConsiderSingleLevelUnwrapping() { + void wrappedPropertiesShouldConsiderSingleLevelUnwrapping() { PersistentEntity persistentEntity = persistentEntities.getRequiredPersistentEntity(OneLevelNesting.class); WrappedProperties wrappedProperties = WrappedProperties.fromJacksonProperties(persistentEntities, persistentEntity, @@ -76,7 +76,7 @@ public class WrappedPropertiesUnitTests { } @Test // DATAREST-910 - public void wrappedPropertiesShouldConsiderMultiLevelUnwrapping() { + void wrappedPropertiesShouldConsiderMultiLevelUnwrapping() { PersistentEntity persistentEntity = persistentEntities.getRequiredPersistentEntity(MultiLevelNesting.class); WrappedProperties wrappedProperties = WrappedProperties.fromJacksonProperties(persistentEntities, persistentEntity, @@ -98,7 +98,7 @@ public class WrappedPropertiesUnitTests { } @Test // DATAREST-910 - public void wrappedPropertiesShouldConsiderJacksonFieldNames() { + void wrappedPropertiesShouldConsiderJacksonFieldNames() { PersistentEntity persistentEntity = persistentEntities.getRequiredPersistentEntity(MultiLevelNesting.class); WrappedProperties wrappedProperties = WrappedProperties.fromJacksonProperties(persistentEntities, persistentEntity, @@ -108,7 +108,7 @@ public class WrappedPropertiesUnitTests { } @Test // DATAREST-910 - public void wrappedPropertiesShouldIgnoreIgnoredJacksonFields() { + void wrappedPropertiesShouldIgnoreIgnoredJacksonFields() { PersistentEntity persistentEntity = persistentEntities.getRequiredPersistentEntity(MultiLevelNesting.class); WrappedProperties wrappedProperties = WrappedProperties.fromJacksonProperties(persistentEntities, persistentEntity, @@ -118,7 +118,7 @@ public class WrappedPropertiesUnitTests { } @Test // DATAREST-910 - public void wrappedPropertiesShouldIgnoreSyntheticProperties() { + void wrappedPropertiesShouldIgnoreSyntheticProperties() { PersistentEntity persistentEntity = persistentEntities.getRequiredPersistentEntity(SyntheticProperties.class); WrappedProperties wrappedProperties = WrappedProperties.fromJacksonProperties(persistentEntities, persistentEntity, diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/AddOperationUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/AddOperationUnitTests.java index 7d93a0a10..736ee3fb3 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/AddOperationUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/AddOperationUnitTests.java @@ -16,8 +16,6 @@ package org.springframework.data.rest.webmvc.json.patch; import static org.assertj.core.api.Assertions.*; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; import lombok.AllArgsConstructor; import lombok.Data; @@ -26,15 +24,15 @@ import lombok.NoArgsConstructor; import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -public class AddOperationUnitTests { +class AddOperationUnitTests { @Test - public void addBooleanPropertyValue() throws Exception { + void addBooleanPropertyValue() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -44,11 +42,11 @@ public class AddOperationUnitTests { AddOperation add = AddOperation.of("/1/complete", true); add.perform(todos, Todo.class); - assertTrue(todos.get(1).isComplete()); + assertThat(todos.get(1).isComplete()).isTrue(); } @Test - public void addStringPropertyValue() throws Exception { + void addStringPropertyValue() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -58,11 +56,11 @@ public class AddOperationUnitTests { AddOperation add = AddOperation.of("/1/description", "BBB"); add.perform(todos, Todo.class); - assertEquals("BBB", todos.get(1).getDescription()); + assertThat(todos.get(1).getDescription()).isEqualTo("BBB"); } @Test - public void addItemToList() throws Exception { + void addItemToList() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -72,19 +70,19 @@ public class AddOperationUnitTests { AddOperation add = AddOperation.of("/1", new Todo(null, "D", true)); add.perform(todos, Todo.class); - assertEquals(4, todos.size()); - assertEquals("A", todos.get(0).getDescription()); - assertFalse(todos.get(0).isComplete()); - assertEquals("D", todos.get(1).getDescription()); - assertTrue(todos.get(1).isComplete()); - assertEquals("B", todos.get(2).getDescription()); - assertFalse(todos.get(2).isComplete()); - assertEquals("C", todos.get(3).getDescription()); - assertFalse(todos.get(3).isComplete()); + assertThat(todos.size()).isEqualTo(4); + assertThat(todos.get(0).getDescription()).isEqualTo("A"); + assertThat(todos.get(0).isComplete()).isFalse(); + assertThat(todos.get(1).getDescription()).isEqualTo("D"); + assertThat(todos.get(1).isComplete()).isTrue(); + assertThat(todos.get(2).getDescription()).isEqualTo("B"); + assertThat(todos.get(2).isComplete()).isFalse(); + assertThat(todos.get(3).getDescription()).isEqualTo("C"); + assertThat(todos.get(3).isComplete()).isFalse(); } @Test // DATAREST-995 - public void addsItemsToNestedList() { + void addsItemsToNestedList() { Todo todo = new Todo(1L, "description", false); @@ -94,7 +92,7 @@ public class AddOperationUnitTests { } @Test // DATAREST-1039 - public void addsLazilyEvaluatedObjectToList() throws Exception { + void addsLazilyEvaluatedObjectToList() throws Exception { Todo todo = new Todo(1L, "description", false); @@ -108,7 +106,7 @@ public class AddOperationUnitTests { } @Test // DATAREST-1039 - public void initializesNullCollectionsOnAppend() { + void initializesNullCollectionsOnAppend() { Todo todo = new Todo(1L, "description", false); @@ -118,7 +116,7 @@ public class AddOperationUnitTests { } @Test // DATAREST-1273 - public void addsItemToTheEndOfACollectionViaIndex() { + void addsItemToTheEndOfACollectionViaIndex() { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -130,7 +128,7 @@ public class AddOperationUnitTests { } @Test // DATAREST-1273 - public void rejectsAdditionBeyondEndOfList() { + void rejectsAdditionBeyondEndOfList() { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -143,7 +141,7 @@ public class AddOperationUnitTests { } @Test // DATAREST-1479 - public void manipulatesNestedCollectionProperly() { + void manipulatesNestedCollectionProperly() { List todos = new ArrayList<>(); todos.add(new Todo(1L, "A", false)); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/CopyOperationUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/CopyOperationUnitTests.java index 255a90c0b..00e8baa3f 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/CopyOperationUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/CopyOperationUnitTests.java @@ -15,17 +15,17 @@ */ package org.springframework.data.rest.webmvc.json.patch; -import static org.junit.Assert.*; +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; -public class CopyOperationUnitTests { +class CopyOperationUnitTests { @Test - public void copyBooleanPropertyValue() throws Exception { + void copyBooleanPropertyValue() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -35,11 +35,11 @@ public class CopyOperationUnitTests { CopyOperation copy = CopyOperation.from("/0/complete").to("/1/complete"); copy.perform(todos, Todo.class); - assertTrue(todos.get(1).isComplete()); + assertThat(todos.get(1).isComplete()).isTrue(); } @Test - public void copyStringPropertyValue() throws Exception { + void copyStringPropertyValue() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -49,11 +49,11 @@ public class CopyOperationUnitTests { CopyOperation copy = CopyOperation.from("/0/description").to("/1/description"); copy.perform(todos, Todo.class); - assertEquals("A", todos.get(1).getDescription()); + assertThat(todos.get(1).getDescription()).isEqualTo("A"); } @Test - public void copyBooleanPropertyValueIntoStringProperty() throws Exception { + void copyBooleanPropertyValueIntoStringProperty() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -63,11 +63,11 @@ public class CopyOperationUnitTests { CopyOperation copy = CopyOperation.from("/0/complete").to("/1/description"); copy.perform(todos, Todo.class); - assertEquals("true", todos.get(1).getDescription()); + assertThat(todos.get(1).getDescription()).isEqualTo("true"); } @Test - public void copyListElementToBeginningOfList() throws Exception { + void copyListElementToBeginningOfList() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -77,15 +77,16 @@ public class CopyOperationUnitTests { CopyOperation copy = CopyOperation.from("/1").to("/0"); copy.perform(todos, Todo.class); - assertEquals(4, todos.size()); - assertEquals(2L, todos.get(0).getId().longValue()); // NOTE: This could be problematic if you try to save it to a DB - // because there'll be duplicate IDs - assertEquals("B", todos.get(0).getDescription()); - assertTrue(todos.get(0).isComplete()); + assertThat(todos.size()).isEqualTo(4); + assertThat(todos.get(0).getId().longValue()).isEqualTo(2L); // NOTE: This could be problematic if you try to save it + // to a DB + // because there'll be duplicate IDs + assertThat(todos.get(0).getDescription()).isEqualTo("B"); + assertThat(todos.get(0).isComplete()).isTrue(); } @Test - public void copyListElementToMiddleOfList() throws Exception { + void copyListElementToMiddleOfList() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -95,15 +96,16 @@ public class CopyOperationUnitTests { CopyOperation copy = CopyOperation.from("/0").to("/2"); copy.perform(todos, Todo.class); - assertEquals(4, todos.size()); - assertEquals(1L, todos.get(2).getId().longValue()); // NOTE: This could be problematic if you try to save it to a DB - // because there'll be duplicate IDs - assertEquals("A", todos.get(2).getDescription()); - assertTrue(todos.get(2).isComplete()); + assertThat(todos.size()).isEqualTo(4); + assertThat(todos.get(2).getId().longValue()).isEqualTo(1L); // NOTE: This could be problematic if you try to save it + // to a DB + // because there'll be duplicate IDs + assertThat(todos.get(2).getDescription()).isEqualTo("A"); + assertThat(todos.get(2).isComplete()).isTrue(); } @Test - public void copyListElementToEndOfList_usingIndex() throws Exception { + void copyListElementToEndOfList_usingIndex() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -113,15 +115,16 @@ public class CopyOperationUnitTests { CopyOperation copy = CopyOperation.from("/0").to("/3"); copy.perform(todos, Todo.class); - assertEquals(4, todos.size()); - assertEquals(1L, todos.get(3).getId().longValue()); // NOTE: This could be problematic if you try to save it to a DB - // because there'll be duplicate IDs - assertEquals("A", todos.get(3).getDescription()); - assertTrue(todos.get(3).isComplete()); + assertThat(todos.size()).isEqualTo(4); + assertThat(todos.get(3).getId().longValue()).isEqualTo(1L); // NOTE: This could be problematic if you try to save it + // to a DB + // because there'll be duplicate IDs + assertThat(todos.get(3).getDescription()).isEqualTo("A"); + assertThat(todos.get(3).isComplete()).isTrue(); } @Test - public void copyListElementToEndOfList_usingDash() throws Exception { + void copyListElementToEndOfList_usingDash() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -131,13 +134,13 @@ public class CopyOperationUnitTests { CopyOperation copy = CopyOperation.from("/0").to("/-"); copy.perform(todos, Todo.class); - assertEquals(4, todos.size()); - assertEquals(new Todo(1L, "A", true), todos.get(3)); // NOTE: This could be problematic if you try to save it to a - // DB because there'll be duplicate IDs + assertThat(todos.size()).isEqualTo(4); + assertThat(todos.get(3)).isEqualTo(new Todo(1L, "A", true)); // NOTE: This could be problematic if you try to save + // it to a DB because there'll be duplicate IDs } @Test - public void copyListElementFromEndOfList_usingDash() throws Exception { + void copyListElementFromEndOfList_usingDash() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -147,8 +150,8 @@ public class CopyOperationUnitTests { CopyOperation copy = CopyOperation.from("/-").to("/0"); copy.perform(todos, Todo.class); - assertEquals(4, todos.size()); - assertEquals(new Todo(3L, "C", false), todos.get(0)); // NOTE: This could be problematic if you try to save it to a - // DB because there'll be duplicate IDs + assertThat(todos.size()).isEqualTo(4); + assertThat(todos.get(0)).isEqualTo(new Todo(3L, "C", false)); // NOTE: This could be problematic if you try to save + // it to a DB because there'll be duplicate IDs } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/JsonPatchUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/JsonPatchUnitTests.java index 2e7a17f19..efdf98e5b 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/JsonPatchUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/JsonPatchUnitTests.java @@ -16,18 +16,13 @@ package org.springframework.data.rest.webmvc.json.patch; import static org.assertj.core.api.Assertions.*; -import static org.junit.Assert.*; -import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; import com.fasterxml.jackson.core.JsonParseException; @@ -43,12 +38,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; * @author Mathias Düsterhöft * @author Oliver Trosien */ -public class JsonPatchUnitTests { - - public @Rule ExpectedException exception = ExpectedException.none(); +class JsonPatchUnitTests { @Test - public void manySuccessfulOperations() throws Exception { + void manySuccessfulOperations() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -59,18 +52,18 @@ public class JsonPatchUnitTests { todos.add(new Todo(6L, "F", false)); Patch patch = readJsonPatch("patch-many-successful-operations.json"); - assertEquals(6, patch.size()); + assertThat(patch.size()).isEqualTo(6); List patchedTodos = patch.apply(todos, Todo.class); - assertEquals(6, todos.size()); - assertTrue(patchedTodos.get(1).isComplete()); - assertEquals("C", patchedTodos.get(3).getDescription()); - assertEquals("A", patchedTodos.get(4).getDescription()); + assertThat(todos.size()).isEqualTo(6); + assertThat(patchedTodos.get(1).isComplete()).isTrue(); + assertThat(patchedTodos.get(3).getDescription()).isEqualTo("C"); + assertThat(patchedTodos.get(4).getDescription()).isEqualTo("A"); } @Test - public void failureAtBeginning() throws Exception { + void failureAtBeginning() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -82,22 +75,19 @@ public class JsonPatchUnitTests { Patch patch = readJsonPatch("patch-failing-operation-first.json"); - try { - patch.apply(todos, Todo.class); - fail(); - } catch (PatchException e) { - assertEquals("Test against path '/5/description' failed.", e.getMessage()); - } + assertThatExceptionOfType(PatchException.class) + .isThrownBy(() -> patch.apply(todos, Todo.class)) + .withMessage("Test against path '/5/description' failed."); - assertEquals(6, todos.size()); - assertFalse(todos.get(1).isComplete()); - assertEquals("D", todos.get(3).getDescription()); - assertEquals("E", todos.get(4).getDescription()); - assertEquals("F", todos.get(5).getDescription()); + assertThat(todos.size()).isEqualTo(6); + assertThat(todos.get(1).isComplete()).isFalse(); + assertThat(todos.get(3).getDescription()).isEqualTo("D"); + assertThat(todos.get(4).getDescription()).isEqualTo("E"); + assertThat(todos.get(5).getDescription()).isEqualTo("F"); } @Test - public void failureInMiddle() throws Exception { + void failureInMiddle() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -109,63 +99,58 @@ public class JsonPatchUnitTests { Patch patch = readJsonPatch("patch-failing-operation-in-middle.json"); - try { - patch.apply(todos, Todo.class); - fail(); - } catch (PatchException e) { - assertEquals("Test against path '/5/description' failed.", e.getMessage()); - } + assertThatExceptionOfType(PatchException.class) + .isThrownBy(() -> patch.apply(todos, Todo.class)) + .withMessage("Test against path '/5/description' failed."); - assertEquals(6, todos.size()); - assertFalse(todos.get(1).isComplete()); - assertEquals("D", todos.get(3).getDescription()); - assertEquals("E", todos.get(4).getDescription()); - assertEquals("F", todos.get(5).getDescription()); + assertThat(todos.size()).isEqualTo(6); + assertThat(todos.get(1).isComplete()).isFalse(); + assertThat(todos.get(3).getDescription()).isEqualTo("D"); + assertThat(todos.get(4).getDescription()).isEqualTo("E"); + assertThat(todos.get(5).getDescription()).isEqualTo("F"); } @Test // DATAREST-889 - public void patchArray() throws Exception { + void patchArray() throws Exception { Todo todo = new Todo(1L, "F", false); Patch patch = readJsonPatch("patch-array.json"); - assertEquals(1, patch.size()); + assertThat(patch.size()).isEqualTo(1); Todo patchedTodo = patch.apply(todo, Todo.class); - assertEquals(Arrays.asList("one", "two", "three"), patchedTodo.getItems()); + assertThat(patchedTodo.getItems()).contains("one", "two", "three"); } @Test // DATAREST-889 - public void patchUnknownType() throws Exception { + void patchUnknownType() { Todo todo = new Todo(); todo.setAmount(BigInteger.ONE); - exception.expect(PatchException.class); - exception.expectMessage("/amount"); - exception.expectMessage("18446744073709551616"); - - readJsonPatch("patch-biginteger.json"); + assertThatExceptionOfType(PatchException.class) + .isThrownBy(() -> readJsonPatch("patch-biginteger.json")) + .withMessageContaining("/amount") + .withMessageContaining("18446744073709551616"); } @Test // DATAREST-889 - public void failureWithInvalidPatchContent() throws Exception { + void failureWithInvalidPatchContent() throws Exception { Todo todo = new Todo(); todo.setDescription("Description"); Patch patch = readJsonPatch("patch-failing-with-invalid-content.json"); - exception.expect(PatchException.class); - exception.expectMessage("content"); - exception.expectMessage("blabla"); - exception.expectMessage(String.class.toString()); - - patch.apply(todo, Todo.class); + assertThatExceptionOfType(PatchException.class) // + .isThrownBy(() -> patch.apply(todo, Todo.class)) // + .withMessageContaining("content") // + .withMessageContaining("blabla") // + .withMessageContaining(String.class.getName().toString()); } @Test // DATAREST-1127 - public void rejectsInvalidPaths() throws Exception { + void rejectsInvalidPaths() { assertThatExceptionOfType(PatchException.class).isThrownBy(() -> { readJsonPatch("patch-invalid-path.json").apply(new Todo(), Todo.class); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/MoveOperationUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/MoveOperationUnitTests.java index c24123c00..db9e4b990 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/MoveOperationUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/MoveOperationUnitTests.java @@ -15,36 +15,34 @@ */ package org.springframework.data.rest.webmvc.json.patch; -import static org.junit.Assert.*; +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; -public class MoveOperationUnitTests { +class MoveOperationUnitTests { @Test - public void moveBooleanPropertyValue() throws Exception { + void moveBooleanPropertyValue() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); todos.add(new Todo(2L, "B", false)); todos.add(new Todo(3L, "C", false)); - try { - MoveOperation move = MoveOperation.from("/0/complete").to("/1/complete"); - move.perform(todos, Todo.class); - fail(); - } catch (PatchException e) { - assertEquals("Path '/0/complete' is not nullable.", e.getMessage()); - } + MoveOperation move = MoveOperation.from("/0/complete").to("/1/complete"); - assertFalse(todos.get(1).isComplete()); + assertThatExceptionOfType(PatchException.class) + .isThrownBy(() -> move.perform(todos, Todo.class)) + .withMessage("Path '/0/complete' is not nullable."); + + assertThat(todos.get(1).isComplete()).isFalse(); } @Test - public void moveStringPropertyValue() throws Exception { + void moveStringPropertyValue() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -54,25 +52,24 @@ public class MoveOperationUnitTests { MoveOperation move = MoveOperation.from("/0/description").to("/1/description"); move.perform(todos, Todo.class); - assertEquals("A", todos.get(1).getDescription()); + assertThat(todos.get(1).getDescription()).isEqualTo("A"); } @Test - public void moveBooleanPropertyValueIntoStringProperty() throws Exception { + void moveBooleanPropertyValueIntoStringProperty() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); todos.add(new Todo(2L, "B", false)); todos.add(new Todo(3L, "C", false)); - try { - MoveOperation move = MoveOperation.from("/0/complete").to("/1/description"); - move.perform(todos, Todo.class); - fail(); - } catch (PatchException e) { - assertEquals("Path '/0/complete' is not nullable.", e.getMessage()); - } - assertEquals("B", todos.get(1).getDescription()); + MoveOperation move = MoveOperation.from("/0/complete").to("/1/description"); + + assertThatExceptionOfType(PatchException.class) + .isThrownBy(() -> move.perform(todos, Todo.class)) + .withMessage("Path '/0/complete' is not nullable."); + + assertThat(todos.get(1).getDescription()).isEqualTo("B"); } // @@ -84,7 +81,7 @@ public class MoveOperationUnitTests { // @Test - public void moveListElementToBeginningOfList() throws Exception { + void moveListElementToBeginningOfList() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -94,14 +91,14 @@ public class MoveOperationUnitTests { MoveOperation move = MoveOperation.from("/1").to("/0"); move.perform(todos, Todo.class); - assertEquals(3, todos.size()); - assertEquals(2L, todos.get(0).getId().longValue()); - assertEquals("B", todos.get(0).getDescription()); - assertTrue(todos.get(0).isComplete()); + assertThat(todos.size()).isEqualTo(3); + assertThat(todos.get(0).getId().longValue()).isEqualTo(2L); + assertThat(todos.get(0).getDescription()).isEqualTo("B"); + assertThat(todos.get(0).isComplete()).isTrue(); } @Test - public void moveListElementToMiddleOfList() throws Exception { + void moveListElementToMiddleOfList() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -111,14 +108,14 @@ public class MoveOperationUnitTests { MoveOperation move = MoveOperation.from("/0").to("/2"); move.perform(todos, Todo.class); - assertEquals(3, todos.size()); - assertEquals(1L, todos.get(2).getId().longValue()); - assertEquals("A", todos.get(2).getDescription()); - assertTrue(todos.get(2).isComplete()); + assertThat(todos.size()).isEqualTo(3); + assertThat(todos.get(2).getId().longValue()).isEqualTo(1L); + assertThat(todos.get(2).getDescription()).isEqualTo("A"); + assertThat(todos.get(2).isComplete()).isTrue(); } @Test - public void moveListElementToEndOfList_usingIndex() throws Exception { + void moveListElementToEndOfList_usingIndex() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -128,14 +125,14 @@ public class MoveOperationUnitTests { MoveOperation move = MoveOperation.from("/0").to("/2"); move.perform(todos, Todo.class); - assertEquals(3, todos.size()); - assertEquals(1L, todos.get(2).getId().longValue()); - assertEquals("A", todos.get(2).getDescription()); - assertTrue(todos.get(2).isComplete()); + assertThat(todos.size()).isEqualTo(3); + assertThat(todos.get(2).getId().longValue()).isEqualTo(1L); + assertThat(todos.get(2).getDescription()).isEqualTo("A"); + assertThat(todos.get(2).isComplete()).isTrue(); } @Test - public void moveListElementToBeginningOfList_usingDash() throws Exception { + void moveListElementToBeginningOfList_usingDash() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -151,11 +148,12 @@ public class MoveOperationUnitTests { MoveOperation move = MoveOperation.from("/-").to("/1"); move.perform(todos, Todo.class); - assertEquals(expected, todos); + + assertThat(todos).isEqualTo(expected); } @Test - public void moveListElementToEndOfList_usingDash() throws Exception { + void moveListElementToEndOfList_usingDash() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", true)); @@ -171,7 +169,7 @@ public class MoveOperationUnitTests { MoveOperation move = MoveOperation.from("/1").to("/-"); move.perform(todos, Todo.class); - assertEquals(expected, todos); - } + assertThat(todos).isEqualTo(expected); + } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/PatchOperationUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/PatchOperationUnitTests.java index a23fb8f3d..b32ccaa2d 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/PatchOperationUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/PatchOperationUnitTests.java @@ -17,29 +17,25 @@ package org.springframework.data.rest.webmvc.json.patch; import static org.assertj.core.api.Assertions.*; -import java.util.Arrays; +import java.util.stream.Stream; -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.DynamicTest; +import org.junit.jupiter.api.TestFactory; /** * General unit tests for {@link PatchOperation} implementations. * * @author Oliver Gierke */ -@RunWith(Parameterized.class) -public class PatchOperationUnitTests { +class PatchOperationUnitTests { - @Parameters - public static Iterable operations() { + @TestFactory // DATAREST-1137 + Stream invalidPathGetsRejected() { String invalidPath = "/nonExistant"; String validPath = "/1/description"; - return Arrays.asList( // + return DynamicTest.stream(Stream.of( // AddOperation.of(invalidPath, null), // RemoveOperation.valueAt(invalidPath), // @@ -51,17 +47,13 @@ public class PatchOperationUnitTests { MoveOperation.from(invalidPath).to(validPath), // MoveOperation.from(validPath).to(invalidPath) // - ); - } - public @Parameter(0) PatchOperation operation; + ), it -> it.toString(), it -> { - @Test // DATAREST-1137 - public void invalidPathGetsRejected() { + Todo todo = new Todo(1L, "A", false); - Todo todo = new Todo(1L, "A", false); - - assertThatExceptionOfType(PatchException.class) // - .isThrownBy(() -> operation.perform(todo, Todo.class)); + assertThatExceptionOfType(PatchException.class) // + .isThrownBy(() -> it.perform(todo, Todo.class)); + }); } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/RemoveOperationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/RemoveOperationTests.java index 0f88413b7..3c5033a44 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/RemoveOperationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/RemoveOperationTests.java @@ -15,17 +15,17 @@ */ package org.springframework.data.rest.webmvc.json.patch; -import static org.junit.Assert.*; +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; -public class RemoveOperationTests { +class RemoveOperationTests { @Test - public void removePropertyFromObject() throws Exception { + void removePropertyFromObject() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -34,11 +34,11 @@ public class RemoveOperationTests { RemoveOperation.valueAt("/1/description").perform(todos, Todo.class); - assertNull(todos.get(1).getDescription()); + assertThat(todos.get(1).getDescription()).isNull(); } @Test - public void removeItemFromList() throws Exception { + void removeItemFromList() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -47,9 +47,8 @@ public class RemoveOperationTests { RemoveOperation.valueAt("/1").perform(todos, Todo.class); - assertEquals(2, todos.size()); - assertEquals("A", todos.get(0).getDescription()); - assertEquals("C", todos.get(1).getDescription()); + assertThat(todos.size()).isEqualTo(2); + assertThat(todos.get(0).getDescription()).isEqualTo("A"); + assertThat(todos.get(1).getDescription()).isEqualTo("C"); } - } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperationTests.java index d5b35ffad..5b961551a 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperationTests.java @@ -15,23 +15,22 @@ */ package org.springframework.data.rest.webmvc.json.patch; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -public class ReplaceOperationTests { +class ReplaceOperationTests { @Test - public void replaceBooleanPropertyValue() throws Exception { + void replaceBooleanPropertyValue() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -41,11 +40,11 @@ public class ReplaceOperationTests { ReplaceOperation replace = ReplaceOperation.valueAt("/1/complete").with(true); replace.perform(todos, Todo.class); - assertTrue(todos.get(1).isComplete()); + assertThat(todos.get(1).isComplete()).isTrue(); } @Test - public void replaceTextPropertyValue() throws Exception { + void replaceTextPropertyValue() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -55,11 +54,11 @@ public class ReplaceOperationTests { ReplaceOperation replace = ReplaceOperation.valueAt("/1/description").with("BBB"); replace.perform(todos, Todo.class); - assertEquals("BBB", todos.get(1).getDescription()); + assertThat(todos.get(1).getDescription()).isEqualTo("BBB"); } @Test - public void replaceTextPropertyValueWithANumber() throws Exception { + void replaceTextPropertyValueWithANumber() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -69,11 +68,11 @@ public class ReplaceOperationTests { ReplaceOperation replace = ReplaceOperation.valueAt("/1/description").with(22); replace.perform(todos, Todo.class); - assertEquals("22", todos.get(1).getDescription()); + assertThat(todos.get(1).getDescription()).isEqualTo("22"); } @Test // DATAREST-885 - public void replaceObjectPropertyValue() throws Exception { + void replaceObjectPropertyValue() throws Exception { Todo todo = new Todo(1L, "A", false); @@ -82,13 +81,13 @@ public class ReplaceOperationTests { .with(new JsonLateObjectEvaluator(mapper, mapper.readTree("{ \"value\" : \"new\" }"))); replace.perform(todo, Todo.class); - assertNotNull(todo.getType()); - assertNotNull(todo.getType().getValue()); - assertTrue(todo.getType().getValue().equals("new")); + assertThat(todo.getType()).isNotNull(); + assertThat(todo.getType().getValue()).isNotNull(); + assertThat(todo.getType().getValue().equals("new")).isTrue(); } @Test // DATAREST-1338 - public void replacesMapValueCorrectly() throws Exception { + void replacesMapValueCorrectly() throws Exception { Book book = new Book(); book.characters = new HashMap<>(); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/SpelPathUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/SpelPathUnitTests.java index b7e5e83f8..4a640d005 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/SpelPathUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/SpelPathUnitTests.java @@ -15,14 +15,13 @@ */ package org.springframework.data.rest.webmvc.json.patch; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.*; import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.rest.webmvc.json.patch.SpelPath.TypedSpelPath; import org.springframework.data.rest.webmvc.json.patch.SpelPath.UntypedSpelPath; @@ -31,10 +30,10 @@ import org.springframework.data.rest.webmvc.json.patch.SpelPath.UntypedSpelPath; * * @author Oliver Gierke */ -public class SpelPathUnitTests { +class SpelPathUnitTests { @Test - public void listIndex() { + void listIndex() { UntypedSpelPath expr = SpelPath.untyped("/1/description"); @@ -43,11 +42,13 @@ public class SpelPathUnitTests { todos.add(new Todo(2L, "B", false)); todos.add(new Todo(3L, "C", false)); - assertEquals("B", expr.bindTo(Todo.class).getValue(todos)); + Object value = expr.bindTo(Todo.class).getValue(todos); + + assertThat(value).isEqualTo("B"); } @Test - public void accessesLastCollectionElementWithDash() { + void accessesLastCollectionElementWithDash() { UntypedSpelPath expr = SpelPath.untyped("/-/description"); @@ -56,35 +57,37 @@ public class SpelPathUnitTests { todos.add(new Todo(2L, "B", false)); todos.add(new Todo(3L, "C", false)); - assertEquals("C", expr.bindTo(Todo.class).getValue(todos)); + Object value = expr.bindTo(Todo.class).getValue(todos); + + assertThat(value).isEqualTo("C"); } @Test // DATAREST-1152 - public void cachesSpelPath() { + void cachesSpelPath() { UntypedSpelPath left = SpelPath.untyped("/description"); UntypedSpelPath right = SpelPath.untyped("/description"); - assertSame(left, right); + assertThat(left).isSameAs(right); } @Test // DATAREST-1152 - public void cachesTypedSpelPath() { + void cachesTypedSpelPath() { UntypedSpelPath source = SpelPath.untyped("/description"); TypedSpelPath left = source.bindTo(Todo.class); TypedSpelPath right = source.bindTo(Todo.class); - assertSame(left, right); + assertThat(left).isSameAs(right); } @Test // DATAREST-1274 - public void supportsMultiDigitCollectionIndex() { + void supportsMultiDigitCollectionIndex() { assertThat(SpelPath.untyped("/11/description").bindTo(Todo.class).getLeafType()).isEqualTo(String.class); } @Test // DATAREST-1338 - public void handlesStringMapKeysInPathExpressions() { + void handlesStringMapKeysInPathExpressions() { TypedSpelPath path = SpelPath.untyped("people/Dave/name").bindTo(MapWrapper.class); @@ -93,7 +96,7 @@ public class SpelPathUnitTests { } @Test // DATAREST-1338 - public void handlesIntegerMapKeysInPathExpressions() { + void handlesIntegerMapKeysInPathExpressions() { TypedSpelPath path = SpelPath.untyped("peopleByInt/0/name").bindTo(MapWrapper.class); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TestOperationUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TestOperationUnitTests.java index c9f0a4fc2..c392e8085 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TestOperationUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TestOperationUnitTests.java @@ -15,15 +15,17 @@ */ package org.springframework.data.rest.webmvc.json.patch; +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; -public class TestOperationUnitTests { +class TestOperationUnitTests { @Test - public void testPropertyValueEquals() throws Exception { + void testPropertyValueEquals() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -38,8 +40,8 @@ public class TestOperationUnitTests { } - @Test(expected = PatchException.class) - public void testPropertyValueNotEquals() throws Exception { + @Test + void testPropertyValueNotEquals() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); @@ -47,11 +49,13 @@ public class TestOperationUnitTests { todos.add(new Todo(3L, "C", false)); TestOperation test = TestOperation.whetherValueAt("/0/complete").hasValue(true); - test.perform(todos, Todo.class); + + assertThatExceptionOfType(PatchException.class) // + .isThrownBy(() -> test.perform(todos, Todo.class)); } @Test - public void testListElementEquals() throws Exception { + void testListElementEquals() throws Exception { List todos = new ArrayList(); todos.add(new Todo(1L, "A", false)); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoList.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoList.java index 60f2f36ac..3cdd2834a 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoList.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoList.java @@ -21,7 +21,7 @@ import java.io.Serializable; import java.util.List; @Data -public class TodoList implements Serializable { +class TodoList implements Serializable { private static final long serialVersionUID = 1L; diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoType.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoType.java index cacd00511..626261f1b 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoType.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoType.java @@ -26,6 +26,6 @@ import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor -public class TodoType { +class TodoType { private String value = "none"; } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mapping/AssociationsUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mapping/AssociationsUnitTests.java index 2bdc2a34e..e3264bf20 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mapping/AssociationsUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mapping/AssociationsUnitTests.java @@ -21,11 +21,13 @@ import static org.mockito.Mockito.*; 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.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.annotation.Reference; import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity; import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty; @@ -45,8 +47,9 @@ import org.springframework.hateoas.Link; /** * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class AssociationsUnitTests { +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +class AssociationsUnitTests { @Mock RepositoryRestConfiguration configuration; @Mock ProjectionDefinitionConfiguration projectionDefinitionConfiguration; @@ -59,8 +62,8 @@ public class AssociationsUnitTests { KeyValueMappingContext mappingContext; ResourceMappings mappings; - @Before - public void setUp() { + @BeforeEach + void setUp() { doReturn(projectionDefinitionConfiguration).when(configuration).getProjectionConfiguration(); this.mappingContext = new KeyValueMappingContext<>(); @@ -71,23 +74,27 @@ public class AssociationsUnitTests { this.associations = new Associations(mappings, configuration); } - @Test(expected = IllegalArgumentException.class) - public void rejectsNullMappings() { - new Associations(null, configuration); - } + @Test + void rejectsNullMappings() { - @Test(expected = IllegalArgumentException.class) - public void rejectsNullConfiguration() { - new Associations(mappings, null); + assertThatIllegalArgumentException() // + .isThrownBy(() -> new Associations(null, configuration)); } @Test - public void handlesNullPropertyForLookupTypeCheck() { + void rejectsNullConfiguration() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new Associations(mappings, null)); + } + + @Test + void handlesNullPropertyForLookupTypeCheck() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> associations.isLookupType(null)); } @Test - public void forwardsLookupTypeCheckToConfiguration() { + void forwardsLookupTypeCheckToConfiguration() { doReturn(Root.class).when(property).getActualType(); assertThat(associations.isLookupType(property)).isFalse(); @@ -97,7 +104,7 @@ public class AssociationsUnitTests { } @Test - public void forwardsIdExposureCheckToConfiguration() { + void forwardsIdExposureCheckToConfiguration() { doReturn(Root.class).when(entity).getType(); assertThat(associations.isIdExposed(entity)).isFalse(); @@ -107,17 +114,17 @@ public class AssociationsUnitTests { } @Test - public void exposesConfiguredMapping() { + void exposesConfiguredMapping() { assertThat(associations.getMappings()).isEqualTo(mappings); } @Test - public void forwardsMetadataLookupToMappings() { + void forwardsMetadataLookupToMappings() { assertThat(associations.getMetadataFor(Root.class)).isNotNull(); } @Test - public void detectsAssociationLinks() { + void detectsAssociationLinks() { List links = associations.getLinksFor(getAssociation(Root.class, "relatedAndExported"), new Path("")); @@ -126,7 +133,7 @@ public class AssociationsUnitTests { } @Test - public void doesNotCreateAssociationLinkIfTargetIsNotExported() { + void doesNotCreateAssociationLinkIfTargetIsNotExported() { List links = associations.getLinksFor(getAssociation(Root.class, "relatedButNotExported"), new Path("")); @@ -134,7 +141,7 @@ public class AssociationsUnitTests { } @Test // DATAREST-1105 - public void detectsProjectionsForAssociationLinks() { + void detectsProjectionsForAssociationLinks() { String projectionParameterName = "projection"; diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/BackendIdHandlerMethodArgumentResolverUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/BackendIdHandlerMethodArgumentResolverUnitTests.java index 490b106fc..e1258039e 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/BackendIdHandlerMethodArgumentResolverUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/BackendIdHandlerMethodArgumentResolverUnitTests.java @@ -21,7 +21,7 @@ import static org.mockito.Mockito.*; import java.io.Serializable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; import org.springframework.data.rest.core.mapping.ResourceMetadata; import org.springframework.data.rest.webmvc.BaseUri; @@ -39,7 +39,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; * * @author Oliver Drotbohm */ -public class BackendIdHandlerMethodArgumentResolverUnitTests { +class BackendIdHandlerMethodArgumentResolverUnitTests { BackendIdConverter converter = mock(BackendIdConverter.class); ResourceMetadataHandlerMethodArgumentResolver delegate = mock(ResourceMetadataHandlerMethodArgumentResolver.class); @@ -47,7 +47,7 @@ public class BackendIdHandlerMethodArgumentResolverUnitTests { PluginRegistry.of(converter), delegate, BaseUri.NONE); @Test // DATAREST-1382 - public void returnsNullForUrisNotNotContainingUri() throws Exception { + void returnsNullForUrisNotNotContainingUri() throws Exception { ResourceMetadata metadata = mock(ResourceMetadata.class); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/DefaultExcerptProjectorUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/DefaultExcerptProjectorUnitTests.java index 8ff8fbbbb..faf52a40e 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/DefaultExcerptProjectorUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/DefaultExcerptProjectorUnitTests.java @@ -20,7 +20,7 @@ import static org.mockito.Mockito.*; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.rest.core.mapping.ResourceMappings; import org.springframework.data.rest.core.mapping.ResourceMetadata; @@ -30,14 +30,14 @@ import org.springframework.data.rest.core.mapping.ResourceMetadata; * * @author Oliver Drotbohm */ -public class DefaultExcerptProjectorUnitTests { +class DefaultExcerptProjectorUnitTests { ProjectionFactory factory = mock(ProjectionFactory.class); ResourceMappings mappings = mock(ResourceMappings.class); ResourceMetadata metadata = mock(ResourceMetadata.class); @Test // DATAREST-1446 - public void doesNotHaveExcerptProjectionIfMetadataReturnsNone() { + void doesNotHaveExcerptProjectionIfMetadataReturnsNone() { when(mappings.getMetadataFor(Object.class)).thenReturn(metadata); when(metadata.getExcerptProjection()).thenReturn(Optional.empty()); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagDoesntMatchExceptionUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagDoesntMatchExceptionUnitTests.java index d5c4fdbbd..08b6af51e 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagDoesntMatchExceptionUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagDoesntMatchExceptionUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2018 original author or authors. + * Copyright 2014-2021 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,22 +15,28 @@ */ package org.springframework.data.rest.webmvc.support; -import org.junit.Test; +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.Test; /** * Unit tests for {@link ETagDoesntMatchException}. * * @author Oliver Gierke */ -public class ETagDoesntMatchExceptionUnitTests { +class ETagDoesntMatchExceptionUnitTests { - @Test(expected = IllegalArgumentException.class) // DATAREST-160 - public void rejectsNullTargetBean() { - new ETagDoesntMatchException(null, ETag.from("1")); + @Test // DATAREST-160 + void rejectsNullTargetBean() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new ETagDoesntMatchException(null, ETag.from("1"))); } - @Test(expected = IllegalArgumentException.class) // DATAREST-160 - public void rejectsNullExpectedETag() { - new ETagDoesntMatchException(new Object(), null); + @Test // DATAREST-160 + void rejectsNullExpectedETag() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new ETagDoesntMatchException(new Object(), null)); } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagUnitTests.java index ccf948e4b..f3da7ba85 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagUnitTests.java @@ -17,9 +17,9 @@ package org.springframework.data.rest.webmvc.support; import static org.assertj.core.api.Assertions.*; -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.Version; import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; import org.springframework.data.mapping.PersistentEntity; @@ -32,25 +32,27 @@ import org.springframework.http.HttpHeaders; * @author Pablo Lozano * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class ETagUnitTests { +@ExtendWith(MockitoExtension.class) +class ETagUnitTests { KeyValueMappingContext context = new KeyValueMappingContext<>(); - @Test(expected = ETagDoesntMatchException.class) // DATAREST-160 - public void expectWrongEtag() throws Exception { + @Test // DATAREST-160 + void expectWrongEtag() throws Exception { ETag eTag = ETag.from("1"); - eTag.verify(context.getRequiredPersistentEntity(Sample.class), new Sample(0L)); + + assertThatExceptionOfType(ETagDoesntMatchException.class) // + .isThrownBy(() -> eTag.verify(context.getRequiredPersistentEntity(Sample.class), new Sample(0L))); } @Test // DATAREST-160 - public void expectCorrectEtag() throws Exception { + void expectCorrectEtag() throws Exception { ETag.from("0").verify(context.getRequiredPersistentEntity(Sample.class), new Sample(0L)); } @Test // DATAREST-160 - public void createsETagFromVersionValue() throws Exception { + void createsETagFromVersionValue() throws Exception { PersistentEntity entity = context.getRequiredPersistentEntity(Sample.class); ETag from = ETag.from(PersistentEntityResource.build(new Sample(0L), entity).build()); @@ -59,17 +61,17 @@ public class ETagUnitTests { } @Test // DATAREST-160 - public void surroundsValueWithQuotationMarksOnToString() { + void surroundsValueWithQuotationMarksOnToString() { assertThat(ETag.from("1").toString()).isEqualTo("\"1\""); } @Test // DATAREST-160 - public void returnsNoEtagForNullStringSource() { + void returnsNoEtagForNullStringSource() { assertThat(ETag.from((String) null)).isEqualTo(ETag.NO_ETAG); } @Test // DATAREST-160 - public void returnsNoEtagForNullPersistentEntityResourceSource() { + void returnsNoEtagForNullPersistentEntityResourceSource() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { ETag.from((PersistentEntityResource) null); @@ -77,7 +79,7 @@ public class ETagUnitTests { } @Test // DATAREST-160 - public void hasValueObjectEqualsSemantics() { + void hasValueObjectEqualsSemantics() { ETag one = ETag.from("1"); ETag two = ETag.from("2"); @@ -92,7 +94,7 @@ public class ETagUnitTests { } @Test // DATAREST-160 - public void returnsNoEtagForEntityWithoutVersionProperty() { + void returnsNoEtagForEntityWithoutVersionProperty() { PersistentEntity entity = context.getRequiredPersistentEntity(SampleWithoutVersion.class); assertThat(ETag.from(PersistentEntityResource.build(new SampleWithoutVersion(), entity).build())) @@ -100,36 +102,36 @@ public class ETagUnitTests { } @Test // DATAREST-160 - public void noETagReturnsNullForToString() { + void noETagReturnsNullForToString() { assertThat(ETag.NO_ETAG.toString()).isNull(); } @Test // DATAREST-160 - public void noETagDoesNotRejectVerification() { + void noETagDoesNotRejectVerification() { ETag.NO_ETAG.verify(context.getRequiredPersistentEntity(Sample.class), new Sample(5L)); } @Test // DATAREST-160 - public void verificationDoesNotRejectNullEntity() { + void verificationDoesNotRejectNullEntity() { ETag.from("5").verify(context.getRequiredPersistentEntity(Sample.class), null); } @Test // DATAREST-160 - public void stripsTrailingAndLeadingQuotesOnCreation() { + void stripsTrailingAndLeadingQuotesOnCreation() { assertThat(ETag.from("\"1\"")).isEqualTo(ETag.from("1")); assertThat(ETag.from("\"\"1\"\"")).isEqualTo(ETag.from("1")); } @Test // DATAREST-160 - public void addsETagToHeadersIfNotNoETag() { + void addsETagToHeadersIfNotNoETag() { HttpHeaders headers = ETag.from("1").addTo(new HttpHeaders()); assertThat(headers.getETag()).isNotNull(); } @Test // DATAREST-160 - public void doesNotAddHeaderForNoETag() { + void doesNotAddHeaderForNoETag() { HttpHeaders headers = ETag.NO_ETAG.addTo(new HttpHeaders()); @@ -137,7 +139,7 @@ public class ETagUnitTests { } // tag::versioned-sample[] - public class Sample { + class Sample { @Version Long version; // <1> @@ -147,5 +149,5 @@ public class ETagUnitTests { } // end::versioned-sample[] - public class SampleWithoutVersion {} + class SampleWithoutVersion {} } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/PersistentEntityProjectorUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/PersistentEntityProjectorUnitTests.java index 701c76a96..bacdf67b3 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/PersistentEntityProjectorUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/PersistentEntityProjectorUnitTests.java @@ -20,11 +20,13 @@ import static org.mockito.Mockito.*; 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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.projection.SpelAwareProxyProjectionFactory; import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration; @@ -36,8 +38,9 @@ import org.springframework.data.rest.core.mapping.ResourceMetadata; * * @author Oliver Gierke */ -@RunWith(MockitoJUnitRunner.class) -public class PersistentEntityProjectorUnitTests { +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +class PersistentEntityProjectorUnitTests { @Mock ResourceMappings mappings; @@ -45,8 +48,8 @@ public class PersistentEntityProjectorUnitTests { ProjectionFactory factory; ProjectionDefinitionConfiguration configuration; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.configuration = new ProjectionDefinitionConfiguration(); this.factory = new SpelAwareProxyProjectionFactory(); @@ -58,7 +61,7 @@ public class PersistentEntityProjectorUnitTests { } @Test // DATAREST-221 - public void returnsObjectAsIsIfNoProjectionTypeFound() { + void returnsObjectAsIsIfNoProjectionTypeFound() { Object object = new Object(); @@ -66,7 +69,7 @@ public class PersistentEntityProjectorUnitTests { } @Test // DATAREST-221 - public void invokesProjectionFactoryIfProjectionFound() { + void invokesProjectionFactoryIfProjectionFound() { configuration.addProjection(Sample.class, Object.class); @@ -74,7 +77,7 @@ public class PersistentEntityProjectorUnitTests { } @Test // DATAREST-806 - public void favorsExplicitProjectionOverExcerpt() { + void favorsExplicitProjectionOverExcerpt() { configuration.addProjection(Sample.class, Object.class); @@ -82,12 +85,12 @@ public class PersistentEntityProjectorUnitTests { } @Test // DATAREST-806 - public void excerptProjectionIsUsedForExcerpt() { + void excerptProjectionIsUsedForExcerpt() { assertThat(projector.projectExcerpt(new Object())).isInstanceOf(Excerpt.class); } @Test // DATAREST-806 - public void usesExcerptProjectionIfNoExplicitProjectionWasRequested() { + void usesExcerptProjectionIfNoExplicitProjectionWasRequested() { configuration.addProjection(Sample.class, Object.class); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryConstraintViolationExceptionMessageUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryConstraintViolationExceptionMessageUnitTests.java index ff3cff6aa..91d6689ff 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryConstraintViolationExceptionMessageUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryConstraintViolationExceptionMessageUnitTests.java @@ -23,8 +23,8 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.context.support.MessageSourceAccessor; import org.springframework.context.support.StaticMessageSource; import org.springframework.data.rest.core.RepositoryConstraintViolationException; @@ -37,13 +37,13 @@ import org.springframework.validation.MapBindingResult; * * @author Oliver Gierke */ -public class RepositoryConstraintViolationExceptionMessageUnitTests { +class RepositoryConstraintViolationExceptionMessageUnitTests { MessageSourceAccessor accessor; RepositoryConstraintViolationException exception; - @Before - public void setUp() { + @BeforeEach + void setUp() { StaticMessageSource messageSource = new StaticMessageSource(); messageSource.addMessage("code", Locale.ENGLISH, "message"); @@ -52,18 +52,22 @@ public class RepositoryConstraintViolationExceptionMessageUnitTests { this.exception = new RepositoryConstraintViolationException(new MapBindingResult(Collections.emptyMap(), "object")); } - @Test(expected = IllegalArgumentException.class) - public void rejectsNullException() { - new RepositoryConstraintViolationExceptionMessage(null, accessor); - } + @Test + void rejectsNullException() { - @Test(expected = IllegalArgumentException.class) - public void rejectsNullAccessor() { - new RepositoryConstraintViolationExceptionMessage(exception, null); + assertThatIllegalArgumentException() // + .isThrownBy(() -> new RepositoryConstraintViolationExceptionMessage(null, accessor)); } @Test - public void calidationErrorsCaptureRejectedValueAsIs() { + void rejectsNullAccessor() { + + assertThatIllegalArgumentException() // + .isThrownBy(() -> new RepositoryConstraintViolationExceptionMessage(exception, null)); + } + + @Test + void calidationErrorsCaptureRejectedValueAsIs() { assertRejectedValue("stringValue", "string"); assertRejectedValue("intValue", 1); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/util/UriUtilsUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/util/UriUtilsUnitTests.java index 4e4974a78..68be201e4 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/util/UriUtilsUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/util/UriUtilsUnitTests.java @@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*; import java.lang.reflect.Method; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.util.ClassUtils; import org.springframework.web.bind.annotation.RequestMapping; @@ -29,10 +29,10 @@ import org.springframework.web.bind.annotation.RequestMapping; * * @author Mark Paluch */ -public class UriUtilsUnitTests { +class UriUtilsUnitTests { @Test // DATAREST-910 - public void pathSegmentsShouldDiscoverPathUsingMethodMapping() throws Exception { + void pathSegmentsShouldDiscoverPathUsingMethodMapping() throws Exception { Method method = ClassUtils.getMethod(MappedMethod.class, "method"); List pathSegments = UriUtils.getPathSegments(method); @@ -41,7 +41,7 @@ public class UriUtilsUnitTests { } @Test // DATAREST-910 - public void pathSegmentsShouldDiscoverPathUsingTypeAndMethodMapping() throws Exception { + void pathSegmentsShouldDiscoverPathUsingTypeAndMethodMapping() throws Exception { Method method = ClassUtils.getMethod(MappedClassAndMethod.class, "method"); List pathSegments = UriUtils.getPathSegments(method);