diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringBootExceptionHandler.java b/spring-boot/src/main/java/org/springframework/boot/SpringBootExceptionHandler.java index bf9e6d9f03..9101e34ed0 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringBootExceptionHandler.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringBootExceptionHandler.java @@ -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) { diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTest.java b/spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTests.java similarity index 63% rename from spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTest.java rename to spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTests.java index ec1d28e77e..33eeaf568d 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTest.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTests.java @@ -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 { +public class SpringBootExceptionHandlerTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule(); + private final UncaughtExceptionHandler parent = mock(UncaughtExceptionHandler.class); - @Mock - private Thread.UncaughtExceptionHandler parent; - - @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)); } + }