DATAREST-1410 - Migrate remaining tests to AssertJ.
This commit is contained in:
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@@ -42,7 +40,7 @@ public class BaseUriUnitTests {
|
||||
|
||||
BaseUri uri = new BaseUri(URI.create("foo"));
|
||||
|
||||
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
|
||||
assertThat(uri.getRepositoryLookupPath("/foo")).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
@@ -50,8 +48,8 @@ public class BaseUriUnitTests {
|
||||
|
||||
BaseUri uri = new BaseUri(URI.create("foo/"));
|
||||
|
||||
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/"), isEmptyString());
|
||||
assertThat(uri.getRepositoryLookupPath("/foo")).isEmpty();
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/")).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
@@ -59,8 +57,8 @@ public class BaseUriUnitTests {
|
||||
|
||||
BaseUri uri = new BaseUri(URI.create("/foo"));
|
||||
|
||||
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/"), isEmptyString());
|
||||
assertThat(uri.getRepositoryLookupPath("/foo")).isEmpty();
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/")).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
@@ -68,8 +66,8 @@ public class BaseUriUnitTests {
|
||||
|
||||
BaseUri uri = new BaseUri(URI.create("http://localhost:8080/foo/"));
|
||||
|
||||
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/"), isEmptyString());
|
||||
assertThat(uri.getRepositoryLookupPath("/foo")).isEmpty();
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/")).isEmpty();
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/people")).isEqualTo("/people");
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/people/")).isEqualTo("/people");
|
||||
}
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -26,6 +24,7 @@ import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.CustomAcceptHeaderHttpServletRequest;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -48,8 +47,8 @@ public class CustomAcceptHeaderHttpServletRequestUnitTests {
|
||||
List<MediaType> mediaTypes = Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_ATOM_XML);
|
||||
HttpServletRequest servletRequest = new CustomAcceptHeaderHttpServletRequest(request, mediaTypes);
|
||||
|
||||
assertThat(servletRequest.getHeader(HttpHeaders.ACCEPT),
|
||||
is(StringUtils.collectionToCommaDelimitedString(mediaTypes)));
|
||||
assertThat(servletRequest.getHeader(HttpHeaders.ACCEPT))
|
||||
.isEqualTo(StringUtils.collectionToCommaDelimitedString(mediaTypes));
|
||||
|
||||
List<String> expected = Collections.list(servletRequest.getHeaders(HttpHeaders.ACCEPT));
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
class HttpEntityMatcher<T> extends BaseMatcher<HttpEntity<T>> {
|
||||
|
||||
private final HttpEntity<T> expected;
|
||||
|
||||
public HttpEntityMatcher(HttpEntity<T> expected) {
|
||||
Assert.notNull(expected, "HttpEntity cannot be null");
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
public static <T> HttpEntityMatcher<T> httpEntity(HttpEntity<T> httpEntity) {
|
||||
return new HttpEntityMatcher<T>(httpEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object item) {
|
||||
if (!(item instanceof HttpEntity)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item instanceof ResponseEntity && expected instanceof ResponseEntity) {
|
||||
ResponseEntity<?> left = (ResponseEntity<?>) expected;
|
||||
ResponseEntity<?> right = (ResponseEntity<?>) item;
|
||||
|
||||
if (!left.getStatusCode().equals(right.getStatusCode())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
HttpEntity<?> left = expected;
|
||||
HttpEntity<?> right = (HttpEntity<?>) item;
|
||||
|
||||
return left.getBody().equals(right.getBody()) && left.getHeaders().equals(right.getHeaders());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText(expected.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -27,6 +25,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.NoOpStringValueResolver;
|
||||
@@ -66,8 +65,8 @@ public class RepositoryCorsConfigurationAccessorUnitTests {
|
||||
assertThat(configuration.getAllowCredentials()).isFalse();
|
||||
assertThat(configuration.getAllowedHeaders()).contains("*");
|
||||
assertThat(configuration.getAllowedOrigins()).contains("*");
|
||||
assertThat(configuration.getAllowedMethods(),
|
||||
hasItems("OPTIONS", "HEAD", "GET", "PATCH", "POST", "PUT", "DELETE", "TRACE"));
|
||||
assertThat(configuration.getAllowedMethods()).contains("OPTIONS", "HEAD", "GET", "PATCH", "POST", "PUT", "DELETE",
|
||||
"TRACE");
|
||||
assertThat(configuration.getMaxAge()).isEqualTo(1800L);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package org.springframework.data.rest.webmvc.json;
|
||||
|
||||
import static com.fasterxml.jackson.annotation.JsonProperty.Access.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -38,6 +36,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Immutable;
|
||||
@@ -210,9 +209,9 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
SampleUser result = reader.readPut(node, sampleUser, mapper);
|
||||
|
||||
assertThat(result.name, is("another"));
|
||||
assertThat(result.password, notNullValue());
|
||||
assertThat(result.lastLogin, notNullValue());
|
||||
assertThat(result.name).isEqualTo("another");
|
||||
assertThat(result.password).isNotNull();
|
||||
assertThat(result.lastLogin).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-873
|
||||
@@ -487,7 +486,7 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
CollectionOfEnumWithMethods result = reader.merge((ObjectNode) node, sample, mapper);
|
||||
|
||||
assertThat(result.enums, contains(SampleEnum.SECOND, SampleEnum.FIRST));
|
||||
assertThat(result.enums).containsExactly(SampleEnum.SECOND, SampleEnum.FIRST);
|
||||
}
|
||||
|
||||
@Test // DATAREST-944
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.json;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -25,6 +23,7 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.rest.webmvc.json.JacksonSerializersUnitTests.Sample.SampleEnum;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -70,7 +69,7 @@ public class JacksonSerializersUnitTests {
|
||||
|
||||
Sample result = mapper.readValue("{ \"array\" : [ \"value\" ] }", Sample.class);
|
||||
|
||||
assertThat(result.array, hasItemInArray(SampleEnum.VALUE));
|
||||
assertThat(result.array).contains(SampleEnum.VALUE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-929
|
||||
|
||||
Reference in New Issue
Block a user