1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 6 package org.mockitousage.bugs; 7 8 import org.junit.Test; 9 import org.mockito.Mock; 10 import org.mockitousage.IMethods; 11 import org.mockitoutil.TestBase; 12 13 import static junit.framework.TestCase.fail; 14 import static org.mockito.Mockito.when; 15 16 public class NPEWhenMockingThrowablesTest extends TestBase { 17 18 @Mock IMethods mock; 19 @Mock DummyException mock2; 20 21 class DummyException extends RuntimeException { 22 private static final long serialVersionUID = 1L; 23 } 24 25 //issue 70 26 @Test shouldNotThrowNPE()27 public void shouldNotThrowNPE() { 28 when(mock.simpleMethod()).thenThrow(mock2); 29 try { 30 mock.simpleMethod(); 31 fail(); 32 } catch(DummyException e) {} 33 } 34 } 35