Browse Source

Add nullability annotations to smoke-test/spring-boot-smoke-test-hateoas

See gh-46587
pull/46818/head
Moritz Halbritter 6 months ago
parent
commit
3c1b59350a
  1. 4
      smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/CustomerRepository.java
  2. 4
      smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/InMemoryCustomerRepository.java
  3. 20
      smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/package-info.java
  4. 20
      smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/package-info.java
  5. 6
      smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/CustomerController.java
  6. 20
      smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/package-info.java

4
smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/CustomerRepository.java

@ -18,10 +18,12 @@ package smoketest.hateoas.domain; @@ -18,10 +18,12 @@ package smoketest.hateoas.domain;
import java.util.List;
import org.jspecify.annotations.Nullable;
public interface CustomerRepository {
List<Customer> findAll();
Customer findOne(Long id);
@Nullable Customer findOne(Long id);
}

4
smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/InMemoryCustomerRepository.java

@ -19,6 +19,8 @@ package smoketest.hateoas.domain; @@ -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 { @@ -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;

20
smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/package-info.java

@ -0,0 +1,20 @@ @@ -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;

20
smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/package-info.java

@ -0,0 +1,20 @@ @@ -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;

6
smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/CustomerController.java

@ -55,7 +55,11 @@ public class CustomerController { @@ -55,7 +55,11 @@ public class CustomerController {
@GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
HttpEntity<EntityModel<Customer>> showCustomer(@PathVariable Long id) {
EntityModel<Customer> resource = EntityModel.of(this.repository.findOne(id));
Customer customer = this.repository.findOne(id);
if (customer == null) {
return ResponseEntity.notFound().build();
}
EntityModel<Customer> resource = EntityModel.of(customer);
resource.add(this.entityLinks.linkToItemResource(Customer.class, id));
return new ResponseEntity<>(resource, HttpStatus.OK);
}

20
smoke-test/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/package-info.java

@ -0,0 +1,20 @@ @@ -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;
Loading…
Cancel
Save