1 5 package org.easymock.tests; 6 7 import java.io.IOException ; 8 9 import junit.framework.TestCase; 10 11 import org.easymock.MockControl; 12 13 public class RecordStateInvalidDefaultThrowableTest extends TestCase { 14 MockControl<IMethods> control; 15 16 IMethods mock; 17 18 private class CheckedException extends Exception { 19 } 20 21 protected void setUp() { 22 control = MockControl.createControl(IMethods.class); 23 mock = control.getMock(); 24 } 25 26 public void testThrowNull() { 27 mock.throwsNothing(false); 28 try { 29 control.setDefaultThrowable(null); 30 fail("NullPointerException expected"); 31 } catch (NullPointerException expected) { 32 assertEquals("null cannot be thrown", expected.getMessage()); 33 } 34 35 } 36 37 public void testThrowCheckedExceptionWhereNoCheckedExceptionIsThrown() { 38 mock.throwsNothing(false); 39 try { 40 control.setDefaultThrowable(new CheckedException()); 41 fail("IllegalArgumentException expected"); 42 } catch (IllegalArgumentException expected) { 43 assertEquals("last method called on mock cannot throw " 44 + this.getClass().getName() + "$CheckedException", expected 45 .getMessage()); 46 } 47 } 48 49 public void testThrowWrongCheckedException() throws IOException { 50 mock.throwsIOException(0); 51 try { 52 control.setDefaultThrowable(new CheckedException()); 53 fail("IllegalArgumentException expected"); 54 } catch (IllegalArgumentException expected) { 55 assertEquals("last method called on mock cannot throw " 56 + this.getClass().getName() + "$CheckedException", expected 57 .getMessage()); 58 } 59 } 60 } 61 | Popular Tags |