#647 - Switch to AssertJ and upgrade to Mockito 2.

This commit is contained in:
Oliver Gierke
2017-10-13 18:39:55 +02:00
parent b862919868
commit 35033fee0e
59 changed files with 697 additions and 736 deletions

18
pom.xml
View File

@@ -500,13 +500,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -523,8 +516,15 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<artifactId>mockito-core</artifactId>
<version>2.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>

View File

@@ -47,7 +47,7 @@ public class Hop {
/**
* Collection of URI Template parameters.
*/
private final @Wither Map<String, ? extends Object> parameters;
private final @Wither Map<String, Object> parameters;
/**
* Creates a new {@link Hop} for the given relation name.

View File

@@ -56,7 +56,7 @@ public class HeaderLinksResponseEntity<T extends ResourceSupport> extends Respon
* @param entity must not be {@literal null}.
*/
private HeaderLinksResponseEntity(HttpEntity<T> entity) {
this(new ResponseEntity<T>(entity.getBody(), entity.getHeaders(), HttpStatus.OK));
this(ResponseEntity.ok().headers(entity.getHeaders()).body(entity.getBody()));
}
/**
@@ -77,6 +77,20 @@ public class HeaderLinksResponseEntity<T extends ResourceSupport> extends Respon
}
}
/**
* Wraps the given {@link ResourceSupport} into a {@link HeaderLinksResponseEntity}. Will default the status code to
* {@link HttpStatus#OK}.
*
* @param entity must not be {@literal null}.
* @return
*/
public static <S extends ResourceSupport> HeaderLinksResponseEntity<S> wrap(S entity) {
Assert.notNull(entity, "ResourceSupport must not be null!");
return new HeaderLinksResponseEntity<>(ResponseEntity.ok(entity));
}
/**
* Returns the {@link Link}s contained in the {@link ResourceSupport} of the given {@link ResponseEntity} as
* {@link HttpHeaders}.

View File

@@ -126,7 +126,7 @@ public class ResourceProcessorHandlerMethodReturnValueHandler implements Handler
Object rewrapResult(ResourceSupport newBody, Object originalValue) {
if (!(originalValue instanceof HttpEntity)) {
return newBody;
return rootLinksAsHeaders ? HeaderLinksResponseEntity.wrap(newBody) : newBody;
}
HttpEntity<ResourceSupport> entity = null;
@@ -139,10 +139,6 @@ public class ResourceProcessorHandlerMethodReturnValueHandler implements Handler
entity = new HttpEntity<ResourceSupport>(newBody, source.getHeaders());
}
return addLinksToHeaderWrapper(entity);
}
private HttpEntity<?> addLinksToHeaderWrapper(HttpEntity<ResourceSupport> entity) {
return rootLinksAsHeaders ? HeaderLinksResponseEntity.wrap(entity) : entity;
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
@@ -35,7 +34,7 @@ public class Jackson2LinkIntegrationTest extends AbstractJackson2MarshallingInte
*/
@Test
public void writesLinkCorrectly() throws Exception {
assertThat(write(new Link("location", "something")), is(REFERENCE));
assertThat(write(new Link("location", "something"))).isEqualTo(REFERENCE);
}
/**
@@ -44,7 +43,7 @@ public class Jackson2LinkIntegrationTest extends AbstractJackson2MarshallingInte
@Test
public void readsLinkCorrectly() throws Exception {
Link result = read(REFERENCE, Link.class);
assertThat(result.getHref(), is("location"));
assertThat(result.getRel(), is("something"));
assertThat(result.getHref()).isEqualTo("location");
assertThat(result.getRel()).isEqualTo("something");
}
}

View File

@@ -15,8 +15,8 @@
*/
package org.springframework.hateoas;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.io.StringWriter;
@@ -80,7 +80,7 @@ public class Jackson2PagedResourcesIntegrationTest {
ReflectionUtils.invokeMethod(SPRING_4_2_WRITE_METHOD, converter, resources, method.getGenericReturnType(),
MediaType.APPLICATION_JSON, outputMessage);
assertThat(writer.toString(), is(REFERENCE));
assertThat(writer.toString()).isEqualTo(REFERENCE);
}
interface Sample {

View File

@@ -1,7 +1,6 @@
package org.springframework.hateoas;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
@@ -31,7 +30,7 @@ public class Jackson2ResourceIntegrationTest extends AbstractJackson2Marshalling
Resource<Person> resource = new Resource<Person>(person);
resource.add(new Link("localhost"));
assertThat(write(resource), is(REFERENCE));
assertThat(write(resource)).isEqualTo(REFERENCE);
}
/**
@@ -42,10 +41,10 @@ public class Jackson2ResourceIntegrationTest extends AbstractJackson2Marshalling
PersonResource result = read(REFERENCE, PersonResource.class);
assertThat(result.getLinks(), hasSize(1));
assertThat(result.getLinks(), hasItem(new Link("localhost")));
assertThat(result.getContent().firstname, is("Dave"));
assertThat(result.getContent().lastname, is("Matthews"));
assertThat(result.getLinks()).hasSize(1);
assertThat(result.getLinks()).contains(new Link("localhost"));
assertThat(result.getContent().firstname).isEqualTo("Dave");
assertThat(result.getContent().lastname).isEqualTo("Matthews");
}
static class PersonResource extends Resource<Person> {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
@@ -38,7 +37,7 @@ public class Jackson2ResourceSupportIntegrationTest extends AbstractJackson2Mars
ResourceSupport resourceSupport = new ResourceSupport();
resourceSupport.add(new Link("localhost"));
assertThat(write(resourceSupport), is(REFERENCE));
assertThat(write(resourceSupport)).isEqualTo(REFERENCE);
}
/**
@@ -49,7 +48,7 @@ public class Jackson2ResourceSupportIntegrationTest extends AbstractJackson2Mars
ResourceSupport result = read(REFERENCE, ResourceSupport.class);
assertThat(result.getLinks(), hasSize(1));
assertThat(result.getLinks(), hasItem(new Link("localhost")));
assertThat(result.getLinks()).hasSize(1);
assertThat(result.getLinks()).contains(new Link("localhost"));
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
@@ -46,7 +45,7 @@ public class LinkDiscoverersUnitTest {
LinkDiscoverer high = new HighPriorityLinkDiscoverer();
PluginRegistry<LinkDiscoverer, MediaType> registry = OrderAwarePluginRegistry.create(Arrays.asList(low, high));
assertThat(registry.getRequiredPluginFor(MediaType.APPLICATION_JSON), is(high));
assertThat(registry.getRequiredPluginFor(MediaType.APPLICATION_JSON)).isEqualTo(high);
}
@Order(20)

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
@@ -34,7 +33,7 @@ public class LinkIntegrationTest extends AbstractJackson2MarshallingIntegrationT
*/
@Test
public void writesLinkCorrectly() throws Exception {
assertThat(write(new Link("location", "something")), is(REFERENCE));
assertThat(write(new Link("location", "something"))).isEqualTo(REFERENCE);
}
/**
@@ -44,7 +43,7 @@ public class LinkIntegrationTest extends AbstractJackson2MarshallingIntegrationT
public void readsLinkCorrectly() throws Exception {
Link result = read(REFERENCE, Link.class);
assertThat(result.getHref(), is("location"));
assertThat(result.getRel(), is("something"));
assertThat(result.getHref()).isEqualTo("location");
assertThat(result.getRel()).isEqualTo("something");
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.io.IOException;
import java.io.ObjectOutputStream;
@@ -35,14 +34,14 @@ public class LinkUnitTest {
@Test
public void linkWithHrefOnlyBecomesSelfLink() {
Link link = new Link("foo");
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
}
@Test
public void createsLinkFromRelAndHref() {
Link link = new Link("foo", Link.REL_SELF);
assertThat(link.getHref(), is("foo"));
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref()).isEqualTo("foo");
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
}
@Test(expected = IllegalArgumentException.class)
@@ -94,14 +93,14 @@ public class LinkUnitTest {
@Test
public void differentTypeDoesNotEqual() {
assertThat(new Link("foo"), is(not((Object) new ResourceSupport())));
assertThat(new Link("foo")).isNotEqualTo((Object) new ResourceSupport());
}
@Test
public void returnsNullForNullOrEmptyLink() {
assertThat(Link.valueOf(null), is(nullValue()));
assertThat(Link.valueOf(""), is(nullValue()));
assertThat(Link.valueOf(null)).isNull();
assertThat(Link.valueOf("")).isNull();
}
/**
@@ -111,15 +110,21 @@ public class LinkUnitTest {
@Test
public void parsesRFC5988HeaderIntoLink() {
assertThat(Link.valueOf("</something>;rel=\"foo\""), is(new Link("/something", "foo")));
assertThat(Link.valueOf("</something>;rel=\"foo\";title=\"Some title\""), is(new Link("/something", "foo")));
assertThat(Link.valueOf("</customer/1>;rel=\"self\";hreflang=\"en\";media=\"pdf\";title=\"pdf customer copy\";type=\"portable document\";deprecation=\"http://example.com/customers/deprecated\""),
is(new Link("/customer/1")
.withHreflang("en")
.withMedia("pdf")
.withTitle("pdf customer copy")
.withType("portable document")
.withDeprecation("http://example.com/customers/deprecated")));
assertThat(Link.valueOf("</something>;rel=\"foo\"")).isEqualTo(new Link("/something", "foo"));
assertThat(Link.valueOf("</something>;rel=\"foo\";title=\"Some title\"")).isEqualTo(new Link("/something", "foo"));
assertThat(Link.valueOf("</customer/1>;" //
+ "rel=\"self\";" //
+ "hreflang=\"en\";" //
+ "media=\"pdf\";" //
+ "title=\"pdf customer copy\";" //
+ "type=\"portable document\";" //
+ "deprecation=\"http://example.com/customers/deprecated\"")) //
.isEqualTo(new Link("/customer/1") //
.withHreflang("en") //
.withMedia("pdf") //
.withTitle("pdf customer copy") //
.withType("portable document") //
.withDeprecation("http://example.com/customers/deprecated"));
}
/**
@@ -129,8 +134,8 @@ public class LinkUnitTest {
public void ignoresUnrecognizedAttributes() {
Link link = Link.valueOf("</something>;rel=\"foo\";unknown=\"should fail\"");
assertThat(link.getHref(), is("/something"));
assertThat(link.getRel(), is("foo"));
assertThat(link.getHref()).isEqualTo("/something");
assertThat(link.getRel()).isEqualTo("foo");
}
@Test(expected = IllegalArgumentException.class)
@@ -159,10 +164,10 @@ public class LinkUnitTest {
Link link = new Link("/foo{?page}");
assertThat(link.isTemplated(), is(true));
assertThat(link.getVariableNames(), hasSize(1));
assertThat(link.getVariableNames(), hasItem("page"));
assertThat(link.expand("2"), is(new Link("/foo?page=2")));
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).hasSize(1);
assertThat(link.getVariableNames()).contains("page");
assertThat(link.expand("2")).isEqualTo(new Link("/foo?page=2"));
}
/**
@@ -173,8 +178,8 @@ public class LinkUnitTest {
Link link = new Link("/foo");
assertThat(link.isTemplated(), is(false));
assertThat(link.getVariableNames(), hasSize(0));
assertThat(link.isTemplated()).isFalse();
assertThat(link.getVariableNames()).hasSize(0);
}
/**
@@ -197,7 +202,7 @@ public class LinkUnitTest {
public void keepsCompleteBaseUri() {
Link link = new Link("/customer/{customerId}/programs", "programs");
assertThat(link.getHref(), is("/customer/{customerId}/programs"));
assertThat(link.getHref()).isEqualTo("/customer/{customerId}/programs");
}
/**
@@ -205,7 +210,8 @@ public class LinkUnitTest {
*/
@Test
public void parsesLinkRelationWithDotAndMinus() {
assertThat(Link.valueOf("<http://localhost>; rel=\"rel-with-minus-and-.\"").getRel(), is("rel-with-minus-and-."));
assertThat(Link.valueOf("<http://localhost>; rel=\"rel-with-minus-and-.\"").getRel())
.isEqualTo("rel-with-minus-and-.");
}
/**
@@ -214,7 +220,7 @@ public class LinkUnitTest {
@Test
public void parsesUriLinkRelations() {
assertThat(Link.valueOf("<http://localhost>; rel=\"http://acme.com/rels/foo-bar\"").getRel(),
is("http://acme.com/rels/foo-bar"));
assertThat(Link.valueOf("<http://localhost>; rel=\"http://acme.com/rels/foo-bar\"").getRel()) //
.isEqualTo("http://acme.com/rels/foo-bar");
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
@@ -43,28 +42,29 @@ public class LinksUnitTest {
static final String LINKS2 = StringUtils.collectionToCommaDelimitedString(Arrays.asList(THIRD, FOURTH));
static final Links reference = new Links(new Link("/something", "foo"), new Link("/somethingElse", "bar"));
static final Links reference2 = new Links(new Link("/something", "foo").withHreflang("en"), new Link("/somethingElse", "bar").withHreflang("de"));
static final Links reference2 = new Links(new Link("/something", "foo").withHreflang("en"),
new Link("/somethingElse", "bar").withHreflang("de"));
@Test
public void parsesLinkHeaderLinks() {
assertThat(Links.valueOf(LINKS), is(reference));
assertThat(Links.valueOf(LINKS2), is(reference2));
assertThat(reference.toString(), is(LINKS));
assertThat(reference2.toString(), is(LINKS2));
assertThat(Links.valueOf(LINKS)).isEqualTo(reference);
assertThat(Links.valueOf(LINKS2)).isEqualTo(reference2);
assertThat(reference.toString()).isEqualTo(LINKS);
assertThat(reference2.toString()).isEqualTo(LINKS2);
}
@Test
public void skipsEmptyLinkElements() {
assertThat(Links.valueOf(LINKS + ",,,"), is(reference));
assertThat(Links.valueOf(LINKS2 + ",,,"), is(reference2));
assertThat(Links.valueOf(LINKS + ",,,")).isEqualTo(reference);
assertThat(Links.valueOf(LINKS2 + ",,,")).isEqualTo(reference2);
}
@Test
public void returnsNullForNullOrEmptySource() {
assertThat(Links.valueOf(null), is(Links.NO_LINKS));
assertThat(Links.valueOf(""), is(Links.NO_LINKS));
assertThat(Links.valueOf(null)).isEqualTo(Links.NO_LINKS);
assertThat(Links.valueOf("")).isEqualTo(Links.NO_LINKS);
}
/**
@@ -73,8 +73,8 @@ public class LinksUnitTest {
*/
@Test
public void getSingleLinkByRel() {
assertThat(reference.getLink("bar"), is(new Link("/somethingElse", "bar")));
assertThat(reference2.getLink("bar"), is(new Link("/somethingElse", "bar").withHreflang("de")));
assertThat(reference.getLink("bar")).isEqualTo(new Link("/somethingElse", "bar"));
assertThat(reference2.getLink("bar")).isEqualTo(new Link("/somethingElse", "bar").withHreflang("de"));
}
/**
@@ -85,11 +85,11 @@ public class LinksUnitTest {
Link withComma = new Link("http://localhost:8080/test?page=0&filter=foo,bar", "foo");
assertThat(Links.valueOf(WITH_COMMA).getLink("foo"), is(withComma));
assertThat(Links.valueOf(WITH_COMMA).getLink("foo")).isEqualTo(withComma);
Links twoWithCommaInFirst = Links.valueOf(WITH_COMMA.concat(",").concat(SECOND));
assertThat(twoWithCommaInFirst.getLink("foo"), is(withComma));
assertThat(twoWithCommaInFirst.getLink("bar"), is(new Link("/somethingElse", "bar")));
assertThat(twoWithCommaInFirst.getLink("foo")).isEqualTo(withComma);
assertThat(twoWithCommaInFirst.getLink("bar")).isEqualTo(new Link("/somethingElse", "bar"));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2017 the 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,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.io.FileInputStream;
import java.io.IOException;
@@ -65,11 +64,9 @@ public class PagedResourcesMarshallingTest {
* @see #98
*/
@Test
@SuppressWarnings("unchecked")
public void jaxbUnMarshalling() throws Exception {
PagedResources<Inner> actual = (PagedResources<Inner>) unmarshaller.unmarshal(new StringReader(xmlReference));
assertThat(actual, is(pagedResources));
assertThat(unmarshaller.unmarshal(new StringReader(xmlReference))).isEqualTo(pagedResources);
}
public static class Inner {}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Collections;
@@ -45,7 +44,7 @@ public class PagedResourcesUnitTest {
resources.add(new Link("foo", Link.REL_NEXT));
assertThat(resources.getNextLink(), is(notNullValue()));
assertThat(resources.getNextLink()).isNotNull();
}
@Test
@@ -53,7 +52,7 @@ public class PagedResourcesUnitTest {
resources.add(new Link("custom", Link.REL_PREVIOUS));
assertThat(resources.getPreviousLink(), is(notNullValue()));
assertThat(resources.getPreviousLink()).isNotNull();
}
/**
@@ -101,6 +100,6 @@ public class PagedResourcesUnitTest {
*/
@Test
public void calculatesTotalPagesCorrectly() {
assertThat(new PageMetadata(5, 0, 16).getTotalPages(), is(4L));
assertThat(new PageMetadata(5, 0, 16).getTotalPages()).isEqualTo(4L);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.io.StringWriter;
@@ -51,7 +50,7 @@ public class ResourceIntegrationTest extends AbstractJackson2MarshallingIntegrat
Resource<Person> resource = new Resource<Person>(person);
resource.add(new Link("localhost"));
assertThat(write(resource), is(REFERENCE));
assertThat(write(resource)).isEqualTo(REFERENCE);
}
/**
@@ -74,7 +73,7 @@ public class ResourceIntegrationTest extends AbstractJackson2MarshallingIntegrat
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(resource, writer);
assertThat(new Diff(XML_REFERENCE, writer.toString()).similar(), is(true));
assertThat(new Diff(XML_REFERENCE, writer.toString()).similar()).isTrue();
}
/**
@@ -85,10 +84,10 @@ public class ResourceIntegrationTest extends AbstractJackson2MarshallingIntegrat
PersonResource result = read(REFERENCE, PersonResource.class);
assertThat(result.getLinks(), hasSize(1));
assertThat(result.getLinks(), hasItem(new Link("localhost")));
assertThat(result.getContent().firstname, is("Dave"));
assertThat(result.getContent().lastname, is("Matthews"));
assertThat(result.getLinks()).hasSize(1);
assertThat(result.getLinks()).contains(new Link("localhost"));
assertThat(result.getContent().firstname).isEqualTo("Dave");
assertThat(result.getContent().lastname).isEqualTo("Matthews");
}
@XmlRootElement

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
@@ -38,7 +37,7 @@ public class ResourceSupportIntegrationTest extends AbstractJackson2MarshallingI
ResourceSupport resourceSupport = new ResourceSupport();
resourceSupport.add(new Link("localhost"));
assertThat(write(resourceSupport), is(REFERENCE));
assertThat(write(resourceSupport)).isEqualTo(REFERENCE);
}
/**
@@ -49,7 +48,7 @@ public class ResourceSupportIntegrationTest extends AbstractJackson2MarshallingI
ResourceSupport result = read(REFERENCE, ResourceSupport.class);
assertThat(result.getLinks(), hasSize(1));
assertThat(result.getLinks(), hasItem(new Link("localhost")));
assertThat(result.getLinks()).hasSize(1);
assertThat(result.getLinks()).contains(new Link("localhost"));
}
}

View File

@@ -15,12 +15,10 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import org.hamcrest.Matchers;
import org.junit.Test;
/**
@@ -34,10 +32,10 @@ public class ResourceSupportUnitTest {
public void setsUpWithEmptyLinkList() {
ResourceSupport support = new ResourceSupport();
assertThat(support.hasLinks(), is(false));
assertThat(support.hasLink(Link.REL_SELF), is(false));
assertThat(support.getLinks().isEmpty(), is(true));
assertThat(support.getLinks(Link.REL_SELF).isEmpty(), is(true));
assertThat(support.hasLinks()).isFalse();
assertThat(support.hasLink(Link.REL_SELF)).isFalse();
assertThat(support.getLinks().isEmpty()).isTrue();
assertThat(support.getLinks(Link.REL_SELF).isEmpty()).isTrue();
}
@Test
@@ -47,11 +45,11 @@ public class ResourceSupportUnitTest {
ResourceSupport support = new ResourceSupport();
support.add(link);
assertThat(support.getId(), is(nullValue()));
assertThat(support.hasLinks(), is(true));
assertThat(support.hasLink(link.getRel()), is(true));
assertThat(support.getLink(link.getRel()), is(link));
assertThat(support.getLinks(Link.REL_NEXT), contains(link));
assertThat(support.getId()).isNull();
assertThat(support.hasLinks()).isTrue();
assertThat(support.hasLink(link.getRel())).isTrue();
assertThat(support.getLink(link.getRel())).isEqualTo(link);
assertThat(support.getLinks(Link.REL_NEXT)).contains(link);
}
@Test
@@ -62,10 +60,10 @@ public class ResourceSupportUnitTest {
ResourceSupport support = new ResourceSupport();
support.add(link, link2);
assertThat(support.getLinks("customers").size(), is(2));
assertThat(support.getLinks("customers"), contains(link, link2));
assertThat(support.getLinks("non-existent").size(), is(0));
assertThat(support.getLinks("non-existent"), is(Matchers.<Link>empty()));
assertThat(support.getLinks("customers")).hasSize(2);
assertThat(support.getLinks("customers")).contains(link, link2);
assertThat(support.getLinks("non-existent")).hasSize(0);
assertThat(support.getLinks("non-existent")).isEmpty();
}
@Test
@@ -77,12 +75,12 @@ public class ResourceSupportUnitTest {
ResourceSupport support = new ResourceSupport();
support.add(Arrays.asList(first, second));
assertThat(support.getId(), is(nullValue()));
assertThat(support.hasLinks(), is(true));
assertThat(support.getLinks(), hasItems(first, second));
assertThat(support.getLinks().size(), is(2));
assertThat(support.getLinks(Link.REL_PREVIOUS), contains(first));
assertThat(support.getLinks(Link.REL_NEXT), contains(second));
assertThat(support.getId()).isNull();
assertThat(support.hasLinks()).isTrue();
assertThat(support.getLinks()).contains(first, second);
assertThat(support.getLinks()).hasSize(2);
assertThat(support.getLinks(Link.REL_PREVIOUS)).contains(first);
assertThat(support.getLinks(Link.REL_NEXT)).contains(second);
}
@Test
@@ -92,7 +90,7 @@ public class ResourceSupportUnitTest {
ResourceSupport support = new ResourceSupport();
support.add(link);
assertThat(support.getId(), is(link));
assertThat(support.getId()).isEqualTo(link);
}
@Test(expected = IllegalArgumentException.class)
@@ -160,7 +158,7 @@ public class ResourceSupportUnitTest {
public void doesNotEqualNull() {
ResourceSupport support = new ResourceSupport();
assertThat(support.equals(null), is(false));
assertThat(support.equals(null)).isFalse();
}
/**
@@ -172,7 +170,7 @@ public class ResourceSupportUnitTest {
ResourceSupport support = new ResourceSupport();
support.add(new Link("/self", "self"), new Link("/another", "another"));
assertThat(support.hasLink("self"), is(true));
assertThat(support.hasLink("another"), is(true));
assertThat(support.hasLink("self")).isTrue();
assertThat(support.hasLink("another")).isTrue();
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Collections;
@@ -33,7 +32,7 @@ public class ResourceUnitTest {
public void equalsForSelfReference() {
Resource<String> resource = new Resource<String>("foo");
assertThat(resource, is(resource));
assertThat(resource).isEqualTo(resource);
}
@Test
@@ -42,8 +41,8 @@ public class ResourceUnitTest {
Resource<String> left = new Resource<String>("foo");
Resource<String> right = new Resource<String>("foo");
assertThat(left, is(right));
assertThat(right, is(left));
assertThat(left).isEqualTo(right);
assertThat(right).isEqualTo(left);
}
@Test
@@ -52,8 +51,8 @@ public class ResourceUnitTest {
Resource<String> left = new Resource<String>("foo");
Resource<String> right = new Resource<String>("bar");
assertThat(left, is(not(right)));
assertThat(right, is(not(left)));
assertThat(left).isNotEqualTo(right);
assertThat(right).isNotEqualTo(left);
}
@Test
@@ -63,8 +62,8 @@ public class ResourceUnitTest {
Resource<String> right = new Resource<String>("foo");
right.add(new Link("localhost"));
assertThat(left, is(not(right)));
assertThat(right, is(not(left)));
assertThat(left).isNotEqualTo(right);
assertThat(right).isNotEqualTo(left);
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Collections;
import java.util.Set;
@@ -37,7 +36,7 @@ public class ResourcesUnitTest {
public void equalsForSelfReference() {
Resources<Resource<String>> resource = new Resources<Resource<String>>(foo);
assertThat(resource, is(resource));
assertThat(resource).isEqualTo(resource);
}
@Test
@@ -46,8 +45,8 @@ public class ResourcesUnitTest {
Resources<Resource<String>> left = new Resources<Resource<String>>(foo);
Resources<Resource<String>> right = new Resources<Resource<String>>(foo);
assertThat(left, is(right));
assertThat(right, is(left));
assertThat(left).isEqualTo(right);
assertThat(right).isEqualTo(left);
}
@Test
@@ -56,8 +55,8 @@ public class ResourcesUnitTest {
Resources<Resource<String>> left = new Resources<Resource<String>>(foo);
Resources<Resource<String>> right = new Resources<Resource<String>>(bar);
assertThat(left, is(not(right)));
assertThat(right, is(not(left)));
assertThat(left).isNotEqualTo(right);
assertThat(right).isNotEqualTo(left);
}
@Test
@@ -67,7 +66,7 @@ public class ResourcesUnitTest {
Resources<Resource<String>> right = new Resources<Resource<String>>(bar);
right.add(new Link("localhost"));
assertThat(left, is(not(right)));
assertThat(right, is(not(left)));
assertThat(left).isNotEqualTo(right);
assertThat(right).isNotEqualTo(left);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.hateoas.TemplateVariable.VariableType.*;
import java.util.List;
@@ -36,7 +35,7 @@ public class TemplateVariablesUnitTest {
*/
@Test
public void rendersNoTempalteVariablesAsEmptyString() {
assertThat(TemplateVariables.NONE.toString(), is(""));
assertThat(TemplateVariables.NONE.toString()).isEqualTo("");
}
/**
@@ -46,7 +45,7 @@ public class TemplateVariablesUnitTest {
public void rendersSingleVariableCorrectly() {
TemplateVariables variables = new TemplateVariables(new TemplateVariable("foo", SEGMENT));
assertThat(variables.toString(), is("{/foo}"));
assertThat(variables.toString()).isEqualTo("{/foo}");
}
/**
@@ -60,7 +59,7 @@ public class TemplateVariablesUnitTest {
TemplateVariables variables = new TemplateVariables(first, second);
assertThat(variables.toString(), is("{?foo,bar}"));
assertThat(variables.toString()).isEqualTo("{?foo,bar}");
}
/**
@@ -74,7 +73,7 @@ public class TemplateVariablesUnitTest {
TemplateVariables variables = new TemplateVariables(first, second);
assertThat(variables.toString(), is("{/foo}{?bar}"));
assertThat(variables.toString()).isEqualTo("{/foo}{?bar}");
}
/**
@@ -86,7 +85,7 @@ public class TemplateVariablesUnitTest {
TemplateVariables variables = new TemplateVariables(new TemplateVariable("foo", SEGMENT));
variables = variables.concat(new TemplateVariable("bar", REQUEST_PARAM));
assertThat(variables.toString(), is("{/foo}{?bar}"));
assertThat(variables.toString()).isEqualTo("{/foo}{?bar}");
}
/**
@@ -100,7 +99,7 @@ public class TemplateVariablesUnitTest {
TemplateVariables variables = new TemplateVariables(first, second);
assertThat(variables.toString(), is("{?foo,bar}"));
assertThat(variables.toString()).isEqualTo("{?foo,bar}");
}
/**
@@ -114,7 +113,7 @@ public class TemplateVariablesUnitTest {
TemplateVariables variables = new TemplateVariables(first, second);
assertThat(variables.toString(), is("{&foo,bar}"));
assertThat(variables.toString()).isEqualTo("{&foo,bar}");
}
/**
@@ -128,8 +127,8 @@ public class TemplateVariablesUnitTest {
List<TemplateVariable> result = variables.concat(variable).asList();
assertThat(result, hasSize(1));
assertThat(result, hasItem(variable));
assertThat(result).hasSize(1);
assertThat(result).contains(variable);
}
/**
@@ -142,9 +141,9 @@ public class TemplateVariablesUnitTest {
TemplateVariable continued = new TemplateVariable("foo", REQUEST_PARAM_CONTINUED);
TemplateVariable fragment = new TemplateVariable("foo", FRAGMENT);
assertThat(parameter.isEquivalent(continued), is(true));
assertThat(continued.isEquivalent(parameter), is(true));
assertThat(fragment.isEquivalent(continued), is(false));
assertThat(parameter.isEquivalent(continued)).isTrue();
assertThat(continued.isEquivalent(parameter)).isTrue();
assertThat(fragment.isEquivalent(continued)).isFalse();
}
/**
@@ -153,8 +152,8 @@ public class TemplateVariablesUnitTest {
@Test
public void considersFragementVariable() {
assertThat(new TemplateVariable("foo", VariableType.FRAGMENT).isFragment(), is(true));
assertThat(new TemplateVariable("foo", VariableType.REQUEST_PARAM).isFragment(), is(false));
assertThat(new TemplateVariable("foo", VariableType.FRAGMENT).isFragment()).isTrue();
assertThat(new TemplateVariable("foo", VariableType.REQUEST_PARAM).isFragment()).isFalse();
}
/**
@@ -168,8 +167,8 @@ public class TemplateVariablesUnitTest {
List<TemplateVariable> result = new TemplateVariables(parameter).concat(parameterContinued).asList();
assertThat(result, hasSize(1));
assertThat(result, hasItem(parameter));
assertThat(result).hasSize(1);
assertThat(result).contains(parameter);
}
/**

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Before;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -24,7 +23,7 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
* Utility class to ease tesing.
* Utility class to ease testing.
*
* @author Oliver Gierke
*/
@@ -41,23 +40,23 @@ public class TestUtils {
}
protected void assertPointsToMockServer(Link link) {
assertThat(link.getHref(), startsWith("http://localhost"));
assertThat(link.getHref()).startsWith("http://localhost");
}
public static void assertEqualAndSameHashCode(Object left, Object right) {
assertThat(left, is(right));
assertThat(right, is(left));
assertThat(left, is(left));
assertThat(left.hashCode(), is(right.hashCode()));
assertThat(left.toString(), is(right.toString()));
assertThat(left).isEqualTo(right);
assertThat(right).isEqualTo(left);
assertThat(left).isEqualTo(left);
assertThat(left.hashCode()).isEqualTo(right.hashCode());
assertThat(left.toString()).isEqualTo(right.toString());
}
public static void assertNotEqualAndDifferentHashCode(Object left, Object right) {
assertThat(left, is(not(right)));
assertThat(right, is(not(left)));
assertThat(left.hashCode(), is(not(right.hashCode())));
assertThat(left.toString(), is(not(right.toString())));
assertThat(left).isNotEqualTo(right);
assertThat(right).isNotEqualTo(left);
assertThat(left.hashCode()).isNotEqualTo(right.hashCode());
assertThat(left.toString()).isNotEqualTo(right.toString());
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.net.URI;
import java.util.ArrayList;
@@ -43,10 +42,10 @@ public class UriTemplateUnitTest {
@Test
public void discoversTemplate() {
assertThat(UriTemplate.isTemplate("/foo{?bar}"), is(true));
assertThat(UriTemplate.isTemplate("/foo"), is(false));
assertThat(UriTemplate.isTemplate(null), is(false));
assertThat(UriTemplate.isTemplate(""), is(false));
assertThat(UriTemplate.isTemplate("/foo{?bar}")).isTrue();
assertThat(UriTemplate.isTemplate("/foo")).isFalse();
assertThat(UriTemplate.isTemplate(null)).isFalse();
assertThat(UriTemplate.isTemplate("")).isFalse();
}
/**
@@ -112,8 +111,8 @@ public class UriTemplateUnitTest {
UriTemplate template = new UriTemplate("/foo{?bar,foobar}");
assertVariables(template, new TemplateVariable("bar", VariableType.REQUEST_PARAM), new TemplateVariable("foobar",
VariableType.REQUEST_PARAM));
assertVariables(template, new TemplateVariable("bar", VariableType.REQUEST_PARAM),
new TemplateVariable("foobar", VariableType.REQUEST_PARAM));
}
/**
@@ -125,7 +124,7 @@ public class UriTemplateUnitTest {
UriTemplate template = new UriTemplate("/foo{?bar}");
URI uri = template.expand(Collections.singletonMap("bar", "myBar"));
assertThat(uri.toString(), is("/foo?bar=myBar"));
assertThat(uri.toString()).isEqualTo("/foo?bar=myBar");
}
/**
@@ -141,7 +140,7 @@ public class UriTemplateUnitTest {
UriTemplate template = new UriTemplate("/foo{?bar,fooBar}");
URI uri = template.expand(parameters);
assertThat(uri.toString(), is("/foo?bar=myBar&fooBar=myFooBar"));
assertThat(uri.toString()).isEqualTo("/foo?bar=myBar&fooBar=myFooBar");
}
/**
@@ -162,7 +161,7 @@ public class UriTemplateUnitTest {
UriTemplate template = new UriTemplate("/foo{/bar}{?firstname,lastname}{#anchor}");
URI uri = template.expand("path", "Dave", "Matthews", "discography");
assertThat(uri.toString(), is("/foo/path?firstname=Dave&lastname=Matthews#discography"));
assertThat(uri.toString()).isEqualTo("/foo/path?firstname=Dave&lastname=Matthews#discography");
}
/**
@@ -170,7 +169,7 @@ public class UriTemplateUnitTest {
*/
@Test
public void expandsTemplateWithoutVariablesCorrectly() {
assertThat(new UriTemplate("/foo").expand().toString(), is("/foo"));
assertThat(new UriTemplate("/foo").expand().toString()).isEqualTo("/foo");
}
/**
@@ -178,7 +177,8 @@ public class UriTemplateUnitTest {
*/
@Test
public void correctlyExpandsFullUri() {
assertThat(new UriTemplate("http://localhost:8080/foo{?bar}").expand().toString(), is("http://localhost:8080/foo"));
assertThat(new UriTemplate("http://localhost:8080/foo{?bar}").expand().toString())
.isEqualTo("http://localhost:8080/foo");
}
/**
@@ -188,7 +188,7 @@ public class UriTemplateUnitTest {
public void rendersUriTempalteWithPathVariable() {
UriTemplate template = new UriTemplate("/{foo}/bar{?page}");
assertThat(template.toString(), is("/{foo}/bar{?page}"));
assertThat(template.toString()).isEqualTo("/{foo}/bar{?page}");
}
/**
@@ -215,10 +215,10 @@ public class UriTemplateUnitTest {
UriTemplate template = new UriTemplate("/?page=2");
UriTemplate result = template.with(new TemplateVariables(new TemplateVariable("page", VariableType.REQUEST_PARAM)));
assertThat(result.getVariableNames(), is(empty()));
assertThat(result.getVariableNames()).isEmpty();
result = template.with(new TemplateVariables(new TemplateVariable("page", VariableType.REQUEST_PARAM_CONTINUED)));
assertThat(result.getVariableNames(), is(empty()));
assertThat(result.getVariableNames()).isEmpty();
}
/**
@@ -229,7 +229,7 @@ public class UriTemplateUnitTest {
UriTemplate template = new UriTemplate("/#fragment");
UriTemplate result = template.with(new TemplateVariables(new TemplateVariable("fragment", VariableType.FRAGMENT)));
assertThat(result.getVariableNames(), is(empty()));
assertThat(result.getVariableNames()).isEmpty();
}
/**
@@ -239,7 +239,7 @@ public class UriTemplateUnitTest {
public void expandASimplePathVariable() {
UriTemplate template = new UriTemplate("/foo/{id}");
assertThat(template.expand(2).toString(), is("/foo/2"));
assertThat(template.expand(2).toString()).isEqualTo("/foo/2");
}
/**
@@ -258,7 +258,7 @@ public class UriTemplateUnitTest {
UriTemplate template = new UriTemplate("/").with("q", VariableType.REQUEST_PARAM);
assertThat(template.toString(), is("/{?q}"));
assertThat(template.toString()).isEqualTo("/{?q}");
}
private static void assertVariables(UriTemplate template, TemplateVariable... variables) {
@@ -267,13 +267,13 @@ public class UriTemplateUnitTest {
private static void assertVariables(UriTemplate template, Collection<TemplateVariable> variables) {
assertThat(template.getVariableNames(), hasSize(variables.size()));
assertThat(template.getVariables(), hasSize(variables.size()));
assertThat(template.getVariableNames()).hasSize(variables.size());
assertThat(template.getVariables()).hasSize(variables.size());
for (TemplateVariable variable : variables) {
assertThat(template, hasItem(variable));
assertThat(template.getVariableNames(), hasItems(variable.getName()));
assertThat(template).contains(variable);
assertThat(template.getVariableNames()).contains(variable.getName());
}
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.io.FileInputStream;
import java.io.IOException;
@@ -89,7 +88,7 @@ public class VndErrorsMarshallingTest {
*/
@Test
public void jackson2Marshalling() throws Exception {
assertThat(jackson2Mapper.writeValueAsString(errors), equalToIgnoringWhiteSpace(json2Reference));
assertThat(jackson2Mapper.writeValueAsString(errors)).isEqualToIgnoringWhitespace(json2Reference);
}
/**
@@ -101,7 +100,7 @@ public class VndErrorsMarshallingTest {
Writer writer = new StringWriter();
marshaller.marshal(errors, writer);
assertThat(new Diff(xmlReference, writer.toString()).similar(), is(true));
assertThat(new Diff(xmlReference, writer.toString()).similar()).isTrue();
}
/**
@@ -109,7 +108,7 @@ public class VndErrorsMarshallingTest {
*/
@Test
public void jackson2UnMarshalling() throws Exception {
assertThat(jackson2Mapper.readValue(jsonReference, VndErrors.class), is(errors));
assertThat(jackson2Mapper.readValue(jsonReference, VndErrors.class)).isEqualTo(errors);
}
/**
@@ -118,7 +117,7 @@ public class VndErrorsMarshallingTest {
@Test
public void jaxbUnMarshalling() throws Exception {
VndErrors actual = (VndErrors) unmarshaller.unmarshal(new StringReader(xmlReference));
assertThat(actual, is(errors));
assertThat(actual).isEqualTo(errors);
}
private static String readFile(org.springframework.core.io.Resource resource) throws IOException {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.hateoas.VndErrors.VndError;
@@ -32,10 +31,10 @@ public class VndErrorsUnitTest {
public void rendersToStringCorrectly() {
VndError error = new VndErrors.VndError("logref", "message", new Link("foo", "bar"));
assertThat(error.toString(), is("VndError[logref: logref, message: message, links: [<foo>;rel=\"bar\"]]"));
assertThat(error.toString()).isEqualTo("VndError[logref: logref, message: message, links: [<foo>;rel=\"bar\"]]");
VndErrors errors = new VndErrors(error);
assertThat(errors.toString(),
is("VndErrors[VndError[logref: logref, message: message, links: [<foo>;rel=\"bar\"]]]"));
assertThat(errors.toString()) //
.isEqualTo("VndErrors[VndError[logref: logref, message: message, links: [<foo>;rel=\"bar\"]]]");
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.alps;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.io.IOException;
import java.nio.charset.Charset;
@@ -43,8 +42,8 @@ public class AlpsLinkDiscoverUnitTest extends AbstractLinkDiscovererUnitTest {
Link link = getDiscoverer().findLinkWithRel("http://foo.com/bar", getInputString());
assertThat(link, is(notNullValue()));
assertThat(link.getHref(), is("fullRelHref"));
assertThat(link).isNotNull();
assertThat(link.getHref()).isEqualTo("fullRelHref");
}
/**

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.alps;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.hateoas.alps.Alps.*;
import java.io.IOException;
@@ -70,7 +69,7 @@ public class JacksonSerializationTest {
).build())//
).build();
assertThat(mapper.writeValueAsString(alps), is(read(new ClassPathResource("reference.json", getClass()))));
assertThat(mapper.writeValueAsString(alps)).isEqualTo(read(new ClassPathResource("reference.json", getClass())));
}
private static String read(Resource resource) throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2017 the 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,8 +15,7 @@
*/
package org.springframework.hateoas.client;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Collections;
import java.util.Map;
@@ -52,7 +51,7 @@ public class HopUnitTest {
*/
@Test
public void hasNoParametersByDefault() {
assertThat(Hop.rel("rel").getParameters().entrySet(), is(empty()));
assertThat(Hop.rel("rel").getParameters()).isEmpty();
}
/**
@@ -63,8 +62,8 @@ public class HopUnitTest {
Hop hop = Hop.rel("rel").withParameter("key", "value");
assertThat(hop.getParameters(), hasEntry("key", (Object) "value"));
assertThat(hop.getParameters().entrySet(), hasSize(1));
assertThat(hop.getParameters()).hasSize(1) //
.containsEntry("key", "value");
}
/**
@@ -73,11 +72,10 @@ public class HopUnitTest {
@Test
public void replacesParametersForWither() {
Hop hop = Hop.rel("rel").withParameter("key", "value")
.withParameters(Collections.<String, Object> singletonMap("foo", "bar"));
Hop hop = Hop.rel("rel").withParameter("key", "value").withParameters(Collections.singletonMap("foo", "bar"));
assertThat(hop.getParameters().entrySet(), hasSize(1));
assertThat(hop.getParameters(), hasEntry("foo", (Object) "bar"));
assertThat(hop.getParameters()).hasSize(1) //
.containsEntry("foo", (Object) "bar");
}
/**
@@ -88,10 +86,9 @@ public class HopUnitTest {
Hop hop = Hop.rel("rel").withParameter("key", "value");
Map<String, Object> result = hop.getMergedParameters(Collections.<String, Object> singletonMap("foo", "bar"));
assertThat(result.entrySet(), hasSize(2));
assertThat(result, allOf(hasEntry("key", (Object) "value"), hasEntry("foo", (Object) "bar")));
assertThat(hop.getMergedParameters(Collections.singletonMap("foo", "bar"))).hasSize(2)//
.containsEntry("key", "value")//
.containsEntry("foo", "bar");
}
/**
@@ -104,7 +101,7 @@ public class HopUnitTest {
Map<String, Object> result = hop.getMergedParameters(Collections.singletonMap("key", (Object) "global"));
assertThat(result.entrySet(), hasSize(1));
assertThat(result, hasEntry("key", (Object) "value"));
assertThat(result).hasSize(1) //
.containsEntry("key", "value");
}
}

View File

@@ -63,11 +63,10 @@ public class Server implements Closeable {
this.mapper.registerModule(new Jackson2HalModule());
this.mapper.setHandlerInstantiator(new Jackson2HalModule.HalHandlerInstantiator(relProvider, null, null));
initJadler(). //
that().//
respondsWithDefaultContentType(MediaTypes.HAL_JSON.toString()). //
respondsWithDefaultStatus(200).//
respondsWithDefaultEncoding(Charset.forName("UTF-8"));
initJadler() //
.withDefaultResponseContentType(MediaTypes.HAL_JSON.toString()) //
.withDefaultResponseEncoding(Charset.forName("UTF-8")) //
.withDefaultResponseStatus(200);
onRequest(). //
havingPathEqualTo("/"). //
@@ -97,10 +96,14 @@ public class Server implements Closeable {
withContentType(MediaTypes.HAL_JSON.toString());
// Sample traversal of HAL docs based on Spring-a-Gram showcase
org.springframework.core.io.Resource springagramRoot = resourceLoader.getResource("classpath:springagram-root.json");
org.springframework.core.io.Resource springagramItems = resourceLoader.getResource("classpath:springagram-items.json");
org.springframework.core.io.Resource springagramItem = resourceLoader.getResource("classpath:springagram-item.json");
org.springframework.core.io.Resource springagramItemWithoutImage = resourceLoader.getResource("classpath:springagram-item-without-image.json");
org.springframework.core.io.Resource springagramRoot = resourceLoader
.getResource("classpath:springagram-root.json");
org.springframework.core.io.Resource springagramItems = resourceLoader
.getResource("classpath:springagram-items.json");
org.springframework.core.io.Resource springagramItem = resourceLoader
.getResource("classpath:springagram-item.json");
org.springframework.core.io.Resource springagramItemWithoutImage = resourceLoader
.getResource("classpath:springagram-item-without-image.json");
String springagramRootTemplate;
String springagramItemsTemplate;
@@ -118,7 +121,8 @@ public class Server implements Closeable {
}
String springagramRootHalDocument = String.format(springagramRootTemplate, rootResource(), rootResource());
String springagramItemsHalDocument = String.format(springagramItemsTemplate, rootResource(), rootResource(), rootResource());
String springagramItemsHalDocument = String.format(springagramItemsTemplate, rootResource(), rootResource(),
rootResource());
String springagramItemHalDocument = String.format(springagramItemTemplate, rootResource(), rootResource());
String springagramItemWithoutImageHalDocument = String.format(springagramItemWithoutImageTemplate, rootResource());

View File

@@ -16,8 +16,8 @@
package org.springframework.hateoas.client;
import static net.jadler.Jadler.*;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.hateoas.client.Hop.*;
import java.io.IOException;
@@ -113,7 +113,7 @@ public class TraversonTest {
*/
@Test
public void readsTraversalIntoJsonPathExpression() {
assertThat(traverson.follow("movies", "movie", "actor").<String> toObject("$.name"), is("Keanu Reaves"));
assertThat(traverson.follow("movies", "movie", "actor").<String> toObject("$.name")).isEqualTo("Keanu Reaves");
}
/**
@@ -124,7 +124,8 @@ public class TraversonTest {
assertThat(traverson.follow(//
"$._links.movies.href", //
"$._links.movie.href", //
"$._links.actor.href").<String> toObject("$.name"), is("Keanu Reaves"));
"$._links.actor.href").<String> toObject("$.name")) //
.isEqualTo("Keanu Reaves");
}
/**
@@ -136,7 +137,7 @@ public class TraversonTest {
ParameterizedTypeReference<Resource<Actor>> typeReference = new ParameterizedTypeReference<Resource<Actor>>() {};
Resource<Actor> result = traverson.follow("movies", "movie", "actor").toObject(typeReference);
assertThat(result.getContent().name, is("Keanu Reaves"));
assertThat(result.getContent().name).isEqualTo("Keanu Reaves");
}
/**
@@ -150,12 +151,12 @@ public class TraversonTest {
HttpHeaders headers = new HttpHeaders();
headers.add("Link", expectedHeader);
assertThat(traverson.follow("movies", "movie", "actor").//
withHeaders(headers).<String> toObject("$.name"), is("Keanu Reaves"));
assertThat(traverson.follow("movies", "movie", "actor") //
.withHeaders(headers).<String> toObject("$.name")).isEqualTo("Keanu Reaves");
verifyThatRequest(). //
havingPathEqualTo("/actors/d95dbf62-f900-4dfa-9de8-0fc71e02ffa4"). //
havingHeader("Link", hasItem(expectedHeader));
verifyThatRequest() //
.havingPathEqualTo("/actors/d95dbf62-f900-4dfa-9de8-0fc71e02ffa4") //
.havingHeader("Link", hasItem(expectedHeader));
}
/**
@@ -192,7 +193,7 @@ public class TraversonTest {
this.traverson.setRestOperations(restTemplate);
traverson.follow("movies", "movie", "actor").<String> toObject("$.name");
assertThat(interceptor.intercepted, is(4));
assertThat(interceptor.intercepted).isEqualTo(4);
}
/**
@@ -205,7 +206,7 @@ public class TraversonTest {
this.traverson.setLinkDiscoverers(Arrays.asList(new GitHubLinkDiscoverer()));
String value = this.traverson.follow("foo").toObject("$.key");
assertThat(value, is("value"));
assertThat(value).isEqualTo("value");
}
/**
@@ -216,8 +217,8 @@ public class TraversonTest {
Link result = traverson.follow("movies").asLink();
assertThat(result.getHref(), endsWith("/movies"));
assertThat(result.getRel(), is("movies"));
assertThat(result.getHref()).endsWith("/movies");
assertThat(result.getRel()).isEqualTo("movies");
}
/**
@@ -231,12 +232,12 @@ public class TraversonTest {
Link link = follow.asTemplatedLink();
assertThat(link.isTemplated(), is(true));
assertThat(link.getVariableNames(), hasItem("template"));
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).contains("template");
link = follow.asLink();
assertThat(link.isTemplated(), is(false));
assertThat(link.isTemplated()).isFalse();
}
/**
@@ -247,15 +248,15 @@ public class TraversonTest {
List<HttpMessageConverter<?>> converters = Traverson.getDefaultMessageConverters(MediaTypes.HAL_JSON);
assertThat(converters, hasSize(2));
assertThat(converters.get(0), is(instanceOf(StringHttpMessageConverter.class)));
assertThat(converters.get(1), is(instanceOf(MappingJackson2HttpMessageConverter.class)));
assertThat(converters).hasSize(2);
assertThat(converters.get(0)).isInstanceOf(StringHttpMessageConverter.class);
assertThat(converters.get(1)).isInstanceOf(MappingJackson2HttpMessageConverter.class);
converters = Traverson.getDefaultMessageConverters(MediaTypes.HAL_JSON_UTF8);
assertThat(converters, hasSize(2));
assertThat(converters.get(0), is(instanceOf(StringHttpMessageConverter.class)));
assertThat(converters.get(1), is(instanceOf(MappingJackson2HttpMessageConverter.class)));
assertThat(converters).hasSize(2);
assertThat(converters.get(0)).isInstanceOf(StringHttpMessageConverter.class);
assertThat(converters.get(1)).isInstanceOf(MappingJackson2HttpMessageConverter.class);
}
/**
@@ -267,8 +268,8 @@ public class TraversonTest {
List<HttpMessageConverter<?>> converters = Traverson
.getDefaultMessageConverters(Collections.<MediaType> emptyList());
assertThat(converters, hasSize(1));
assertThat(converters.get(0), is(instanceOf(StringHttpMessageConverter.class)));
assertThat(converters).hasSize(1);
assertThat(converters.get(0)).isInstanceOf(StringHttpMessageConverter.class);
}
/**
@@ -280,7 +281,7 @@ public class TraversonTest {
ParameterizedTypeReference<Resource<Actor>> typeReference = new ParameterizedTypeReference<Resource<Actor>>() {};
Resource<Actor> result = traverson.follow("movies").follow("movie").follow("actor").toObject(typeReference);
assertThat(result.getContent().name, is("Keanu Reaves"));
assertThat(result.getContent().name).isEqualTo("Keanu Reaves");
}
/**
@@ -300,13 +301,13 @@ public class TraversonTest {
toObject(resourceParameterizedTypeReference);
// end::hop-with-param[]
assertThat(itemResource.hasLink("self"), is(true));
assertThat(itemResource.getLink("self").expand().getHref(),
equalTo(server.rootResource() + "/springagram/items/1"));
assertThat(itemResource.hasLink("self")).isTrue();
assertThat(itemResource.getLink("self").expand().getHref())
.isEqualTo(server.rootResource() + "/springagram/items/1");
final Item item = itemResource.getContent();
assertThat(item.image, equalTo(server.rootResource() + "/springagram/file/cat"));
assertThat(item.description, equalTo("cat"));
assertThat(item.image).isEqualTo(server.rootResource() + "/springagram/file/cat");
assertThat(item.description).isEqualTo("cat");
}
/**
@@ -320,8 +321,7 @@ public class TraversonTest {
// tag::hop-put[]
ParameterizedTypeReference<Resource<Item>> resourceParameterizedTypeReference = new ParameterizedTypeReference<Resource<Item>>() {};
Map<String, String> params = new HashMap<String, String>();
params.put("projection", "noImages");
Map<String, Object> params = Collections.singletonMap("projection", "noImages");
Resource<Item> itemResource = traverson.//
follow(rel("items").withParameters(params)).//
@@ -329,13 +329,13 @@ public class TraversonTest {
toObject(resourceParameterizedTypeReference);
// end::hop-put[]
assertThat(itemResource.hasLink("self"), is(true));
assertThat(itemResource.getLink("self").expand().getHref(),
equalTo(server.rootResource() + "/springagram/items/1"));
assertThat(itemResource.hasLink("self")).isTrue();
assertThat(itemResource.getLink("self").expand().getHref())
.isEqualTo(server.rootResource() + "/springagram/items/1");
final Item item = itemResource.getContent();
assertThat(item.image, equalTo(server.rootResource() + "/springagram/file/cat"));
assertThat(item.description, equalTo("cat"));
assertThat(item.image).isEqualTo(server.rootResource() + "/springagram/file/cat");
assertThat(item.description).isEqualTo("cat");
}
/**
@@ -354,13 +354,13 @@ public class TraversonTest {
.follow("$._embedded.items[0]._links.self.href") // retrieve first Item in the collection
.withTemplateParameters(params).toObject(resourceParameterizedTypeReference);
assertThat(itemResource.hasLink("self"), is(true));
assertThat(itemResource.getLink("self").expand().getHref(),
equalTo(server.rootResource() + "/springagram/items/1"));
assertThat(itemResource.hasLink("self")).isTrue();
assertThat(itemResource.getLink("self").expand().getHref())
.isEqualTo(server.rootResource() + "/springagram/items/1");
final Item item = itemResource.getContent();
assertThat(item.image, equalTo(server.rootResource() + "/springagram/file/cat"));
assertThat(item.description, equalTo("cat"));
assertThat(item.image).isEqualTo(server.rootResource() + "/springagram/file/cat");
assertThat(item.description).isEqualTo("cat");
}
/**
@@ -375,8 +375,8 @@ public class TraversonTest {
follow(rel("items").withParameters(Collections.singletonMap("projection", "no images"))).//
toObject(Resource.class);
assertThat(itemResource.hasLink("self"), is(true));
assertThat(itemResource.getLink("self").expand().getHref(), equalTo(server.rootResource() + "/springagram/items"));
assertThat(itemResource.hasLink("self")).isTrue();
assertThat(itemResource.getLink("self").expand().getHref()).isEqualTo(server.rootResource() + "/springagram/items");
}
private void setUpActors() {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.config;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import javax.ws.rs.Path;
@@ -56,16 +55,15 @@ public class EnableEntityLinksIntegrationTest {
}
}
@Autowired
DelegatingEntityLinks builder;
@Autowired DelegatingEntityLinks builder;
@Test
public void initializesDelegatingEntityLinks() {
assertThat(builder, is(notNullValue()));
assertThat(builder.supports(Person.class), is(true));
assertThat(builder.supports(Address.class), is(true));
assertThat(builder.supports(Object.class), is(false));
assertThat(builder).isNotNull();
assertThat(builder.supports(Person.class)).isTrue();
assertThat(builder.supports(Address.class)).isTrue();
assertThat(builder.supports(Object.class)).isFalse();
}
@Controller

View File

@@ -15,18 +15,15 @@
*/
package org.springframework.hateoas.config;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.hateoas.hal.HalConfiguration.RenderSingleLinks.*;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -76,13 +73,15 @@ public class EnableHypermediaSupportIntegrationTest {
@Test
public void registersLinkDiscoverers() {
ApplicationContext context = new AnnotationConfigApplicationContext(HalConfig.class);
LinkDiscoverers discoverers = context.getBean(LinkDiscoverers.class);
withContext(HalConfig.class, context -> {
assertThat(discoverers, is(notNullValue()));
assertThat(discoverers.getLinkDiscovererFor(MediaTypes.HAL_JSON), is(instanceOf(HalLinkDiscoverer.class)));
assertThat(discoverers.getLinkDiscovererFor(MediaTypes.HAL_JSON_UTF8), is(instanceOf(HalLinkDiscoverer.class)));
assertRelProvidersSetUp(context);
LinkDiscoverers discoverers = context.getBean(LinkDiscoverers.class);
assertThat(discoverers).isNotNull();
assertThat(discoverers.getLinkDiscovererFor(MediaTypes.HAL_JSON)).isInstanceOf(HalLinkDiscoverer.class);
assertThat(discoverers.getLinkDiscovererFor(MediaTypes.HAL_JSON_UTF8)).isInstanceOf(HalLinkDiscoverer.class);
assertRelProvidersSetUp(context);
});
}
@Test
@@ -97,34 +96,37 @@ public class EnableHypermediaSupportIntegrationTest {
@SuppressWarnings("unchecked")
public void halSetupIsAppliedToAllTransitiveComponentsInRequestMappingHandlerAdapter() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(HalConfig.class);
withContext(HalConfig.class, context -> {
Jackson2ModuleRegisteringBeanPostProcessor postProcessor = new HypermediaSupportBeanDefinitionRegistrar.Jackson2ModuleRegisteringBeanPostProcessor();
postProcessor.setBeanFactory(context.getAutowireCapableBeanFactory());
Jackson2ModuleRegisteringBeanPostProcessor postProcessor = new HypermediaSupportBeanDefinitionRegistrar.Jackson2ModuleRegisteringBeanPostProcessor();
postProcessor.setBeanFactory(context.getAutowireCapableBeanFactory());
RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
assertThat(adapter.getMessageConverters().get(0).getSupportedMediaTypes(),
hasItems(MediaTypes.HAL_JSON, MediaTypes.HAL_JSON_UTF8));
assertThat(adapter.getMessageConverters().get(0).getSupportedMediaTypes()) //
.contains(MediaTypes.HAL_JSON, MediaTypes.HAL_JSON_UTF8);
boolean found = false;
boolean found = false;
for (HandlerMethodArgumentResolver resolver : getResolvers(adapter)) {
for (HandlerMethodArgumentResolver resolver : getResolvers(adapter)) {
if (resolver instanceof AbstractMessageConverterMethodArgumentResolver) {
if (resolver instanceof AbstractMessageConverterMethodArgumentResolver) {
found = true;
found = true;
AbstractMessageConverterMethodArgumentResolver processor = (AbstractMessageConverterMethodArgumentResolver) resolver;
List<HttpMessageConverter<?>> converters = (List<HttpMessageConverter<?>>) ReflectionTestUtils
.getField(processor, "messageConverters");
AbstractMessageConverterMethodArgumentResolver processor = (AbstractMessageConverterMethodArgumentResolver) resolver;
List<HttpMessageConverter<?>> converters = (List<HttpMessageConverter<?>>) ReflectionTestUtils
.getField(processor, "messageConverters");
assertThat(converters.get(0), is(instanceOf(TypeConstrainedMappingJackson2HttpMessageConverter.class)));
assertThat(converters.get(0).getSupportedMediaTypes(), hasItems(MediaTypes.HAL_JSON, MediaTypes.HAL_JSON_UTF8));
assertThat(converters.get(0)).isInstanceOfSatisfying(TypeConstrainedMappingJackson2HttpMessageConverter.class,
it -> {
assertThat(it.getSupportedMediaTypes()).contains(MediaTypes.HAL_JSON, MediaTypes.HAL_JSON_UTF8);
});
}
}
}
assertThat(found, is(true));
assertThat(found).isTrue();
});
}
/**
@@ -133,12 +135,13 @@ public class EnableHypermediaSupportIntegrationTest {
@Test
public void registersHttpMessageConvertersForRestTemplate() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(HalConfig.class);
RestTemplate template = context.getBean(RestTemplate.class);
withContext(HalConfig.class, context -> {
assertThat(template.getMessageConverters().get(0).getSupportedMediaTypes(),
hasItems(MediaTypes.HAL_JSON, MediaTypes.HAL_JSON_UTF8));
context.close();
RestTemplate template = context.getBean(RestTemplate.class);
assertThat(template.getMessageConverters().get(0).getSupportedMediaTypes()) //
.contains(MediaTypes.HAL_JSON, MediaTypes.HAL_JSON_UTF8);
});
}
/**
@@ -147,11 +150,12 @@ public class EnableHypermediaSupportIntegrationTest {
@Test
public void configuresDefaultObjectMapperForHalToIgnoreUnknownProperties() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(HalConfig.class);
ObjectMapper mapper = context.getBean("_halObjectMapper", ObjectMapper.class);
withContext(HalConfig.class, context -> {
assertThat(mapper.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES), is(false));
context.close();
ObjectMapper mapper = context.getBean("_halObjectMapper", ObjectMapper.class);
assertThat(mapper.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)).isFalse();
});
}
@Test
@@ -164,7 +168,8 @@ public class EnableHypermediaSupportIntegrationTest {
ResourceSupport resourceSupport = new ResourceSupport();
resourceSupport.add(new Link("localhost").withSelfRel());
assertThat(mapper.writeValueAsString(resourceSupport), is("{\"_links\":{\"self\":{\"href\":\"localhost\"}}}"));
assertThat(mapper.writeValueAsString(resourceSupport))
.isEqualTo("{\"_links\":{\"self\":{\"href\":\"localhost\"}}}");
context.close();
}
@@ -172,42 +177,50 @@ public class EnableHypermediaSupportIntegrationTest {
@Test
public void verifyRenderSingleLinkAsArrayViaOverridingBean() throws JsonProcessingException {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
RenderLinkAsSingleLinksConfig.class);
withContext(RenderLinkAsSingleLinksConfig.class, context -> {
ObjectMapper mapper = context.getBean("_halObjectMapper", ObjectMapper.class);
ObjectMapper mapper = context.getBean("_halObjectMapper", ObjectMapper.class);
ResourceSupport resourceSupport = new ResourceSupport();
resourceSupport.add(new Link("localhost").withSelfRel());
ResourceSupport resourceSupport = new ResourceSupport();
resourceSupport.add(new Link("localhost").withSelfRel());
assertThat(mapper.writeValueAsString(resourceSupport), is("{\"_links\":{\"self\":[{\"href\":\"localhost\"}]}}"));
assertThat(mapper.writeValueAsString(resourceSupport))
.isEqualTo("{\"_links\":{\"self\":[{\"href\":\"localhost\"}]}}");
});
}
context.close();
private static <E extends Exception> void withContext(Class<?> configuration,
ConsumerWithException<AnnotationConfigApplicationContext, E> consumer) throws E {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configuration)) {
consumer.accept(context);
}
}
private static void assertEntityLinksSetUp(ApplicationContext context) {
Map<String, EntityLinks> discoverers = context.getBeansOfType(EntityLinks.class);
assertThat(discoverers.values(), Matchers.<EntityLinks> hasItem(instanceOf(DelegatingEntityLinks.class)));
assertThat(context.getBeansOfType(EntityLinks.class).values()) //
.anySatisfy(it -> assertThat(it).isInstanceOf(DelegatingEntityLinks.class));
}
private static void assertRelProvidersSetUp(ApplicationContext context) {
Map<String, RelProvider> discoverers = context.getBeansOfType(RelProvider.class);
assertThat(discoverers.values(), Matchers.<RelProvider> hasItem(instanceOf(DelegatingRelProvider.class)));
assertThat(context.getBeansOfType(RelProvider.class).values()) //
.anySatisfy(it -> assertThat(it).isInstanceOf(DelegatingRelProvider.class));
}
@SuppressWarnings({ "unchecked" })
private static void assertHalSetupForConfigClass(Class<?> configClass) {
ApplicationContext context = new AnnotationConfigApplicationContext(configClass);
assertEntityLinksSetUp(context);
assertThat(context.getBean(LinkDiscoverer.class), is(instanceOf(HalLinkDiscoverer.class)));
assertThat(context.getBean(ObjectMapper.class), is(notNullValue()));
withContext(configClass, context -> {
RequestMappingHandlerAdapter rmha = context.getBean(RequestMappingHandlerAdapter.class);
assertThat(rmha.getMessageConverters(),
Matchers.<HttpMessageConverter<?>> hasItems(instanceOf(MappingJackson2HttpMessageConverter.class)));
assertEntityLinksSetUp(context);
assertThat(context.getBean(LinkDiscoverer.class)).isInstanceOf(HalLinkDiscoverer.class);
assertThat(context.getBean(ObjectMapper.class)).isNotNull();
RequestMappingHandlerAdapter rmha = context.getBean(RequestMappingHandlerAdapter.class);
assertThat(rmha.getMessageConverters())
.anySatisfy(it -> assertThat(it).isInstanceOf(MappingJackson2HttpMessageConverter.class));
});
}
/**
@@ -278,4 +291,8 @@ public class EnableHypermediaSupportIntegrationTest {
return new RequestMappingHandlerAdapter();
}
}
interface ConsumerWithException<T, E extends Exception> {
void accept(T element) throws E;
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.config;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
@@ -40,7 +39,7 @@ public class XmlConfigurationIntegrationTest {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml", getClass());
assertThat(context.getBean(RelProvider.class), is(notNullValue()));
assertThat(context.getBean(RelProvider.class)).isNotNull();
context.close();
}

View File

@@ -15,14 +15,12 @@
*/
package org.springframework.hateoas.core;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkDiscoverer;
@@ -37,45 +35,45 @@ public abstract class AbstractLinkDiscovererUnitTest {
@Test
public void findsSingleLink() {
assertThat(getDiscoverer().findLinkWithRel("self", getInputString()), is(new Link("selfHref")));
assertThat(getDiscoverer().findLinkWithRel("self", getInputString())).isEqualTo(new Link("selfHref"));
List<Link> links = getDiscoverer().findLinksWithRel("self", getInputString());
assertThat(links, hasSize(1));
assertThat(links, hasItem(new Link("selfHref")));
assertThat(links).hasSize(1);
assertThat(links).contains(new Link("selfHref"));
}
@Test
public void findsFirstLink() {
assertThat(getDiscoverer().findLinkWithRel("relation", getInputString()), is(new Link("firstHref", "relation")));
assertThat(getDiscoverer().findLinkWithRel("relation", getInputString()))
.isEqualTo(new Link("firstHref", "relation"));
}
@Test
public void findsAllLinks() {
List<Link> links = getDiscoverer().findLinksWithRel("relation", getInputString());
assertThat(links, hasSize(2));
assertThat(links, hasItems(new Link("firstHref", "relation"), new Link("secondHref", "relation")));
assertThat(links).hasSize(2);
assertThat(links).contains(new Link("firstHref", "relation"), new Link("secondHref", "relation"));
}
@Test
public void returnsForInexistingLink() {
assertThat(getDiscoverer().findLinkWithRel("something", getInputString()), is(nullValue()));
assertThat(getDiscoverer().findLinkWithRel("something", getInputString())).isNull();
}
@Test
public void returnsForInexistingLinkFromInputStream() throws Exception {
InputStream inputStream = new ByteArrayInputStream(getInputString().getBytes("UTF-8"));
assertThat(getDiscoverer().findLinkWithRel("something", inputStream), is(nullValue()));
assertThat(getDiscoverer().findLinkWithRel("something", inputStream)).isNull();
}
@Test
public void returnsNullForNonExistingLinkContainer() {
assertThat(getDiscoverer().findLinksWithRel("something", getInputStringWithoutLinkContainer()),
is(Matchers.<Link> empty()));
assertThat(getDiscoverer().findLinkWithRel("something", getInputStringWithoutLinkContainer()), is(nullValue()));
assertThat(getDiscoverer().findLinksWithRel("something", getInputStringWithoutLinkContainer())).isEmpty();
assertThat(getDiscoverer().findLinkWithRel("something", getInputStringWithoutLinkContainer())).isNull();
}
/**

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.lang.reflect.Method;
@@ -42,32 +41,32 @@ public class AnnotationMappingDiscovererUnitTest {
@Test
public void discoversTypeLevelMapping() {
assertThat(discoverer.getMapping(MyController.class), is("/type"));
assertThat(discoverer.getMapping(MyController.class)).isEqualTo("/type");
}
@Test
public void discoversMethodLevelMapping() throws Exception {
Method method = MyController.class.getMethod("method");
assertThat(discoverer.getMapping(method), is("/type/method"));
assertThat(discoverer.getMapping(method)).isEqualTo("/type/method");
}
@Test
public void returnsNullForNonExistentTypeLevelMapping() {
assertThat(discoverer.getMapping(ControllerWithoutTypeLevelMapping.class), is(nullValue()));
assertThat(discoverer.getMapping(ControllerWithoutTypeLevelMapping.class)).isNull();
}
@Test
public void resolvesMethodLevelMappingWithoutTypeLevelMapping() throws Exception {
Method method = ControllerWithoutTypeLevelMapping.class.getMethod("method");
assertThat(discoverer.getMapping(method), is("/method"));
assertThat(discoverer.getMapping(method)).isEqualTo("/method");
}
@Test
public void resolvesMethodLevelMappingWithSlashRootMapping() throws Exception {
Method method = SlashRootMapping.class.getMethod("method");
assertThat(discoverer.getMapping(method), is("/method"));
assertThat(discoverer.getMapping(method)).isEqualTo("/method");
}
/**
@@ -77,7 +76,7 @@ public class AnnotationMappingDiscovererUnitTest {
public void treatsMissingMethodMappingAsEmptyMapping() throws Exception {
Method method = MyController.class.getMethod("noMethodMapping");
assertThat(discoverer.getMapping(method), is("/type"));
assertThat(discoverer.getMapping(method)).isEqualTo("/type");
}
/**
@@ -87,7 +86,7 @@ public class AnnotationMappingDiscovererUnitTest {
public void detectsClassMappingOnSuperType() throws Exception {
Method method = ChildController.class.getMethod("mapping");
assertThat(discoverer.getMapping(method), is("/parent/child"));
assertThat(discoverer.getMapping(method)).isEqualTo("/parent/child");
}
/**
@@ -97,7 +96,7 @@ public class AnnotationMappingDiscovererUnitTest {
public void includesTypeMappingFromChildClass() throws Exception {
Method method = ParentWithMethod.class.getMethod("mapping");
assertThat(discoverer.getMapping(ChildWithTypeMapping.class, method), is("/child/parent"));
assertThat(discoverer.getMapping(ChildWithTypeMapping.class, method)).isEqualTo("/child/parent");
}
/**
@@ -107,16 +106,16 @@ public class AnnotationMappingDiscovererUnitTest {
public void handlesSlashes() throws Exception {
Method method = ControllerWithoutSlashes.class.getMethod("noslash");
assertThat(discoverer.getMapping(method), is("slashes/noslash"));
assertThat(discoverer.getMapping(method)).isEqualTo("slashes/noslash");
method = ControllerWithoutSlashes.class.getMethod("withslash");
assertThat(discoverer.getMapping(method), is("slashes/withslash"));
assertThat(discoverer.getMapping(method)).isEqualTo("slashes/withslash");
method = ControllerWithTrailingSlashes.class.getMethod("noslash");
assertThat(discoverer.getMapping(method), is("trailing/noslash"));
assertThat(discoverer.getMapping(method)).isEqualTo("trailing/noslash");
method = ControllerWithTrailingSlashes.class.getMethod("withslash");
assertThat(discoverer.getMapping(method), is("trailing/withslash"));
assertThat(discoverer.getMapping(method)).isEqualTo("trailing/withslash");
}
/**
@@ -127,7 +126,7 @@ public class AnnotationMappingDiscovererUnitTest {
Method method = ControllerWithMultipleSlashes.class.getMethod("withslash");
assertThat(discoverer.getMapping(method), is("trailing/withslash"));
assertThat(discoverer.getMapping(method)).isEqualTo("trailing/withslash");
}
/**
@@ -138,7 +137,7 @@ public class AnnotationMappingDiscovererUnitTest {
Method method = MultipleMappingsController.class.getMethod("method");
assertThat(discoverer.getMapping(method), is("/type/method"));
assertThat(discoverer.getMapping(method)).isEqualTo("/type/method");
}
/**
@@ -148,7 +147,7 @@ public class AnnotationMappingDiscovererUnitTest {
public void discoversMethodLevelMappingUsingComposedAnnotation() throws Exception {
Method method = MyController.class.getMethod("methodWithComposedAnnotation");
assertThat(discoverer.getMapping(method), is("/type/otherMethod"));
assertThat(discoverer.getMapping(method)).isEqualTo("/type/otherMethod");
}
@RequestMapping("/type")

View File

@@ -15,12 +15,9 @@
*/
package org.springframework.hateoas.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ConfigurableApplicationContext;
@@ -37,16 +34,14 @@ import org.springframework.stereotype.Controller;
*/
public class ControllerEntityLinksFactoryBeanUnitTest {
@Rule public ExpectedException exception = ExpectedException.none();
@Test
public void rejectsFactoryBeanIfAnnotationNotSet() throws Exception {
exception.expect(IllegalStateException.class);
exception.expectMessage("Annotation");
ControllerEntityLinksFactoryBean builder = new ControllerEntityLinksFactoryBean();
builder.afterPropertiesSet();
assertThatExceptionOfType(IllegalStateException.class) //
.isThrownBy(() -> builder.afterPropertiesSet()) //
.withMessageContaining("Annotation");
}
@Test
@@ -65,6 +60,6 @@ public class ControllerEntityLinksFactoryBeanUnitTest {
builder.afterPropertiesSet();
ControllerEntityLinks entityLinks = builder.getObject();
assertThat(entityLinks.supports(Person.class), is(true));
assertThat(entityLinks.supports(Person.class)).isTrue();
}
}

View File

@@ -15,22 +15,17 @@
*/
package org.springframework.hateoas.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
import java.util.Arrays;
import org.hamcrest.CoreMatchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.ExposesResourceFor;
import org.springframework.hateoas.LinkBuilder;
@@ -47,101 +42,84 @@ import org.springframework.web.bind.annotation.RequestMapping;
@RunWith(MockitoJUnitRunner.class)
public class ControllerEntityLinksUnitTest extends TestUtils {
@Mock
LinkBuilderFactory<LinkBuilder> linkBuilderFactory;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Mock LinkBuilderFactory<LinkBuilder> linkBuilderFactory;
@Test
@SuppressWarnings("unchecked")
public void rejectsUnannotatedController() {
thrown.expectMessage(InvalidController.class.getName());
new ControllerEntityLinks(Arrays.asList(InvalidController.class), linkBuilderFactory);
}
@Test(expected = IllegalArgumentException.class)
public void rejectsNullControllerList() {
new ControllerEntityLinks(null, linkBuilderFactory);
assertThatExceptionOfType(IllegalArgumentException.class) //
.isThrownBy(() -> new ControllerEntityLinks(Arrays.asList(InvalidController.class), linkBuilderFactory)) //
.withMessageContaining(InvalidController.class.getName());
}
@Test
public void rejectsNullControllerList() {
assertThatExceptionOfType(IllegalArgumentException.class) //
.isThrownBy(() -> new ControllerEntityLinks(null, linkBuilderFactory));
}
@Test
@SuppressWarnings("unchecked")
public void rejectsNullLinkBuilderFactory() {
thrown.expectMessage(InvalidController.class.getName());
new ControllerEntityLinks(Arrays.asList(InvalidController.class), linkBuilderFactory);
assertThatExceptionOfType(IllegalArgumentException.class) //
.isThrownBy(() -> new ControllerEntityLinks(Arrays.asList(SampleController.class), null));
}
@Test
@SuppressWarnings("unchecked")
public void registersControllerForEntity() {
when(linkBuilderFactory.linkTo(SampleController.class, new Object[0])).thenReturn(linkTo(SampleController.class));
EntityLinks links = new ControllerEntityLinks(Arrays.asList(SampleController.class), linkBuilderFactory);
assertThat(links.supports(Person.class), is(true));
assertThat(links.linkFor(Person.class), is(notNullValue()));
assertThat(links.supports(Person.class)).isTrue();
assertThat(links.linkFor(Person.class)).isNotNull();
}
/**
* @see #43
*/
@Test
@SuppressWarnings("unchecked")
public void returnsLinkBuilderForParameterizedController() {
when(linkBuilderFactory.linkTo(eq(ControllerWithParameters.class), Mockito.any(Object[].class))).thenReturn(
linkTo(ControllerWithParameters.class, "1"));
when(linkBuilderFactory.linkTo(eq(ControllerWithParameters.class), (Object[]) any())) //
.thenReturn(linkTo(ControllerWithParameters.class, "1"));
ControllerEntityLinks links = new ControllerEntityLinks(Arrays.asList(ControllerWithParameters.class),
linkBuilderFactory);
LinkBuilder builder = links.linkFor(Order.class, "1");
assertThat(builder.withSelfRel().getHref(), CoreMatchers.endsWith("/person/1"));
assertThat(builder.withSelfRel().getHref()).endsWith("/person/1");
}
@Test
@SuppressWarnings("unchecked")
public void rejectsUnmanagedEntity() {
EntityLinks links = new ControllerEntityLinks(
Arrays.asList(SampleController.class, ControllerWithParameters.class), linkBuilderFactory);
EntityLinks links = new ControllerEntityLinks(Arrays.asList(SampleController.class, ControllerWithParameters.class),
linkBuilderFactory);
assertThat(links.supports(Person.class), is(true));
assertThat(links.supports(Order.class), is(true));
assertThat(links.supports(SampleController.class), is(false));
assertThat(links.supports(Person.class)).isTrue();
assertThat(links.supports(Order.class)).isTrue();
assertThat(links.supports(SampleController.class)).isFalse();
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(SampleController.class.getName());
thrown.expectMessage(ExposesResourceFor.class.getName());
links.linkFor(SampleController.class);
assertThatExceptionOfType(IllegalArgumentException.class) //
.isThrownBy(() -> links.linkFor(SampleController.class)) //
.withMessageContaining(SampleController.class.getName()) //
.withMessageContaining(ExposesResourceFor.class.getName());
}
@Controller
@ExposesResourceFor(Person.class)
@RequestMapping("/person")
static class SampleController {
}
static class SampleController {}
@Controller
@ExposesResourceFor(Order.class)
@RequestMapping("/person/{id}")
static class ControllerWithParameters {
static class ControllerWithParameters {}
}
static class InvalidController {}
static class InvalidController {
static class Person {}
}
static class Person {
}
static class Order {
}
static class Order {}
}

View File

@@ -15,23 +15,19 @@
*/
package org.springframework.hateoas.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.ExposesResourceFor;
import org.springframework.hateoas.TestUtils;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.plugin.core.SimplePluginRegistry;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -43,11 +39,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
@RunWith(MockitoJUnitRunner.class)
public class DelegatingEntityLinksUnitTest extends TestUtils {
@Rule
public ExpectedException exception = ExpectedException.none();
@Mock
EntityLinks target;
@Mock EntityLinks target;
@Before
@Override
@@ -63,11 +55,11 @@ public class DelegatingEntityLinksUnitTest extends TestUtils {
@Test
public void throwsExceptionForUnsupportedClass() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage(String.class.getName());
EntityLinks links = new DelegatingEntityLinks(SimplePluginRegistry.<Class<?>, EntityLinks> create());
links.linkFor(String.class);
assertThatExceptionOfType(IllegalArgumentException.class) //
.isThrownBy(() -> links.linkFor(String.class)) //
.withMessageContaining(String.class.getName());
}
@Test
@@ -75,27 +67,22 @@ public class DelegatingEntityLinksUnitTest extends TestUtils {
EntityLinks links = createDelegatingEntityLinks();
assertThat(links.supports(String.class), is(true));
assertThat(links.supports(String.class)).isTrue();
}
@Test
public void delegatesLinkForCall() {
EntityLinks links = createDelegatingEntityLinks();
createDelegatingEntityLinks().linkFor(String.class);
links.linkFor(String.class);
verify(target, times(1)).linkFor(String.class);
}
private EntityLinks createDelegatingEntityLinks() {
PluginRegistry<EntityLinks, Class<?>> registry = SimplePluginRegistry.create(Arrays.asList(target));
return new DelegatingEntityLinks(registry);
return new DelegatingEntityLinks(SimplePluginRegistry.create(Arrays.asList(target)));
}
@ExposesResourceFor(String.class)
@RequestMapping("/string")
static class Controller {
}
static class Controller {}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.List;
@@ -41,13 +40,13 @@ public class DelegatingRelProviderUnitTest {
RelProvider delegatingProvider = new DelegatingRelProvider(registry);
assertThat(delegatingProvider.supports(Sample.class), is(true));
assertThat(delegatingProvider.getItemResourceRelFor(Sample.class), is("foo"));
assertThat(delegatingProvider.getCollectionResourceRelFor(Sample.class), is("bar"));
assertThat(delegatingProvider.supports(Sample.class)).isTrue();
assertThat(delegatingProvider.getItemResourceRelFor(Sample.class)).isEqualTo("foo");
assertThat(delegatingProvider.getCollectionResourceRelFor(Sample.class)).isEqualTo("bar");
assertThat(delegatingProvider.supports(String.class), is(true));
assertThat(delegatingProvider.getItemResourceRelFor(String.class), is("string"));
assertThat(delegatingProvider.getCollectionResourceRelFor(String.class), is("stringList"));
assertThat(delegatingProvider.supports(String.class)).isTrue();
assertThat(delegatingProvider.getItemResourceRelFor(String.class)).isEqualTo("string");
assertThat(delegatingProvider.getCollectionResourceRelFor(String.class)).isEqualTo("stringList");
}
@Relation(value = "foo", collectionRelation = "bar")

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.core;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Collection;
import java.util.Collections;
@@ -42,8 +41,8 @@ public class EmbeddedWrappersUnitTest {
EmbeddedWrapper wrapper = wrappers.emptyCollectionOf(String.class);
assertEmptyCollectionValue(wrapper);
assertThat(wrapper.getRel(), is(nullValue()));
assertThat(wrapper.getRelTargetType(), is(equalTo((Class) String.class)));
assertThat(wrapper.getRel()).isNull();
assertThat(wrapper.getRelTargetType()).isEqualTo((Class) String.class);
}
/**
@@ -55,8 +54,8 @@ public class EmbeddedWrappersUnitTest {
EmbeddedWrapper wrapper = wrappers.wrap(Collections.emptySet(), "rel");
assertEmptyCollectionValue(wrapper);
assertThat(wrapper.getRel(), is("rel"));
assertThat(wrapper.getRelTargetType(), is(nullValue()));
assertThat(wrapper.getRel()).isEqualTo("rel");
assertThat(wrapper.getRelTargetType()).isNull();
}
/**
@@ -67,9 +66,8 @@ public class EmbeddedWrappersUnitTest {
wrappers.wrap(Collections.emptySet());
}
@SuppressWarnings("unchecked")
private static void assertEmptyCollectionValue(EmbeddedWrapper wrapper) {
assertThat(wrapper.getValue(), is(instanceOf(Collection.class)));
assertThat((Collection<?>) wrapper.getValue(), is(empty()));
assertThat(wrapper.getValue()).isInstanceOfSatisfying(Collection.class, it -> assertThat(it).isEmpty());
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.hateoas.RelProvider;
@@ -37,8 +36,8 @@ public class EvoInflectorRelProviderUnitTest {
}
private void assertRels(Class<?> type, String singleRel, String collectionRel) {
assertThat(provider.getItemResourceRelFor(type), is(singleRel));
assertThat(provider.getCollectionResourceRelFor(type), is(collectionRel));
assertThat(provider.getItemResourceRelFor(type)).isEqualTo(singleRel);
assertThat(provider.getCollectionResourceRelFor(type)).isEqualTo(collectionRel);
}
static class Person {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.hateoas.TestUtils;
@@ -34,7 +33,7 @@ public class LinkBuilderSupportUnitTest extends TestUtils {
public void callingSlashWithEmptyStringIsNoOp() {
SampleLinkBuilder builder = new SampleLinkBuilder(UriComponentsBuilder.newInstance());
assertThat(builder.slash(""), is(builder));
assertThat(builder.slash("")).isEqualTo(builder);
}
@Test
@@ -42,15 +41,15 @@ public class LinkBuilderSupportUnitTest extends TestUtils {
SampleLinkBuilder builder = new SampleLinkBuilder(UriComponentsBuilder.newInstance());
builder = builder.slash("foo#bar");
assertThat(builder.toString(), endsWith("foo#bar"));
assertThat(builder.toString()).endsWith("foo#bar");
builder = builder.slash("bar");
assertThat(builder.toString(), endsWith("foo/bar#bar"));
assertThat(builder.toString()).endsWith("foo/bar#bar");
builder = builder.slash("#foo");
assertThat(builder.toString(), endsWith("foo/bar#foo"));
assertThat(builder.toString()).endsWith("foo/bar#foo");
builder = builder.slash("#");
assertThat(builder.toString(), endsWith("foo/bar#foo"));
assertThat(builder.toString()).endsWith("foo/bar#foo");
builder = builder.slash("foo bar");
assertThat(builder.toString(), endsWith("foo%20bar#foo"));
assertThat(builder.toString()).endsWith("foo%20bar#foo");
}
/**
@@ -63,7 +62,7 @@ public class LinkBuilderSupportUnitTest extends TestUtils {
builder = builder.slash("47:11");
assertThat(builder.toString(), endsWith("47:11"));
assertThat(builder.toString()).endsWith("47:11");
}
static class SampleLinkBuilder extends LinkBuilderSupport<SampleLinkBuilder> {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.core;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.lang.reflect.Method;
import java.util.List;
@@ -38,9 +37,9 @@ public class MethodParametersUnitTest {
Method method = Sample.class.getMethod("method", String.class, String.class, Object.class);
MethodParameters parameters = new MethodParameters(method, new AnnotationAttribute(Qualifier.class));
assertThat(parameters.getParameter("param"), is(notNullValue()));
assertThat(parameters.getParameter("foo"), is(notNullValue()));
assertThat(parameters.getParameter("another"), is(nullValue()));
assertThat(parameters.getParameter("param")).isNotNull();
assertThat(parameters.getParameter("foo")).isNotNull();
assertThat(parameters.getParameter("another")).isNull();
}
/**
@@ -53,8 +52,8 @@ public class MethodParametersUnitTest {
MethodParameters methodParameters = new MethodParameters(method);
List<MethodParameter> objectParameters = methodParameters.getParametersOfType(Object.class);
assertThat(objectParameters, hasSize(1));
assertThat(objectParameters.get(0).getParameterIndex(), is(2));
assertThat(objectParameters).hasSize(1);
assertThat(objectParameters.get(0).getParameterIndex()).isEqualTo(2);
}
static class Sample {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.hal;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Collection;
import java.util.HashMap;
@@ -70,17 +69,17 @@ public class DefaultCurieProviderUnitTest {
@Test
public void doesNotPrefixIanaRels() {
assertThat(provider.getNamespacedRelFrom(new Link("http://amazon.com")), is("self"));
assertThat(provider.getNamespacedRelFrom(new Link("http://amazon.com"))).isEqualTo("self");
}
@Test
public void prefixesNormalRels() {
assertThat(provider.getNamespacedRelFrom(new Link("http://amazon.com", "book")), is("acme:book"));
assertThat(provider.getNamespacedRelFrom(new Link("http://amazon.com", "book"))).isEqualTo("acme:book");
}
@Test
public void doesNotPrefixQualifiedRels() {
assertThat(provider.getNamespacedRelFrom(new Link("http://amazon.com", "custom:rel")), is("custom:rel"));
assertThat(provider.getNamespacedRelFrom(new Link("http://amazon.com", "custom:rel"))).isEqualTo("custom:rel");
}
/**
@@ -88,12 +87,15 @@ public class DefaultCurieProviderUnitTest {
*/
@Test
public void prefixesNormalRelsThatHaveExtraRFC5988Attributes() {
assertThat(provider.getNamespacedRelFrom(new Link("http://amazon.com", "custom:rel")
.withHreflang("en")
.withTitle("the title")
.withMedia("the media")
.withType("the type")
.withDeprecation("http://example.com/custom/deprecated")), is("custom:rel"));
Link link = new Link("http://amazon.com", "custom:rel") //
.withHreflang("en") //
.withTitle("the title") //
.withMedia("the media") //
.withType("the type") //
.withDeprecation("http://example.com/custom/deprecated");
assertThat(provider.getNamespacedRelFrom(link)).isEqualTo("custom:rel");
}
/**
@@ -101,7 +103,7 @@ public class DefaultCurieProviderUnitTest {
*/
@Test
public void doesNotPrefixIanaRelsForRelAsString() {
assertThat(provider.getNamespacedRelFor("self"), is("self"));
assertThat(provider.getNamespacedRelFor("self")).isEqualTo("self");
}
/**
@@ -109,7 +111,7 @@ public class DefaultCurieProviderUnitTest {
*/
@Test
public void prefixesNormalRelsForRelAsString() {
assertThat(provider.getNamespacedRelFor("book"), is("acme:book"));
assertThat(provider.getNamespacedRelFor("book")).isEqualTo("acme:book");
}
/**
@@ -117,7 +119,7 @@ public class DefaultCurieProviderUnitTest {
*/
@Test
public void doesNotPrefixQualifiedRelsForRelAsString() {
assertThat(provider.getNamespacedRelFor("custom:rel"), is("custom:rel"));
assertThat(provider.getNamespacedRelFor("custom:rel")).isEqualTo("custom:rel");
}
/**
@@ -128,8 +130,8 @@ public class DefaultCurieProviderUnitTest {
DefaultCurieProvider provider = new DefaultCurieProvider(getCuries());
assertThat(provider.getCurieInformation(new Links()), hasSize(2));
assertThat(provider.getNamespacedRelFor("some"), is("some"));
assertThat(provider.getCurieInformation(new Links())).hasSize(2);
assertThat(provider.getNamespacedRelFor("some")).isEqualTo("some");
}
/**
@@ -140,8 +142,8 @@ public class DefaultCurieProviderUnitTest {
DefaultCurieProvider provider = new DefaultCurieProvider(getCuries(), "foo");
assertThat(provider.getCurieInformation(new Links()), hasSize(2));
assertThat(provider.getNamespacedRelFor("some"), is("foo:some"));
assertThat(provider.getCurieInformation(new Links())).hasSize(2);
assertThat(provider.getNamespacedRelFor("some")).isEqualTo("foo:some");
}
/**
@@ -159,12 +161,11 @@ public class DefaultCurieProviderUnitTest {
Links links = new Links(new Link("http://localhost", "name:foo"));
Collection<? extends Object> curies = provider.getCurieInformation(links);
assertThat(curies, hasSize(1));
assertThat(curies).hasSize(1);
Object curie = curies.iterator().next();
assertThat(curie, is(instanceOf(Curie.class)));
assertThat(((Curie) curie).getHref(), startsWith("http://localhost"));
assertThat(curie).isInstanceOfSatisfying(Curie.class,
it -> assertThat(it.getHref()).startsWith("http://localhost"));
}
private static Map<String, UriTemplate> getCuries() {

View File

@@ -15,14 +15,12 @@
*/
package org.springframework.hateoas.hal;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.List;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.springframework.hateoas.RelProvider;
@@ -53,8 +51,8 @@ public class HalEmbeddedBuilderUnitTest {
Map<String, Object> map = setUpBuilder(null, "foo", 1L);
assertThat(map.get("string"), is((Object) "foo"));
assertThat(map.get("long"), is((Object) 1L));
assertThat(map.get("string")).isEqualTo((Object) "foo");
assertThat(map.get("long")).isEqualTo((Object) 1L);
}
@Test
@@ -62,8 +60,8 @@ public class HalEmbeddedBuilderUnitTest {
Map<String, Object> map = setUpBuilder(null, "foo", "bar", 1L);
assertThat(map.containsKey("string"), is(false));
assertThat(map.get("long"), is((Object) 1L));
assertThat(map.containsKey("string")).isFalse();
assertThat(map.get("long")).isEqualTo(1L);
assertHasValues(map, "strings", "foo", "bar");
}
@@ -75,9 +73,9 @@ public class HalEmbeddedBuilderUnitTest {
Map<String, Object> map = setUpBuilder(null, "foo", "bar", "foobar", 1L);
assertThat(map.containsKey("string"), is(false));
assertThat(map.containsKey("string")).isFalse();
assertHasValues(map, "strings", "foo", "bar", "foobar");
assertThat(map.get("long"), is((Object) 1L));
assertThat(map.get("long")).isEqualTo(1L);
}
/**
@@ -89,7 +87,7 @@ public class HalEmbeddedBuilderUnitTest {
HalEmbeddedBuilder builder = new HalEmbeddedBuilder(provider, null, true);
builder.add("Sample");
assertThat(builder.asMap().get("string"), is(nullValue()));
assertThat(builder.asMap().get("string")).isNull();
assertHasValues(builder.asMap(), "strings", "Sample");
}
@@ -104,7 +102,7 @@ public class HalEmbeddedBuilderUnitTest {
HalEmbeddedBuilder builder = new HalEmbeddedBuilder(provider, null, true);
builder.add(wrappers.wrap("MyValue", "foo"));
assertThat(builder.asMap().get("foo"), is(instanceOf(String.class)));
assertThat(builder.asMap().get("foo")).isInstanceOf(String.class);
}
/**
@@ -123,8 +121,8 @@ public class HalEmbeddedBuilderUnitTest {
Map<String, Object> map = setUpBuilder(curieProvider, "foo", 1L);
assertThat(map.get("curie:string"), is((Object) "foo"));
assertThat(map.get("curie:long"), is((Object) 1L));
assertThat(map.get("curie:string")).isEqualTo((Object) "foo");
assertThat(map.get("curie:long")).isEqualTo((Object) 1L);
}
/**
@@ -135,8 +133,8 @@ public class HalEmbeddedBuilderUnitTest {
Map<String, Object> map = setUpBuilder(curieProvider, "foo", "bar", 1L);
assertThat(map.containsKey("curie:string"), is(false));
assertThat(map.get("curie:long"), is((Object) 1L));
assertThat(map.containsKey("curie:string")).isFalse();
assertThat(map.get("curie:long")).isEqualTo((Object) 1L);
assertHasValues(map, "curie:strings", "foo", "bar");
}
@@ -148,9 +146,9 @@ public class HalEmbeddedBuilderUnitTest {
Map<String, Object> map = setUpBuilder(curieProvider, "foo", "bar", "foobar", 1L);
assertThat(map.containsKey("curie:string"), is(false));
assertThat(map.containsKey("curie:string")).isFalse();
assertHasValues(map, "curie:strings", "foo", "bar", "foobar");
assertThat(map.get("curie:long"), is((Object) 1L));
assertThat(map.get("curie:long")).isEqualTo((Object) 1L);
}
/**
@@ -162,7 +160,7 @@ public class HalEmbeddedBuilderUnitTest {
HalEmbeddedBuilder builder = new HalEmbeddedBuilder(provider, curieProvider, true);
builder.add("Sample");
assertThat(builder.asMap().get("curie:string"), is(nullValue()));
assertThat(builder.asMap().get("curie:string")).isNull();
assertHasValues(builder.asMap(), "curie:strings", "Sample");
}
@@ -179,8 +177,10 @@ public class HalEmbeddedBuilderUnitTest {
Object value = source.get(rel);
assertThat(value, is(instanceOf(List.class)));
assertThat((List<Object>) value, Matchers.<List<Object>> allOf(hasSize(values.length), hasItems(values)));
assertThat(value).isInstanceOfSatisfying(List.class, it -> {
assertThat(it).hasSize(values.length);
assertThat(it).contains(values);
});
}
private Map<String, Object> setUpBuilder(CurieProvider curieProvider, Object... values) {

View File

@@ -15,11 +15,9 @@
*/
package org.springframework.hateoas.hal;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkDiscoverer;
import org.springframework.hateoas.MediaTypes;
@@ -45,8 +43,8 @@ public class HalLinkDiscovererUnitTest extends AbstractLinkDiscovererUnitTest {
Link link = getDiscoverer().findLinkWithRel("http://foo.com/bar", SAMPLE);
assertThat(link, is(notNullValue()));
assertThat(link.getHref(), is("fullRelHref"));
assertThat(link).isNotNull();
assertThat(link.getHref()).isEqualTo("fullRelHref");
}
/**
@@ -54,7 +52,7 @@ public class HalLinkDiscovererUnitTest extends AbstractLinkDiscovererUnitTest {
*/
@Test
public void supportsHalUtf8() {
assertThat(getDiscoverer().supports(MediaTypes.HAL_JSON_UTF8), is(true));
assertThat(getDiscoverer().supports(MediaTypes.HAL_JSON_UTF8)).isTrue();
}
@Override

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.hal;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.ArrayList;
import java.util.Arrays;
@@ -99,7 +98,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
ResourceSupport resourceSupport = new ResourceSupport();
resourceSupport.add(new Link("localhost"));
assertThat(write(resourceSupport), is(SINGLE_LINK_REFERENCE));
assertThat(write(resourceSupport)).isEqualTo(SINGLE_LINK_REFERENCE);
}
/**
@@ -116,7 +115,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
.withMedia("the media") //
.withDeprecation("/customers/deprecated"));
assertThat(write(resourceSupport), is(SINGLE_WITH_ALL_EXTRA_ATTRIBUTES));
assertThat(write(resourceSupport)).isEqualTo(SINGLE_WITH_ALL_EXTRA_ATTRIBUTES);
}
@Test
@@ -125,14 +124,14 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
ResourceSupport resourceSupport = new ResourceSupport();
resourceSupport.add(new Link("localhost", "self").withTitle("the title"));
assertThat(write(resourceSupport), is(SINGLE_WITH_ONE_EXTRA_ATTRIBUTES));
assertThat(write(resourceSupport)).isEqualTo(SINGLE_WITH_ONE_EXTRA_ATTRIBUTES);
}
@Test
public void deserializeSingleLink() throws Exception {
ResourceSupport expected = new ResourceSupport();
expected.add(new Link("localhost"));
assertThat(read(SINGLE_LINK_REFERENCE, ResourceSupport.class), is(expected));
assertThat(read(SINGLE_LINK_REFERENCE, ResourceSupport.class)).isEqualTo(expected);
}
/**
@@ -145,7 +144,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
resourceSupport.add(new Link("localhost"));
resourceSupport.add(new Link("localhost2"));
assertThat(write(resourceSupport), is(LIST_LINK_REFERENCE));
assertThat(write(resourceSupport)).isEqualTo(LIST_LINK_REFERENCE);
}
@Test
@@ -155,7 +154,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
expected.add(new Link("localhost"));
expected.add(new Link("localhost2"));
assertThat(read(LIST_LINK_REFERENCE, ResourceSupport.class), is(expected));
assertThat(read(LIST_LINK_REFERENCE, ResourceSupport.class)).isEqualTo(expected);
}
@Test
@@ -168,7 +167,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
Resources<String> resources = new Resources<String>(content);
resources.add(new Link("localhost"));
assertThat(write(resources), is(SIMPLE_EMBEDDED_RESOURCE_REFERENCE));
assertThat(write(resources)).isEqualTo(SIMPLE_EMBEDDED_RESOURCE_REFERENCE);
}
@Test
@@ -184,7 +183,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
Resources<String> result = mapper.readValue(SIMPLE_EMBEDDED_RESOURCE_REFERENCE,
mapper.getTypeFactory().constructParametricType(Resources.class, String.class));
assertThat(result, is(expected));
assertThat(result).isEqualTo(expected);
}
@@ -197,7 +196,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
Resources<Resource<SimplePojo>> resources = new Resources<Resource<SimplePojo>>(content);
resources.add(new Link("localhost"));
assertThat(write(resources), is(SINGLE_EMBEDDED_RESOURCE_REFERENCE));
assertThat(write(resources)).isEqualTo(SINGLE_EMBEDDED_RESOURCE_REFERENCE);
}
@Test
@@ -213,7 +212,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
mapper.getTypeFactory().constructParametricType(Resources.class,
mapper.getTypeFactory().constructParametricType(Resource.class, SimplePojo.class)));
assertThat(result, is(expected));
assertThat(result).isEqualTo(expected);
}
@@ -223,7 +222,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
Resources<Resource<SimplePojo>> resources = setupResources();
resources.add(new Link("localhost"));
assertThat(write(resources), is(LIST_EMBEDDED_RESOURCE_REFERENCE));
assertThat(write(resources)).isEqualTo(LIST_EMBEDDED_RESOURCE_REFERENCE);
}
@Test
@@ -236,7 +235,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
mapper.getTypeFactory().constructParametricType(Resources.class,
mapper.getTypeFactory().constructParametricType(Resource.class, SimplePojo.class)));
assertThat(result, is(expected));
assertThat(result).isEqualTo(expected);
}
/**
@@ -251,7 +250,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
Resources<Resource<SimpleAnnotatedPojo>> resources = new Resources<Resource<SimpleAnnotatedPojo>>(content);
resources.add(new Link("localhost"));
assertThat(write(resources), is(ANNOTATED_EMBEDDED_RESOURCE_REFERENCE));
assertThat(write(resources)).isEqualTo(ANNOTATED_EMBEDDED_RESOURCE_REFERENCE);
}
/**
@@ -270,7 +269,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
mapper.getTypeFactory().constructParametricType(Resources.class,
mapper.getTypeFactory().constructParametricType(Resource.class, SimpleAnnotatedPojo.class)));
assertThat(result, is(expected));
assertThat(result).isEqualTo(expected);
}
/**
@@ -278,7 +277,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
*/
@Test
public void serializesMultipleAnnotatedResourceResourcesAsEmbedded() throws Exception {
assertThat(write(setupAnnotatedResources()), is(ANNOTATED_EMBEDDED_RESOURCES_REFERENCE));
assertThat(write(setupAnnotatedResources())).isEqualTo(ANNOTATED_EMBEDDED_RESOURCES_REFERENCE);
}
/**
@@ -291,7 +290,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
mapper.getTypeFactory().constructParametricType(Resources.class,
mapper.getTypeFactory().constructParametricType(Resource.class, SimpleAnnotatedPojo.class)));
assertThat(result, is(setupAnnotatedResources()));
assertThat(result).isEqualTo(setupAnnotatedResources());
}
/**
@@ -299,7 +298,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
*/
@Test
public void serializesPagedResource() throws Exception {
assertThat(write(setupAnnotatedPagedResources()), is(ANNOTATED_PAGED_RESOURCES));
assertThat(write(setupAnnotatedPagedResources())).isEqualTo(ANNOTATED_PAGED_RESOURCES);
}
/**
@@ -311,7 +310,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
mapper.getTypeFactory().constructParametricType(PagedResources.class,
mapper.getTypeFactory().constructParametricType(Resource.class, SimpleAnnotatedPojo.class)));
assertThat(result, is(setupAnnotatedPagedResources()));
assertThat(result).isEqualTo(setupAnnotatedPagedResources());
}
/**
@@ -323,7 +322,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
Resources<Object> resources = new Resources<Object>(Collections.emptySet(), new Link("foo"),
new Link("bar", "myrel"));
assertThat(getCuriedObjectMapper().writeValueAsString(resources), is(CURIED_DOCUMENT));
assertThat(getCuriedObjectMapper().writeValueAsString(resources)).isEqualTo(CURIED_DOCUMENT);
}
/**
@@ -333,7 +332,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
public void doesNotRenderCuriesIfNoLinkIsPresent() throws Exception {
Resources<Object> resources = new Resources<Object>(Collections.emptySet());
assertThat(getCuriedObjectMapper().writeValueAsString(resources), is(EMPTY_DOCUMENT));
assertThat(getCuriedObjectMapper().writeValueAsString(resources)).isEqualTo(EMPTY_DOCUMENT);
}
/**
@@ -345,7 +344,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
Resources<Object> resources = new Resources<Object>(Collections.emptySet());
resources.add(new Link("foo"));
assertThat(getCuriedObjectMapper().writeValueAsString(resources), is(SINGLE_NON_CURIE_LINK));
assertThat(getCuriedObjectMapper().writeValueAsString(resources)).isEqualTo(SINGLE_NON_CURIE_LINK);
}
/**
@@ -357,7 +356,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
ResourceSupport support = new ResourceSupport();
support.add(new Link("/foo{?bar}", "search"));
assertThat(write(support), is(LINK_TEMPLATE));
assertThat(write(support)).isEqualTo(LINK_TEMPLATE);
}
/**
@@ -376,7 +375,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
}
};
assertThat(getCuriedObjectMapper(provider, null).writeValueAsString(resources), is(MULTIPLE_CURIES_DOCUMENT));
assertThat(getCuriedObjectMapper(provider, null).writeValueAsString(resources)).isEqualTo(MULTIPLE_CURIES_DOCUMENT);
}
/**
@@ -392,7 +391,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
Resources<Object> resources = new Resources<Object>(values);
assertThat(write(resources), is("{\"_embedded\":{\"pojos\":[]}}"));
assertThat(write(resources)).isEqualTo("{\"_embedded\":{\"pojos\":[]}}");
}
/**
@@ -420,7 +419,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
ResourceSupport resourceSupport = new ResourceSupport();
resourceSupport.add(new Link("localhost").withSelfRel());
assertThat(write(resourceSupport), is("{\"_links\":{\"self\":[{\"href\":\"localhost\"}]}}"));
assertThat(write(resourceSupport)).isEqualTo("{\"_links\":{\"self\":[{\"href\":\"localhost\"}]}}");
}
private static void verifyResolvedTitle(String resourceBundleKey) throws Exception {
@@ -435,7 +434,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
ResourceSupport resource = new ResourceSupport();
resource.add(new Link("target", "ns:foobar"));
assertThat(objectMapper.writeValueAsString(resource), is(LINK_WITH_TITLE));
assertThat(objectMapper.writeValueAsString(resource)).isEqualTo(LINK_WITH_TITLE);
}
private static Resources<Resource<SimpleAnnotatedPojo>> setupAnnotatedPagedResources() {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.jaxrs;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Collections;
@@ -43,8 +42,8 @@ public class JaxRsLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(PersonServiceImpl.class).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people");
}
@Test
@@ -52,8 +51,8 @@ public class JaxRsLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(PersonsAddressesService.class, 15).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people/15/addresses"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/15/addresses");
}
/**
@@ -64,8 +63,8 @@ public class JaxRsLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(PersonsAddressesService.class, "with blank").withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people/with%20blank/addresses"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/with%20blank/addresses");
}
/**
@@ -76,8 +75,8 @@ public class JaxRsLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(PersonsAddressesService.class, Collections.singletonMap("id", "17")).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people/17/addresses"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/17/addresses");
}
@Path("/people")

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.mvc;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
import java.util.Arrays;
@@ -61,8 +60,8 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(PersonControllerImpl.class).withSelfRel();
assertPointsToMockServer(link);
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people");
}
@Test
@@ -71,8 +70,8 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(PersonsAddressesController.class, 15).withSelfRel();
assertPointsToMockServer(link);
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people/15/addresses"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/15/addresses");
}
@Test
@@ -86,7 +85,7 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(methodOn(SampleController.class).sampleMethod(1L, specialType)).withSelfRel();
assertPointsToMockServer(link);
assertThat(link.getHref(), endsWith("/sample/1?foo=value"));
assertThat(link.getHref()).endsWith("/sample/1?foo=value");
}
/**
@@ -99,7 +98,7 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils {
ControllerLinkBuilderFactory factory = new ControllerLinkBuilderFactory();
Link link = factory.linkTo(methodOn(SampleController.class).sampleMethod(now)).withSelfRel();
assertThat(link.getHref(), endsWith("/sample/" + ISODateTimeFormat.date().print(now)));
assertThat(link.getHref()).endsWith("/sample/" + ISODateTimeFormat.date().print(now));
}
/**
@@ -109,8 +108,8 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils {
public void linksToMethodWithPathVariableContainingBlank() {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithPathVariable("with blank")).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/something/with%20blank/foo"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/something/with%20blank/foo");
}
/**
@@ -122,8 +121,8 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(PersonsAddressesController.class, "with blank").withSelfRel();
assertPointsToMockServer(link);
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people/with%20blank/addresses"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/with%20blank/addresses");
}
/**
@@ -139,8 +138,8 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(methodOn(SampleController.class).sampleMethodWithMap(queryParams)).withSelfRel();
assertPointsToMockServer(link);
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/sample/mapsupport?firstKey=firstValue&secondKey=secondValue"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/sample/mapsupport?firstKey=firstValue&secondKey=secondValue");
}
/**
@@ -156,9 +155,9 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(methodOn(SampleController.class).sampleMethodWithMap(queryParams)).withSelfRel();
assertPointsToMockServer(link);
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(),
endsWith("/sample/multivaluemapsupport?key1=value1a&key1=value1b&key2=value2a&key2=value2b"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()) //
.endsWith("/sample/multivaluemapsupport?key1=value1a&key1=value1b&key2=value2a&key2=value2b");
}
/**
@@ -170,8 +169,8 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils {
Link link = factory.linkTo(PersonsAddressesController.class, Collections.singletonMap("id", "17")).withSelfRel();
assertPointsToMockServer(link);
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people/17/addresses"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/17/addresses");
}
static interface SampleController {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.mvc;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
import org.junit.Before;
@@ -49,6 +48,6 @@ public class ControllerLinkBuilderOutsideSpringMvcUnitTest {
methodOn(ControllerLinkBuilderUnitTest.PersonsAddressesController.class, 15).getAddressesForCountry("DE"))
.withSelfRel();
assertThat(link, is(new Link("/people/15/addresses/DE").withSelfRel()));
assertThat(link).isEqualTo(new Link("/people/15/addresses/DE").withSelfRel());
}
}

View File

@@ -15,7 +15,8 @@
*/
package org.springframework.hateoas.mvc;
import static org.hamcrest.MatcherAssert.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
@@ -24,7 +25,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -63,16 +63,16 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
public void createsLinkToControllerRoot() {
Link link = linkTo(PersonControllerImpl.class).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), Matchers.endsWith("/people"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people");
}
@Test
public void createsLinkToParameterizedControllerRoot() {
Link link = linkTo(PersonsAddressesController.class, 15).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people/15/addresses"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/15/addresses");
}
/**
@@ -82,24 +82,24 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
public void createsLinkToMethodOnParameterizedControllerRoot() {
Link link = linkTo(methodOn(PersonsAddressesController.class, 15).getAddressesForCountry("DE")).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people/15/addresses/DE"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/15/addresses/DE");
}
@Test
public void createsLinkToSubResource() {
Link link = linkTo(PersonControllerImpl.class).slash("something").withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people/something"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/something");
}
@Test
public void createsLinkWithCustomRel() {
Link link = linkTo(PersonControllerImpl.class).withRel(Link.REL_NEXT);
assertThat(link.getRel(), is(Link.REL_NEXT));
assertThat(link.getHref(), endsWith("/people"));
assertThat(link.getRel()).isEqualTo(Link.REL_NEXT);
assertThat(link.getHref()).endsWith("/people");
}
/**
@@ -107,14 +107,14 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
*/
@Test
public void usesFirstMappingInCaseMultipleOnesAreDefined() {
assertThat(linkTo(InvalidController.class).withSelfRel().getHref(), endsWith("/persons"));
assertThat(linkTo(InvalidController.class).withSelfRel().getHref()).endsWith("/persons");
}
@Test
public void createsLinkToUnmappedController() {
Link link = linkTo(UnmappedController.class).withSelfRel();
assertThat(link.getHref(), is("http://localhost"));
assertThat(link.getHref()).isEqualTo("http://localhost");
}
@Test
@@ -125,17 +125,17 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Mockito.when(identifyable.getId()).thenReturn(10L);
Link link = linkTo(PersonControllerImpl.class).slash(identifyable).withSelfRel();
assertThat(link.getHref(), endsWith("/people/10"));
assertThat(link.getHref()).endsWith("/people/10");
}
@Test
public void appendingNullIsANoOp() {
Link link = linkTo(PersonControllerImpl.class).slash(null).withSelfRel();
assertThat(link.getHref(), endsWith("/people"));
assertThat(link.getHref()).endsWith("/people");
link = linkTo(PersonControllerImpl.class).slash((Object) null).withSelfRel();
assertThat(link.getHref(), endsWith("/people"));
assertThat(link.getHref()).endsWith("/people");
}
@Test
@@ -143,7 +143,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Link link = linkTo(methodOn(ControllerWithMethods.class).myMethod(null)).withSelfRel();
assertPointsToMockServer(link);
assertThat(link.getHref(), endsWith("/something/else"));
assertThat(link.getHref()).endsWith("/something/else");
}
@Test
@@ -151,7 +151,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithPathVariable("1")).withSelfRel();
assertPointsToMockServer(link);
assertThat(link.getHref(), endsWith("/something/1/foo"));
assertThat(link.getHref()).endsWith("/something/1/foo");
}
/**
@@ -212,7 +212,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Link link = linkTo(PersonController.class).slash("?foo=bar").withSelfRel();
UriComponents components = toComponents(link);
assertThat(components.getQuery(), is("foo=bar"));
assertThat(components.getQuery()).isEqualTo("foo=bar");
}
/**
@@ -224,7 +224,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodForNextPage("1", 10, 5)).withSelfRel();
UriComponents components = toComponents(link);
assertThat(components.getPath(), is("/something/1/foo"));
assertThat(components.getPath()).isEqualTo("/something/1/foo");
MultiValueMap<String, String> queryParams = components.getQueryParams();
assertThat(queryParams.get("limit"), contains("5"));
@@ -242,7 +242,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
.withSelfRel();
UriComponents components = toComponents(link);
assertThat(components.getPath(), is("/something/1/foo"));
assertThat(components.getPath()).isEqualTo("/something/1/foo");
MultiValueMap<String, String> queryParams = components.getQueryParams();
assertThat(queryParams.get("limit"), contains("5"));
@@ -258,8 +258,8 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
UriComponents components = linkTo(PersonController.class).slash("something?foo=bar").toUriComponentsBuilder()
.build();
assertThat(components.getPath(), is("/people/something"));
assertThat(components.getQuery(), is("foo=bar"));
assertThat(components.getPath()).isEqualTo("/people/something");
assertThat(components.getQuery()).isEqualTo("foo=bar");
}
/**
@@ -295,7 +295,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodForOptionalNextPage(null)).withSelfRel();
assertThat(link.getVariables(), contains(new TemplateVariable("offset", VariableType.REQUEST_PARAM)));
assertThat(link.expand().getHref(), endsWith("/foo"));
assertThat(link.expand().getHref()).endsWith("/foo");
}
/**
@@ -360,7 +360,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
public void discoversParentClassTypeMappingForInvocation() {
Link link = linkTo(methodOn(ChildController.class).myMethod()).withSelfRel();
assertThat(link.getHref(), endsWith("/parent/child"));
assertThat(link.getHref()).endsWith("/parent/child");
}
/**
@@ -370,7 +370,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
public void includesTypeMappingFromChildClass() {
Link link = linkTo(methodOn(ChildWithTypeMapping.class).myMethod()).withSelfRel();
assertThat(link.getHref(), endsWith("/child/parent"));
assertThat(link.getHref()).endsWith("/child/parent");
}
/**
@@ -380,8 +380,8 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
public void linksToMethodWithPathVariableContainingBlank() {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithPathVariable("with blank")).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/something/with%20blank/foo"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/something/with%20blank/foo");
}
/**
@@ -391,7 +391,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
public void usesRootMappingOfTargetClassForMethodsOfParentClass() {
Link link = linkTo(methodOn(ChildControllerWithRootMapping.class).someEmptyMappedMethod()).withSelfRel();
assertThat(link.getHref(), endsWith("/root"));
assertThat(link.getHref()).endsWith("/root");
}
/**
@@ -403,7 +403,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Method method = ParentControllerWithoutRootMapping.class.getMethod("someEmptyMappedMethod");
Link link = linkTo(ChildControllerWithRootMapping.class, method).withSelfRel();
assertThat(link.getHref(), endsWith("/root"));
assertThat(link.getHref()).endsWith("/root");
}
/**
@@ -459,7 +459,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodForOptionalSizeWithDefaultValue(null)).withSelfRel();
assertThat(link.getHref(), endsWith("/bar"));
assertThat(link.getHref()).endsWith("/bar");
}
/**
@@ -470,8 +470,8 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithRequestParam("Spring#\n")).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/something/foo?id=Spring%23%0A"));
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/something/foo?id=Spring%23%0A");
}
/**
@@ -483,8 +483,8 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Link link = linkTo(methodOn(PersonsAddressesController.class, "some id").getAddressesForCountry(null))
.withSelfRel();
assertThat(link.isTemplated(), is(true));
assertThat(link.getHref(), containsString("some%20id"));
assertThat(link.isTemplated()).isTrue();
assertThat(link.getHref()).contains("some%20id");
}
/**
@@ -515,7 +515,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
UriComponents components = toComponents(link);
assertThat(components.getQueryParams().get("query"), is(nullValue()));
assertThat(components.getQueryParams().get("query")).isNull();
}
/**
@@ -552,7 +552,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
request.setServletPath("/foo");
request.setRequestURI("/ctx/foo");
assertThat(linkTo(PersonControllerImpl.class).withSelfRel().getHref(), endsWith("/ctx/people"));
assertThat(linkTo(PersonControllerImpl.class).withSelfRel().getHref()).endsWith("/ctx/people");
}
/**
@@ -564,7 +564,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithJdk8Optional(Optional.<Integer> empty()))
.withSelfRel();
assertThat(link.isTemplated(), is(true));
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames(), contains("value"));
}
@@ -576,8 +576,8 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithJdk8Optional(Optional.of(1))).withSelfRel();
assertThat(link.isTemplated(), is(false));
assertThat(link.getHref(), endsWith("?value=1"));
assertThat(link.isTemplated()).isFalse();
assertThat(link.getHref()).endsWith("?value=1");
}
/**
@@ -587,7 +587,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
public void alternativePathVariableParameter() {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithAlternatePathVariable("bar")).withSelfRel();
assertThat(link.getHref(), is("http://localhost/something/bar/foo"));
assertThat(link.getHref()).isEqualTo("http://localhost/something/bar/foo");
}
private static UriComponents toComponents(Link link) {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.mvc;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.hateoas.Link;
@@ -36,15 +35,17 @@ public class DummyInvocationUtilsUnitTest extends TestUtils {
@Test
public void pathVariableWithDefaultParameter() {
Link link = ControllerLinkBuilder.linkTo(DummyInvocationUtils.methodOn(SampleController.class).someMethod(1L)).withSelfRel();
assertThat(link.getHref(), is("http://localhost/sample/1/foo"));
Link link = ControllerLinkBuilder.linkTo(DummyInvocationUtils.methodOn(SampleController.class).someMethod(1L))
.withSelfRel();
assertThat(link.getHref()).isEqualTo("http://localhost/sample/1/foo");
}
@Test
public void pathVariableWithNameParameter() {
Link link = ControllerLinkBuilder.linkTo(DummyInvocationUtils.methodOn(SampleController.class).someOtherMethod(2L)).withSelfRel();
assertThat(link.getHref(), is("http://localhost/sample/2/bar"));
Link link = ControllerLinkBuilder.linkTo(DummyInvocationUtils.methodOn(SampleController.class).someOtherMethod(2L))
.withSelfRel();
assertThat(link.getHref()).isEqualTo("http://localhost/sample/2/bar");
}
@RequestMapping("/sample")

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.mvc;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
@@ -32,7 +31,7 @@ public class ForwardedHeaderUnitTest {
*/
@Test
public void detectsProtoValue() {
assertThat(ForwardedHeader.of("for=192.0.2.60;proto=http").getProto(), is("http"));
assertThat(ForwardedHeader.of("for=192.0.2.60;proto=http").getProto()).isEqualTo("http");
}
/**
@@ -40,7 +39,7 @@ public class ForwardedHeaderUnitTest {
*/
@Test
public void detectsHostValue() {
assertThat(ForwardedHeader.of("host=localhost;proto=http").getHost(), is("localhost"));
assertThat(ForwardedHeader.of("host=localhost;proto=http").getHost()).isEqualTo("localhost");
}
/**
@@ -51,8 +50,8 @@ public class ForwardedHeaderUnitTest {
ForwardedHeader header = ForwardedHeader.of(null);
assertThat(header, is(notNullValue()));
assertThat(header.getHost(), is(nullValue()));
assertThat(header.getProto(), is(nullValue()));
assertThat(header).isNotNull();
assertThat(header.getHost()).isNull();
assertThat(header.getProto()).isNull();
}
}

View File

@@ -15,12 +15,10 @@
*/
package org.springframework.hateoas.mvc;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.List;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Resource;
@@ -47,14 +45,14 @@ public class HeaderLinksResponseEntityUnitTest {
HttpEntity<Resource<Object>> wrapper = HeaderLinksResponseEntity.wrap(entity);
// No links in resource anymore
assertThat(wrapper.getBody().getLinks(), is(Matchers.<Link> empty()));
assertThat(wrapper.getBody().getLinks()).isEmpty();
// Link found in header
List<String> linkHeader = wrapper.getHeaders().get("Link");
assertThat(linkHeader, hasSize(1));
assertThat(linkHeader).hasSize(1);
Link link = Link.valueOf(linkHeader.get(0));
assertThat(link, is(LINK));
assertThat(link).isEqualTo(LINK);
}
@Test
@@ -63,6 +61,6 @@ public class HeaderLinksResponseEntityUnitTest {
HttpEntity<Resource<Object>> entity = new HttpEntity<Resource<Object>>(resource);
ResponseEntity<Resource<Object>> wrappedEntity = HeaderLinksResponseEntity.wrap(entity);
assertThat(wrappedEntity.getStatusCode(), is(HttpStatus.OK));
assertThat(wrappedEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.mvc;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
import java.util.Arrays;
@@ -56,8 +55,8 @@ public class IdentifiableResourceAssemblerSupportUnitTest extends TestUtils {
PersonResource resource = assembler.createResource(person);
Link link = resource.getLink(Link.REL_SELF);
assertThat(link, is(notNullValue()));
assertThat(resource.getLinks().size(), is(1));
assertThat(link).isNotNull();
assertThat(resource.getLinks()).hasSize(1);
}
@Test
@@ -65,7 +64,7 @@ public class IdentifiableResourceAssemblerSupportUnitTest extends TestUtils {
PersonResource resource = assembler.createResourceWithId(person.alternateId, person);
Link selfLink = resource.getId();
assertThat(selfLink.getHref(), endsWith("/people/id"));
assertThat(selfLink.getHref()).endsWith("/people/id");
}
@Test
@@ -74,7 +73,7 @@ public class IdentifiableResourceAssemblerSupportUnitTest extends TestUtils {
PersonResource resource = new PersonResourceAssembler(ParameterizedController.class).createResource(person, person,
"bar");
Link selfLink = resource.getId();
assertThat(selfLink.getHref(), endsWith("/people/10/bar/addresses/10"));
assertThat(selfLink.getHref()).endsWith("/people/10/bar/addresses/10");
}
@Test
@@ -95,8 +94,8 @@ public class IdentifiableResourceAssemblerSupportUnitTest extends TestUtils {
PersonResource secondResource = new PersonResource();
secondResource.add(builder.slash(1L).withSelfRel());
assertThat(result.size(), is(2));
assertThat(result, hasItems(firstResource, secondResource));
assertThat(result).hasSize(2);
assertThat(result).contains(firstResource, secondResource);
}
@RequestMapping("/people")

View File

@@ -15,9 +15,8 @@
*/
package org.springframework.hateoas.mvc;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.util.ReflectionUtils.*;
@@ -27,13 +26,14 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
@@ -49,9 +49,7 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ReflectionUtils.MethodCallback;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;
/**
* Unit tests for {@link org.springframework.data.rest.webmvc.ResourceProcessorHandlerMethodReturnValueHandler}.
@@ -60,7 +58,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
* @author Jon Brisbin
*/
@RunWith(MockitoJUnitRunner.class)
public class ResourceProcessorHandlerMethodReturnValueHandlerUnitTests {
public class ResourceProcessorHandlerMethodReturnValueHandlerUnitTest {
static final Resource<String> FOO = new Resource<String>("foo");
static final Resources<Resource<String>> FOOS = new Resources<Resource<String>>(Collections.singletonList(FOO));
@@ -241,11 +239,23 @@ public class ResourceProcessorHandlerMethodReturnValueHandlerUnitTests {
invokeReturnValueHandler("resourceEntity", LONG_10_RES, LONG_20);
}
/**
* @see #362
*/
@Test
public void usesHeaderLinksResponseEntityForResourceIfConfigured() throws Exception {
usesHeaderLinksResponseEntityIfConfigured(Function.identity());
}
/**
* @see #362
*/
@Test
public void usesHeaderLinksResponseEntityIfConfigured() throws Exception {
usesHeaderLinksResponseEntityIfConfigured(it -> ResponseEntity.ok(it));
}
private void usesHeaderLinksResponseEntityIfConfigured(Function<Object, Object> mapper) throws Exception {
Resource<String> resource = new Resource<String>("foo", new Link("href", "rel"));
MethodParameter parameter = METHOD_PARAMS.get("resource");
@@ -253,10 +263,10 @@ public class ResourceProcessorHandlerMethodReturnValueHandlerUnitTests {
ResourceProcessorHandlerMethodReturnValueHandler handler = new ResourceProcessorHandlerMethodReturnValueHandler(
delegate, new ResourceProcessorInvoker(resourceProcessors));
handler.setRootLinksAsHeaders(true);
handler.handleReturnValue(resource, parameter, null, null);
handler.handleReturnValue(mapper.apply(resource), parameter, null, null);
verify(delegate, times(1)).handleReturnValue(Mockito.any(HeaderLinksResponseEntity.class), eq(parameter),
Mockito.any(ModelAndViewContainer.class), Mockito.any(NativeWebRequest.class));
verify(delegate, times(1)).handleReturnValue(any(HeaderLinksResponseEntity.class), eq(parameter), isNull(),
isNull());
}
/**
@@ -267,7 +277,7 @@ public class ResourceProcessorHandlerMethodReturnValueHandlerUnitTests {
ResolvableType type = ResolvableType.forClass(PagedStringResources.class);
assertThat(ResourcesProcessorWrapper.isValueTypeMatch(FOO_PAGE, type), is(true));
assertThat(ResourcesProcessorWrapper.isValueTypeMatch(FOO_PAGE, type)).isTrue();
}
/**
@@ -278,12 +288,12 @@ public class ResourceProcessorHandlerMethodReturnValueHandlerUnitTests {
EmbeddedWrappers wrappers = new EmbeddedWrappers(false);
Resources<Object> value = new Resources<Object>(
Collections.<Object>singleton(wrappers.emptyCollectionOf(Object.class)));
Collections.<Object> singleton(wrappers.emptyCollectionOf(Object.class)));
ResourcesProcessorWrapper wrapper = new ResourcesProcessorWrapper(new SpecialResourcesProcessor());
ResolvableType type = ResolvableType.forMethodReturnType(Controller.class.getMethod("resourcesOfObject"));
assertThat(wrapper.supports(type, value), is(false));
assertThat(wrapper.supports(type, value)).isFalse();
}
/**
@@ -334,7 +344,7 @@ public class ResourceProcessorHandlerMethodReturnValueHandlerUnitTests {
HandlerMethodReturnValueHandler handler = new ResourceProcessorHandlerMethodReturnValueHandler(delegate,
new ResourceProcessorInvoker(resourceProcessors));
assertThat(handler.supportsReturnType(parameter), is(value));
assertThat(handler.supportsReturnType(parameter)).isEqualTo(value);
}
enum StringResourceProcessor implements ResourceProcessor<Resource<String>> {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.mvc;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.http.MediaType.*;
import org.junit.Test;
@@ -69,12 +68,12 @@ public class TypeConstrainedMappingJackson2HttpMessageConverterUnitTest {
private static void assertCanRead(GenericHttpMessageConverter<Object> converter, Class<?> type, boolean expected) {
assertThat(converter.canRead(type, APPLICATION_JSON), is(expected));
assertThat(converter.canRead(type, type, APPLICATION_JSON), is(expected));
assertThat(converter.canRead(type, APPLICATION_JSON)).isEqualTo(expected);
assertThat(converter.canRead(type, type, APPLICATION_JSON)).isEqualTo(expected);
}
private static void assertCanWrite(GenericHttpMessageConverter<Object> converter, Class<?> type, boolean expected) {
assertThat(converter.canWrite(type, APPLICATION_JSON), is(expected));
assertThat(converter.canWrite(type, APPLICATION_JSON)).isEqualTo(expected);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.mvc;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.test.web.client.MockRestServiceServer.*;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
@@ -54,10 +53,10 @@ public class TypeReferencesIntegrationTest {
private static final String USER = "\"firstname\" : \"Dave\", \"lastname\" : \"Matthews\"";
private static final String RESOURCE = String.format("{ \"_links\" : { \"self\" : \"/resource\" }, %s }", USER);
private static final String RESOURCES_OF_USER = String.format(
"{ \"_links\" : { \"self\" : \"/resources\" }, \"_embedded\" : { \"users\" : [ { %s } ] }}", USER);
private static final String RESOURCES_OF_RESOURCE = String.format(
"{ \"_links\" : { \"self\" : \"/resources\" }, \"_embedded\" : { \"users\" : [ %s ] }}", RESOURCE);
private static final String RESOURCES_OF_USER = String
.format("{ \"_links\" : { \"self\" : \"/resources\" }, \"_embedded\" : { \"users\" : [ { %s } ] }}", USER);
private static final String RESOURCES_OF_RESOURCE = String
.format("{ \"_links\" : { \"self\" : \"/resources\" }, \"_embedded\" : { \"users\" : [ %s ] }}", RESOURCE);
@Configuration
@EnableHypermediaSupport(type = HypermediaType.HAL)
@@ -102,11 +101,11 @@ public class TypeReferencesIntegrationTest {
new ResourcesType<User>() {});
Resources<User> body = response.getBody();
assertThat(body.hasLink("self"), is(true));
assertThat(body.hasLink("self")).isTrue();
Collection<User> nested = body.getContent();
assertThat(nested, hasSize(1));
assertThat(nested).hasSize(1);
assertExpectedUser(nested.iterator().next());
}
@@ -122,24 +121,24 @@ public class TypeReferencesIntegrationTest {
new ResourcesType<Resource<User>>() {});
Resources<Resource<User>> body = response.getBody();
assertThat(body.hasLink("self"), is(true));
assertThat(body.hasLink("self")).isTrue();
Collection<Resource<User>> nested = body.getContent();
assertThat(nested, hasSize(1));
assertThat(nested).hasSize(1);
assertExpectedUserResource(nested.iterator().next());
}
private static void assertExpectedUserResource(Resource<User> user) {
assertThat(user.hasLink("self"), is(true));
assertThat(user.hasLink("self")).isTrue();
assertExpectedUser(user.getContent());
}
private static void assertExpectedUser(User user) {
assertThat(user.firstname, is("Dave"));
assertThat(user.lastname, is("Matthews"));
assertThat(user.firstname).isEqualTo("Dave");
assertThat(user.lastname).isEqualTo("Matthews");
}
static class User {