Commit 4bb84234 authored by jason's avatar jason Committed by Stephane Nicoll

Simplify some code

See gh-17860
parent e8effad0
...@@ -123,9 +123,7 @@ class RequestPredicateFactory { ...@@ -123,9 +123,7 @@ class RequestPredicateFactory {
} }
if (WebEndpointResponse.class.isAssignableFrom(method.getReturnType())) { if (WebEndpointResponse.class.isAssignableFrom(method.getReturnType())) {
ResolvableType returnType = ResolvableType.forMethodReturnType(method); ResolvableType returnType = ResolvableType.forMethodReturnType(method);
if (ResolvableType.forClass(Resource.class).isAssignableFrom(returnType.getGeneric(0))) { return ResolvableType.forClass(Resource.class).isAssignableFrom(returnType.getGeneric(0));
return true;
}
} }
return false; return false;
} }
......
...@@ -89,7 +89,7 @@ public final class Health { ...@@ -89,7 +89,7 @@ public final class Health {
if (obj == this) { if (obj == this) {
return true; return true;
} }
if (obj != null && obj instanceof Health) { if (obj instanceof Health) {
Health other = (Health) obj; Health other = (Health) obj;
return this.status.equals(other.status) && this.details.equals(other.details); return this.status.equals(other.status) && this.details.equals(other.details);
} }
......
...@@ -97,11 +97,8 @@ public class HealthWebEndpointResponseMapper { ...@@ -97,11 +97,8 @@ public class HealthWebEndpointResponseMapper {
} }
private boolean canSeeDetails(SecurityContext securityContext, ShowDetails showDetails) { private boolean canSeeDetails(SecurityContext securityContext, ShowDetails showDetails) {
if (showDetails == ShowDetails.NEVER || (showDetails == ShowDetails.WHEN_AUTHORIZED return showDetails != ShowDetails.NEVER && (showDetails != ShowDetails.WHEN_AUTHORIZED
&& (securityContext.getPrincipal() == null || !isUserInRole(securityContext)))) { || (securityContext.getPrincipal() != null && isUserInRole(securityContext)));
return false;
}
return true;
} }
private boolean isUserInRole(SecurityContext securityContext) { private boolean isUserInRole(SecurityContext securityContext) {
......
...@@ -107,7 +107,7 @@ public final class Status { ...@@ -107,7 +107,7 @@ public final class Status {
if (obj == this) { if (obj == this) {
return true; return true;
} }
if (obj != null && obj instanceof Status) { if (obj instanceof Status) {
return ObjectUtils.nullSafeEquals(this.code, ((Status) obj).code); return ObjectUtils.nullSafeEquals(this.code, ((Status) obj).code);
} }
return false; return false;
......
...@@ -71,7 +71,7 @@ public final class Info { ...@@ -71,7 +71,7 @@ public final class Info {
if (obj == this) { if (obj == this) {
return true; return true;
} }
if (obj != null && obj instanceof Info) { if (obj instanceof Info) {
Info other = (Info) obj; Info other = (Info) obj;
return this.details.equals(other.details); return this.details.equals(other.details);
} }
......
...@@ -83,9 +83,7 @@ class PlainTextThreadDumpFormatter { ...@@ -83,9 +83,7 @@ class PlainTextThreadDumpFormatter {
LockInfo lockInfo = info.getLockInfo(); LockInfo lockInfo = info.getLockInfo();
if (firstElement && lockInfo != null) { if (firstElement && lockInfo != null) {
if (element.getClassName().equals(Object.class.getName()) && element.getMethodName().equals("wait")) { if (element.getClassName().equals(Object.class.getName()) && element.getMethodName().equals("wait")) {
if (lockInfo != null) { writer.printf("\t- waiting on %s%n", format(lockInfo));
writer.printf("\t- waiting on %s%n", format(lockInfo));
}
} }
else { else {
String lockOwner = info.getLockOwnerName(); String lockOwner = info.getLockOwnerName();
......
...@@ -36,7 +36,7 @@ class AuditEventTests { ...@@ -36,7 +36,7 @@ class AuditEventTests {
@Test @Test
void nowEvent() { void nowEvent() {
AuditEvent event = new AuditEvent("phil", "UNKNOWN", Collections.singletonMap("a", (Object) "b")); AuditEvent event = new AuditEvent("phil", "UNKNOWN", Collections.singletonMap("a", "b"));
assertThat(event.getData().get("a")).isEqualTo("b"); assertThat(event.getData().get("a")).isEqualTo("b");
assertThat(event.getType()).isEqualTo("UNKNOWN"); assertThat(event.getType()).isEqualTo("UNKNOWN");
assertThat(event.getPrincipal()).isEqualTo("phil"); assertThat(event.getPrincipal()).isEqualTo("phil");
...@@ -52,21 +52,21 @@ class AuditEventTests { ...@@ -52,21 +52,21 @@ class AuditEventTests {
@Test @Test
void nullPrincipalIsMappedToEmptyString() { void nullPrincipalIsMappedToEmptyString() {
AuditEvent auditEvent = new AuditEvent(null, "UNKNOWN", Collections.singletonMap("a", (Object) "b")); AuditEvent auditEvent = new AuditEvent(null, "UNKNOWN", Collections.singletonMap("a", "b"));
assertThat(auditEvent.getPrincipal()).isEmpty(); assertThat(auditEvent.getPrincipal()).isEmpty();
} }
@Test @Test
void nullTimestamp() { void nullTimestamp() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> new AuditEvent(null, "phil", "UNKNOWN", Collections.singletonMap("a", (Object) "b"))) .isThrownBy(() -> new AuditEvent(null, "phil", "UNKNOWN", Collections.singletonMap("a", "b")))
.withMessageContaining("Timestamp must not be null"); .withMessageContaining("Timestamp must not be null");
} }
@Test @Test
void nullType() { void nullType() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> new AuditEvent("phil", null, Collections.singletonMap("a", (Object) "b"))) .isThrownBy(() -> new AuditEvent("phil", null, Collections.singletonMap("a", "b")))
.withMessageContaining("Type must not be null"); .withMessageContaining("Type must not be null");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment