Switch to JUnit 5.

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

View File

@@ -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<Link> 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));
}

View File

@@ -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));

View File

@@ -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));

View File

@@ -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");
}
}

View File

@@ -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<MediaType> mediaTypes = Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_ATOM_XML);
HttpServletRequest servletRequest = new CustomAcceptHeaderHttpServletRequest(request, mediaTypes);

View File

@@ -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");

View File

@@ -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<EmbeddedWrapper> 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();

View File

@@ -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());

View File

@@ -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);

View File

@@ -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<Object> 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);

View File

@@ -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<ExceptionMessage> 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<ExceptionMessage> 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!";

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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<PersistentEntityResource> 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) {

View File

@@ -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));
}
/**

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -45,7 +45,7 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException;
* @author Oliver Drotbohm
*/
@ExtendWith(MockitoExtension.class)
public class HalFormsAdaptingResponseBodyAdviceTests<T extends RepresentationModel<T>> {
class HalFormsAdaptingResponseBodyAdviceTests<T extends RepresentationModel<T>> {
HalFormsAdaptingResponseBodyAdvice<T> advice = new HalFormsAdaptingResponseBodyAdvice<>();

View File

@@ -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.<HttpMessageConverter<?>> 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();

View File

@@ -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<MappingJackson2HttpMessageConverter> 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<HttpMessageConverter<?>> 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<HttpMessageConverter<?>> converters;
@Autowired
public void setConverters(List<HttpMessageConverter<?>> converters) {
void setConverters(List<HttpMessageConverter<?>> converters) {
this.converters = converters;
}
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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, Object>) 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<String, Object> childMap = new HashMap<String, Object>();
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<Item>();
@@ -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<Item>();
@@ -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<Item>();
@@ -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<Item>();
@@ -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<Nested> 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<Nested> originalCollection = new ArrayList<Nested>(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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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) {}
}
}

View File

@@ -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());

View File

@@ -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();

View File

@@ -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";

View File

@@ -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));

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
todos.add(new Todo(1L, "A", false));
@@ -130,7 +128,7 @@ public class AddOperationUnitTests {
}
@Test // DATAREST-1273
public void rejectsAdditionBeyondEndOfList() {
void rejectsAdditionBeyondEndOfList() {
List<Todo> todos = new ArrayList<Todo>();
todos.add(new Todo(1L, "A", false));
@@ -143,7 +141,7 @@ public class AddOperationUnitTests {
}
@Test // DATAREST-1479
public void manipulatesNestedCollectionProperly() {
void manipulatesNestedCollectionProperly() {
List<Todo> todos = new ArrayList<>();
todos.add(new Todo(1L, "A", false));

View File

@@ -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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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
}
}

View File

@@ -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<Todo> todos = new ArrayList<Todo>();
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<Todo> 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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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);

View File

@@ -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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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);
}
}

View File

@@ -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<? extends PatchOperation> operations() {
@TestFactory // DATAREST-1137
Stream<DynamicTest> 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));
});
}
}

View File

@@ -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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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");
}
}

View File

@@ -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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<>();

View File

@@ -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);

View File

@@ -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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
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<Todo> todos = new ArrayList<Todo>();
todos.add(new Todo(1L, "A", false));

View File

@@ -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;

View File

@@ -26,6 +26,6 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TodoType {
class TodoType {
private String value = "none";
}

View File

@@ -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<Link> links = associations.getLinksFor(getAssociation(Root.class, "relatedAndExported"), new Path(""));
@@ -126,7 +133,7 @@ public class AssociationsUnitTests {
}
@Test
public void doesNotCreateAssociationLinkIfTargetIsNotExported() {
void doesNotCreateAssociationLinkIfTargetIsNotExported() {
List<Link> 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";

View File

@@ -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);

View File

@@ -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());

View File

@@ -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));
}
}

View File

@@ -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 {}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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<String> 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<String> pathSegments = UriUtils.getPathSegments(method);