1 package org.mockitousage.bugs; 2 3 import org.junit.Test; 4 import org.mockito.Mock; 5 import org.mockitousage.IMethods; 6 import org.mockitoutil.TestBase; 7 8 import static junit.framework.TestCase.fail; 9 import static org.mockito.Mockito.when; 10 11 public class NPEWhenCustomExceptionStackTraceReturnNullTest extends TestBase { 12 13 @Mock 14 IMethods mock; 15 16 class NullStackTraceException extends RuntimeException { 17 @Override fillInStackTrace()18 public Exception fillInStackTrace() { 19 return null; 20 } 21 } 22 23 //issue 866 24 @Test shouldNotThrowNPE()25 public void shouldNotThrowNPE() { 26 when(mock.simpleMethod()).thenThrow(new NullStackTraceException()); 27 try { 28 mock.simpleMethod(); 29 fail(); 30 } catch(NullStackTraceException e) {} 31 } 32 } 33