Add nullability annotations to smoke-test/spring-boot-smoke-test-web-thymeleaf
See gh-46587
This commit is contained in:
parent
e94cee4860
commit
31d8faa520
|
@ -20,6 +20,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
public class InMemoryMessageRepository implements MessageRepository {
|
||||
|
||||
private static final AtomicLong counter = new AtomicLong();
|
||||
|
@ -43,7 +45,7 @@ public class InMemoryMessageRepository implements MessageRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Message findMessage(Long id) {
|
||||
public @Nullable Message findMessage(Long id) {
|
||||
return this.messages.get(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,25 +18,26 @@ package smoketest.web.thymeleaf;
|
|||
|
||||
import java.util.Calendar;
|
||||
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
public class Message {
|
||||
|
||||
private Long id;
|
||||
private @Nullable Long id;
|
||||
|
||||
@NotEmpty(message = "Text is required.")
|
||||
private String text;
|
||||
private @Nullable String text;
|
||||
|
||||
@NotEmpty(message = "Summary is required.")
|
||||
private String summary;
|
||||
private @Nullable String summary;
|
||||
|
||||
private Calendar created = Calendar.getInstance();
|
||||
|
||||
public Long getId() {
|
||||
public @Nullable Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
public void setId(@Nullable Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
@ -48,19 +49,19 @@ public class Message {
|
|||
this.created = created;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
public @Nullable String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
public void setText(@Nullable String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
public @Nullable String getSummary() {
|
||||
return this.summary;
|
||||
}
|
||||
|
||||
public void setSummary(String summary) {
|
||||
public void setSummary(@Nullable String summary) {
|
||||
this.summary = summary;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,13 +16,15 @@
|
|||
|
||||
package smoketest.web.thymeleaf;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
public interface MessageRepository {
|
||||
|
||||
Iterable<Message> findAll();
|
||||
|
||||
Message save(Message message);
|
||||
|
||||
Message findMessage(Long id);
|
||||
@Nullable Message findMessage(Long id);
|
||||
|
||||
void deleteMessage(Long id);
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package smoketest.web.thymeleaf;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -33,7 +35,7 @@ public class SampleWebUiApplication {
|
|||
public Converter<String, Message> messageConverter() {
|
||||
return new Converter<>() {
|
||||
@Override
|
||||
public Message convert(String id) {
|
||||
public @Nullable Message convert(String id) {
|
||||
return messageRepository().findMessage(Long.valueOf(id));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -21,6 +21,7 @@ import smoketest.web.thymeleaf.Message;
|
|||
import smoketest.web.thymeleaf.MessageRepository;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
@ -63,7 +64,9 @@ public class MessageController {
|
|||
}
|
||||
message = this.messageRepository.save(message);
|
||||
redirect.addFlashAttribute("globalMessage", "view.success");
|
||||
return new ModelAndView("redirect:/{message.id}", "message.id", message.getId());
|
||||
Long id = message.getId();
|
||||
Assert.state(id != null, "'id' must not be null");
|
||||
return new ModelAndView("redirect:/{message.id}", "message.id", id);
|
||||
}
|
||||
|
||||
@RequestMapping("foo")
|
||||
|
|
|
@ -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.web.thymeleaf.mvc;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
|
@ -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.web.thymeleaf;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
Loading…
Reference in New Issue