diff --git a/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/CustomerRepository.java b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/CustomerRepository.java index 33edf56584e..abaaaf3b7a5 100644 --- a/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/CustomerRepository.java +++ b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/CustomerRepository.java @@ -18,10 +18,12 @@ package smoketest.hateoas.domain; import java.util.List; +import org.jspecify.annotations.Nullable; + public interface CustomerRepository { List findAll(); - Customer findOne(Long id); + @Nullable Customer findOne(Long id); } diff --git a/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/InMemoryCustomerRepository.java b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/InMemoryCustomerRepository.java index c08d38cbbc7..dd4d88883d4 100644 --- a/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/InMemoryCustomerRepository.java +++ b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/InMemoryCustomerRepository.java @@ -19,6 +19,8 @@ package smoketest.hateoas.domain; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.stereotype.Repository; import org.springframework.util.ObjectUtils; @@ -39,7 +41,7 @@ public class InMemoryCustomerRepository implements CustomerRepository { } @Override - public Customer findOne(Long id) { + public @Nullable Customer findOne(Long id) { for (Customer customer : this.customers) { if (ObjectUtils.nullSafeEquals(customer.getId(), id)) { return customer; diff --git a/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/package-info.java b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/package-info.java new file mode 100644 index 00000000000..56d4b3df095 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@NullMarked +package smoketest.hateoas.domain; + +import org.jspecify.annotations.NullMarked; diff --git a/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/package-info.java b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/package-info.java new file mode 100644 index 00000000000..4d987e60f67 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@NullMarked +package smoketest.hateoas; + +import org.jspecify.annotations.NullMarked; diff --git a/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/CustomerController.java b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/CustomerController.java index 79f326dcfb0..df64c2ad3bf 100644 --- a/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/CustomerController.java +++ b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/CustomerController.java @@ -55,7 +55,11 @@ public class CustomerController { @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) HttpEntity> showCustomer(@PathVariable Long id) { - EntityModel resource = EntityModel.of(this.repository.findOne(id)); + Customer customer = this.repository.findOne(id); + if (customer == null) { + return ResponseEntity.notFound().build(); + } + EntityModel resource = EntityModel.of(customer); resource.add(this.entityLinks.linkToItemResource(Customer.class, id)); return new ResponseEntity<>(resource, HttpStatus.OK); } diff --git a/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/package-info.java b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/package-info.java new file mode 100644 index 00000000000..e28548fd2d8 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@NullMarked +package smoketest.hateoas.web; + +import org.jspecify.annotations.NullMarked;