Skip to content

Commit 678e125

Browse files
committed
Polish "Unwrap InvocationTargetException in isLogConfigurationMessage"
Closes gh-12958
1 parent 2953ed1 commit 678e125

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

spring-boot/src/main/java/org/springframework/boot/SpringBootExceptionHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,7 +89,6 @@ private boolean isLogConfigurationMessage(Throwable ex) {
8989
if (ex instanceof InvocationTargetException) {
9090
return isLogConfigurationMessage(ex.getCause());
9191
}
92-
9392
String message = ex.getMessage();
9493
if (message != null) {
9594
for (String candidate : LOG_CONFIGURATION_MESSAGES) {

spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTest.java renamed to spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTests.java

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,56 @@
1616

1717
package org.springframework.boot;
1818

19+
import java.lang.Thread.UncaughtExceptionHandler;
1920
import java.lang.reflect.InvocationTargetException;
2021

21-
import org.junit.Rule;
2222
import org.junit.Test;
23-
import org.mockito.InjectMocks;
24-
import org.mockito.Mock;
25-
import org.mockito.junit.MockitoJUnit;
26-
import org.mockito.junit.MockitoRule;
2723

28-
29-
import static org.mockito.ArgumentMatchers.same;
24+
import static org.mockito.Matchers.same;
25+
import static org.mockito.Mockito.mock;
3026
import static org.mockito.Mockito.verify;
3127
import static org.mockito.Mockito.verifyZeroInteractions;
3228

3329
/**
3430
* Tests for {@link SpringBootExceptionHandler}.
3531
*
3632
* @author Henri Tremblay
33+
* @author Andy Wilkinson
3734
*/
38-
public class SpringBootExceptionHandlerTest {
39-
40-
@Rule
41-
public MockitoRule rule = MockitoJUnit.rule();
35+
public class SpringBootExceptionHandlerTests {
4236

43-
@Mock
44-
private Thread.UncaughtExceptionHandler parent;
37+
private final UncaughtExceptionHandler parent = mock(UncaughtExceptionHandler.class);
4538

46-
@InjectMocks
47-
private SpringBootExceptionHandler handler;
39+
private final SpringBootExceptionHandler handler = new SpringBootExceptionHandler(
40+
this.parent);
4841

4942
@Test
50-
public void uncaughtException_shouldNotForwardLoggedErrorToParent() {
43+
public void uncaughtExceptionDoesNotForwardLoggedErrorToParent() {
5144
Thread thread = Thread.currentThread();
5245
Exception ex = new Exception();
5346
this.handler.registerLoggedException(ex);
54-
5547
this.handler.uncaughtException(thread, ex);
56-
5748
verifyZeroInteractions(this.parent);
5849
}
5950

6051
@Test
61-
public void uncaughtException_shouldForwardLogConfigurationErrorToParent() {
52+
public void uncaughtExceptionForwardsLogConfigurationErrorToParent() {
6253
Thread thread = Thread.currentThread();
63-
Exception ex = new Exception("[stuff] Logback configuration error detected [stuff]");
54+
Exception ex = new Exception(
55+
"[stuff] Logback configuration error detected [stuff]");
6456
this.handler.registerLoggedException(ex);
65-
6657
this.handler.uncaughtException(thread, ex);
67-
6858
verify(this.parent).uncaughtException(same(thread), same(ex));
6959
}
7060

7161
@Test
72-
public void uncaughtException_shouldForwardLogConfigurationErrorToParentEvenWhenWrapped() {
62+
public void uncaughtExceptionForwardsWrappedLogConfigurationErrorToParent() {
7363
Thread thread = Thread.currentThread();
74-
Exception ex = new InvocationTargetException(new Exception("[stuff] Logback configuration error detected [stuff]", new Exception()));
64+
Exception ex = new InvocationTargetException(new Exception(
65+
"[stuff] Logback configuration error detected [stuff]", new Exception()));
7566
this.handler.registerLoggedException(ex);
76-
7767
this.handler.uncaughtException(thread, ex);
78-
7968
verify(this.parent).uncaughtException(same(thread), same(ex));
8069
}
70+
8171
}

0 commit comments

Comments
 (0)