Use modern language features in tests

This commit is contained in:
Sam Brannen
2022-02-03 15:35:32 +01:00
parent 32cd73261a
commit b3f786728e
58 changed files with 117 additions and 151 deletions

View File

@@ -52,8 +52,7 @@ public abstract class AbstractHttpHandlerIntegrationTests {
*/
@RegisterExtension
TestExecutionExceptionHandler serverErrorToAssertionErrorConverter = (context, throwable) -> {
if (throwable instanceof HttpServerErrorException) {
HttpServerErrorException ex = (HttpServerErrorException) throwable;
if (throwable instanceof HttpServerErrorException ex) {
String responseBody = ex.getResponseBodyAsString();
if (StringUtils.hasText(responseBody)) {
String prefix = AssertionError.class.getName() + ": ";

View File

@@ -1282,8 +1282,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
public void setSession(HttpSession session) {
this.session = session;
if (session instanceof MockHttpSession) {
MockHttpSession mockSession = ((MockHttpSession) session);
if (session instanceof MockHttpSession mockSession) {
mockSession.access();
}
}

View File

@@ -447,8 +447,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
if (cookie.isHttpOnly()) {
buf.append("; HttpOnly");
}
if (cookie instanceof MockCookie) {
MockCookie mockCookie = (MockCookie) cookie;
if (cookie instanceof MockCookie mockCookie) {
if (StringUtils.hasText(mockCookie.getSameSite())) {
buf.append("; SameSite=").append(mockCookie.getSameSite());
}

View File

@@ -57,8 +57,7 @@ public class Pojo {
if (this == o) {
return true;
}
if (o instanceof Pojo) {
Pojo other = (Pojo) o;
if (o instanceof Pojo other) {
return this.foo.equals(other.foo) && this.bar.equals(other.bar);
}
return false;