#860 - Polishing.

Removed some superfluous variables.
Replaces Hamcrest with AssertJ.
Formatting.
This commit is contained in:
Jens Schauder
2019-03-12 08:21:37 +01:00
committed by Greg Turnquist
parent c35a700eca
commit dbf9e4bc73
6 changed files with 28 additions and 32 deletions

View File

@@ -155,8 +155,7 @@ public class EmployeeController {
// end::patch[]
{
Employee oldEmployee = EMPLOYEES.get(id);
Employee newEmployee = oldEmployee;
Employee newEmployee = EMPLOYEES.get(id);
if (employee.getContent().getName() != null) {
newEmployee = newEmployee.withName(employee.getContent().getName());

View File

@@ -287,8 +287,7 @@ public class CollectionJsonWebMvcIntegrationTest {
public ResponseEntity<?> partiallyUpdateEmployee(@RequestBody EntityModel<Employee> employee,
@PathVariable Integer id) {
Employee oldEmployee = EMPLOYEES.get(id);
Employee newEmployee = oldEmployee;
Employee newEmployee = EMPLOYEES.get(id);
if (employee.getContent().getName() != null) {
newEmployee = newEmployee.withName(employee.getContent().getName());

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.hateoas.mediatype.hal.forms;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -84,8 +83,9 @@ public class HalFormsValidationIntegrationTest {
.andReturn() //
.getResolvedException();
assertThat(exception.getMessage(), containsString("Affordance's URI http://localhost/employees"));
assertThat(exception.getMessage(), containsString("doesn't match self link http://localhost/employees/0"));
assertThat(exception).isNotNull();
assertThat(exception.getMessage()).contains("Affordance's URI http://localhost/employees");
assertThat(exception.getMessage()).contains("doesn't match self link http://localhost/employees/0");
}
@Test
@@ -95,8 +95,9 @@ public class HalFormsValidationIntegrationTest {
.andExpect(status().is5xxServerError()) //
.andReturn().getResolvedException();
assertThat(exception.getMessage(), containsString("Affordance's URI http://localhost/employees/0"));
assertThat(exception.getMessage(), containsString("doesn't match self link http://localhost/employees"));
assertThat(exception).isNotNull();
assertThat(exception.getMessage()).contains("Affordance's URI http://localhost/employees/0");
assertThat(exception.getMessage()).contains("doesn't match self link http://localhost/employees");
}
/**

View File

@@ -207,7 +207,7 @@ public class WebFluxLinkBuilderTest {
* @see #728
*/
@Test
public void linkToRouteWithNoExchangeInTheContextShouldFallbackToRelativeUris() throws URISyntaxException {
public void linkToRouteWithNoExchangeInTheContextShouldFallbackToRelativeUris() {
linkTo(methodOn(TestController2.class).root()).withSelfRel().toMono() //
.as(StepVerifier::create).expectNextMatches(link -> {
@@ -224,7 +224,7 @@ public class WebFluxLinkBuilderTest {
* @see #728
*/
@Test
public void linkToRouteWithExplictExchangeBeingNullShouldFallbackToRelativeUris() throws URISyntaxException {
public void linkToRouteWithExplictExchangeBeingNullShouldFallbackToRelativeUris() {
linkTo(methodOn(TestController2.class).root(), null).withSelfRel().toMono() //
.as(StepVerifier::create).expectNextMatches(link -> {

View File

@@ -66,7 +66,7 @@ public class WebFluxEmployeeController {
WebFluxEmployeeController controller = methodOn(WebFluxEmployeeController.class);
return Flux.fromIterable(EMPLOYEES.keySet()) //
.flatMap(id -> findOne(id)) //
.flatMap(this::findOne) //
.collectList() //
.flatMap(resources -> linkTo(controller.all()).withSelfRel() //
.andAffordance(controller.newEmployee(null)) //
@@ -83,7 +83,7 @@ public class WebFluxEmployeeController {
WebFluxEmployeeController controller = methodOn(WebFluxEmployeeController.class);
return Flux.fromIterable(EMPLOYEES.keySet()) //
.flatMap(id -> findOne(id)) //
.flatMap(this::findOne) //
.filter(resource -> {
boolean nameMatches = name //
@@ -94,13 +94,12 @@ public class WebFluxEmployeeController {
.orElse(true);
return nameMatches && roleMatches;
}).collectList().flatMap(resources -> {
return linkTo(controller.all()).withSelfRel() //
.andAffordance(controller.newEmployee(null)) //
.andAffordance(controller.search(null, null)) //
.toMono() //
.map(selfLink -> new CollectionModel<>(resources, selfLink));
});
}).collectList().flatMap(resources -> linkTo(controller.all()) //
.withSelfRel() //
.andAffordance(controller.newEmployee(null)) //
.andAffordance(controller.search(null, null)) //
.toMono() //
.map(selfLink -> new CollectionModel<>(resources, selfLink)));
}
@GetMapping("/employees/{id}")
@@ -118,9 +117,7 @@ public class WebFluxEmployeeController {
return selfLink.zipWith(employeesLink) //
.map(function((left, right) -> Links.of(left, right))) //
.map(links -> {
return new EntityModel<>(EMPLOYEES.get(id), links);
});
.map(links -> new EntityModel<>(EMPLOYEES.get(id), links));
}
@PostMapping("/employees")
@@ -144,6 +141,7 @@ public class WebFluxEmployeeController {
@PathVariable Integer id) {
return employee.flatMap(resource -> {
EMPLOYEES.put(id, resource.getContent());
return findOne(id);
}).map(findOne -> ResponseEntity.noContent() //
@@ -157,8 +155,7 @@ public class WebFluxEmployeeController {
return employee //
.flatMap(resource -> {
Employee oldEmployee = EMPLOYEES.get(id);
Employee newEmployee = oldEmployee;
Employee newEmployee = EMPLOYEES.get(id);
if (resource.getContent().getName() != null) {
newEmployee = newEmployee.withName(resource.getContent().getName());
@@ -172,8 +169,9 @@ public class WebFluxEmployeeController {
return findOne(id);
}) //
.map(findOne -> ResponseEntity.noContent() //
.location(findOne.getRequiredLink(IanaLinkRelations.SELF).toUri()).build());
}).map(findOne -> ResponseEntity.noContent() //
.location(findOne.getRequiredLink(IanaLinkRelations.SELF).toUri()) //
.build() //
);
}
}

View File

@@ -155,8 +155,7 @@ public class WebMvcEmployeeController {
public ResponseEntity<?> partiallyUpdateEmployee(@RequestBody EntityModel<Employee> employee,
@PathVariable Integer id) {
Employee oldEmployee = EMPLOYEES.get(id);
Employee newEmployee = oldEmployee;
Employee newEmployee = EMPLOYEES.get(id);
if (employee.getContent().getName() != null) {
newEmployee = newEmployee.withName(employee.getContent().getName());
@@ -172,7 +171,7 @@ public class WebMvcEmployeeController {
.noContent() //
.location(findOne(id) //
.getRequiredLink(IanaLinkRelations.SELF) //
.toUri())
.toUri()) //
.build();
}
}