mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-26 20:09:02 +00:00
Add nullability annotations to smoke-test/spring-boot-smoke-test-hateoas
See gh-46587
This commit is contained in:
+3
-1
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
+3
-1
@@ -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;
|
||||
|
||||
+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
@@ -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;
|
||||
+5
-1
@@ -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
@@ -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;
|
||||
Reference in New Issue
Block a user