Simplify some code

See gh-17860
This commit is contained in:
jason
2019-08-14 13:59:40 +08:00
committed by Stephane Nicoll
parent e8effad0b4
commit 4bb842343a
7 changed files with 11 additions and 18 deletions

View File

@@ -123,9 +123,7 @@ class RequestPredicateFactory {
}
if (WebEndpointResponse.class.isAssignableFrom(method.getReturnType())) {
ResolvableType returnType = ResolvableType.forMethodReturnType(method);
if (ResolvableType.forClass(Resource.class).isAssignableFrom(returnType.getGeneric(0))) {
return true;
}
return ResolvableType.forClass(Resource.class).isAssignableFrom(returnType.getGeneric(0));
}
return false;
}

View File

@@ -89,7 +89,7 @@ public final class Health {
if (obj == this) {
return true;
}
if (obj != null && obj instanceof Health) {
if (obj instanceof Health) {
Health other = (Health) obj;
return this.status.equals(other.status) && this.details.equals(other.details);
}

View File

@@ -97,11 +97,8 @@ public class HealthWebEndpointResponseMapper {
}
private boolean canSeeDetails(SecurityContext securityContext, ShowDetails showDetails) {
if (showDetails == ShowDetails.NEVER || (showDetails == ShowDetails.WHEN_AUTHORIZED
&& (securityContext.getPrincipal() == null || !isUserInRole(securityContext)))) {
return false;
}
return true;
return showDetails != ShowDetails.NEVER && (showDetails != ShowDetails.WHEN_AUTHORIZED
|| (securityContext.getPrincipal() != null && isUserInRole(securityContext)));
}
private boolean isUserInRole(SecurityContext securityContext) {

View File

@@ -107,7 +107,7 @@ public final class Status {
if (obj == this) {
return true;
}
if (obj != null && obj instanceof Status) {
if (obj instanceof Status) {
return ObjectUtils.nullSafeEquals(this.code, ((Status) obj).code);
}
return false;

View File

@@ -71,7 +71,7 @@ public final class Info {
if (obj == this) {
return true;
}
if (obj != null && obj instanceof Info) {
if (obj instanceof Info) {
Info other = (Info) obj;
return this.details.equals(other.details);
}

View File

@@ -83,9 +83,7 @@ class PlainTextThreadDumpFormatter {
LockInfo lockInfo = info.getLockInfo();
if (firstElement && lockInfo != null) {
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 {
String lockOwner = info.getLockOwnerName();

View File

@@ -36,7 +36,7 @@ class AuditEventTests {
@Test
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.getType()).isEqualTo("UNKNOWN");
assertThat(event.getPrincipal()).isEqualTo("phil");
@@ -52,21 +52,21 @@ class AuditEventTests {
@Test
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();
}
@Test
void nullTimestamp() {
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");
}
@Test
void nullType() {
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");
}