Polish "Unwrap InvocationTargetException in isLogConfigurationMessage"

Closes gh-12958
pull/12071/merge
Andy Wilkinson 7 years ago
parent 2953ed1dca
commit 678e125720

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2018 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.
@ -89,7 +89,6 @@ class SpringBootExceptionHandler implements UncaughtExceptionHandler {
if (ex instanceof InvocationTargetException) {
return isLogConfigurationMessage(ex.getCause());
}
String message = ex.getMessage();
if (message != null) {
for (String candidate : LOG_CONFIGURATION_MESSAGES) {

@ -16,17 +16,13 @@
package org.springframework.boot;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.InvocationTargetException;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
@ -34,48 +30,42 @@ import static org.mockito.Mockito.verifyZeroInteractions;
* Tests for {@link SpringBootExceptionHandler}.
*
* @author Henri Tremblay
* @author Andy Wilkinson
*/
public class SpringBootExceptionHandlerTest {
@Rule
public MockitoRule rule = MockitoJUnit.rule();
public class SpringBootExceptionHandlerTests {
@Mock
private Thread.UncaughtExceptionHandler parent;
private final UncaughtExceptionHandler parent = mock(UncaughtExceptionHandler.class);
@InjectMocks
private SpringBootExceptionHandler handler;
private final SpringBootExceptionHandler handler = new SpringBootExceptionHandler(
this.parent);
@Test
public void uncaughtException_shouldNotForwardLoggedErrorToParent() {
public void uncaughtExceptionDoesNotForwardLoggedErrorToParent() {
Thread thread = Thread.currentThread();
Exception ex = new Exception();
this.handler.registerLoggedException(ex);
this.handler.uncaughtException(thread, ex);
verifyZeroInteractions(this.parent);
}
@Test
public void uncaughtException_shouldForwardLogConfigurationErrorToParent() {
public void uncaughtExceptionForwardsLogConfigurationErrorToParent() {
Thread thread = Thread.currentThread();
Exception ex = new Exception("[stuff] Logback configuration error detected [stuff]");
Exception ex = new Exception(
"[stuff] Logback configuration error detected [stuff]");
this.handler.registerLoggedException(ex);
this.handler.uncaughtException(thread, ex);
verify(this.parent).uncaughtException(same(thread), same(ex));
}
@Test
public void uncaughtException_shouldForwardLogConfigurationErrorToParentEvenWhenWrapped() {
public void uncaughtExceptionForwardsWrappedLogConfigurationErrorToParent() {
Thread thread = Thread.currentThread();
Exception ex = new InvocationTargetException(new Exception("[stuff] Logback configuration error detected [stuff]", new Exception()));
Exception ex = new InvocationTargetException(new Exception(
"[stuff] Logback configuration error detected [stuff]", new Exception()));
this.handler.registerLoggedException(ex);
this.handler.uncaughtException(thread, ex);
verify(this.parent).uncaughtException(same(thread), same(ex));
}
}
Loading…
Cancel
Save