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 RecordStateInvalidThrowableTest extends TestCase { 14 15 MockControl<IMethods> control; 16 17 IMethods mock; 18 19 private class CheckedException extends Exception { 20 } 21 22 protected void setUp() { 23 control = MockControl.createControl(IMethods.class); 24 mock = control.getMock(); 25 } 26 27 public void testThrowNull() { 28 mock.throwsNothing(false); 29 try { 30 control.setThrowable(null); 31 fail("NullPointerException expected"); 32 } catch (NullPointerException expected) { 33 assertEquals("null cannot be thrown", expected.getMessage()); 34 } 35 36 } 37 38 public void testThrowCheckedExceptionWhereNoCheckedExceptionIsThrown() { 39 mock.throwsNothing(false); 40 try { 41 control.setThrowable(new CheckedException()); 42 fail("IllegalArgumentException expected"); 43 } catch (IllegalArgumentException expected) { 44 assertEquals("last method called on mock cannot throw " 45 + CheckedException.class.getName(), expected.getMessage()); 46 } 47 } 48 49 public void testThrowWrongCheckedException() throws IOException { 50 mock.throwsIOException(0); 51 try { 52 control.setThrowable(new CheckedException()); 53 fail("IllegalArgumentException expected"); 54 } catch (IllegalArgumentException expected) { 55 assertEquals("last method called on mock cannot throw " 56 + CheckedException.class.getName(), expected.getMessage()); 57 } 58 } 59 60 public void testThrowAfterThrowable() throws IOException { 61 mock.throwsIOException(0); 62 control.setThrowable(new IOException (), MockControl.ONE_OR_MORE); 63 try { 64 control.setThrowable(new IOException ()); 65 fail("IllegalStateException expected"); 66 } catch (IllegalStateException expected) { 67 assertEquals( 68 "last method called on mock already has a non-fixed count set.", 69 expected.getMessage()); 70 } 71 } 72 } 73
| Popular Tags
|