1 /* 2 * Copyright (c) 2017 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockitousage.bugs; 6 7 import org.junit.Test; 8 import org.mockito.Mock; 9 import org.mockitousage.IMethods; 10 import org.mockitoutil.TestBase; 11 12 import static org.junit.Assert.fail; 13 import static org.mockito.Mockito.when; 14 15 public class NPEWhenCustomExceptionStackTraceReturnNullTest extends TestBase { 16 17 @Mock 18 IMethods mock; 19 20 class NullStackTraceException extends RuntimeException { 21 @Override 22 public Exception fillInStackTrace() { 23 return null; 24 } 25 } 26 27 //issue 866 28 @Test 29 public void shouldNotThrowNPE() { 30 when(mock.simpleMethod()).thenThrow(new NullStackTraceException()); 31 try { 32 mock.simpleMethod(); 33 fail(); 34 } catch(NullStackTraceException e) {} 35 } 36 } 37