diff --git a/src/docs/java/org/springframework/hateoas/EmployeeController.java b/src/docs/java/org/springframework/hateoas/EmployeeController.java index 6bc85aa3..0d32d49d 100644 --- a/src/docs/java/org/springframework/hateoas/EmployeeController.java +++ b/src/docs/java/org/springframework/hateoas/EmployeeController.java @@ -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()); diff --git a/src/test/java/org/springframework/hateoas/mediatype/collectionjson/CollectionJsonWebMvcIntegrationTest.java b/src/test/java/org/springframework/hateoas/mediatype/collectionjson/CollectionJsonWebMvcIntegrationTest.java index f8e772be..e17eec12 100644 --- a/src/test/java/org/springframework/hateoas/mediatype/collectionjson/CollectionJsonWebMvcIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/mediatype/collectionjson/CollectionJsonWebMvcIntegrationTest.java @@ -287,8 +287,7 @@ public class CollectionJsonWebMvcIntegrationTest { public ResponseEntity partiallyUpdateEmployee(@RequestBody EntityModel 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()); diff --git a/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsValidationIntegrationTest.java b/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsValidationIntegrationTest.java index 95ac7537..f02f88d0 100644 --- a/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsValidationIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsValidationIntegrationTest.java @@ -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"); } /** diff --git a/src/test/java/org/springframework/hateoas/server/reactive/WebFluxLinkBuilderTest.java b/src/test/java/org/springframework/hateoas/server/reactive/WebFluxLinkBuilderTest.java index fea78f56..511e745b 100644 --- a/src/test/java/org/springframework/hateoas/server/reactive/WebFluxLinkBuilderTest.java +++ b/src/test/java/org/springframework/hateoas/server/reactive/WebFluxLinkBuilderTest.java @@ -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 -> { diff --git a/src/test/java/org/springframework/hateoas/support/WebFluxEmployeeController.java b/src/test/java/org/springframework/hateoas/support/WebFluxEmployeeController.java index 955627dd..a95b7064 100644 --- a/src/test/java/org/springframework/hateoas/support/WebFluxEmployeeController.java +++ b/src/test/java/org/springframework/hateoas/support/WebFluxEmployeeController.java @@ -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() // + ); } } diff --git a/src/test/java/org/springframework/hateoas/support/WebMvcEmployeeController.java b/src/test/java/org/springframework/hateoas/support/WebMvcEmployeeController.java index 2bdf131b..4ce556c8 100644 --- a/src/test/java/org/springframework/hateoas/support/WebMvcEmployeeController.java +++ b/src/test/java/org/springframework/hateoas/support/WebMvcEmployeeController.java @@ -155,8 +155,7 @@ public class WebMvcEmployeeController { public ResponseEntity partiallyUpdateEmployee(@RequestBody EntityModel 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(); } }