1 5 package org.easymock.tests; 6 7 import junit.framework.TestCase; 8 9 import org.easymock.MockControl; 10 11 public class RecordStateInvalidMatcherTest extends TestCase { 12 MockControl<IMethods> control; 13 14 IMethods mock; 15 16 protected void setUp() { 17 control = MockControl.createControl(IMethods.class); 18 mock = control.getMock(); 19 } 20 21 public void testSetMatcherBeforeCallingMethods() { 22 try { 23 control.setMatcher(MockControl.ARRAY_MATCHER); 24 fail(); 25 } catch (IllegalStateException expected) { 26 assertEquals( 27 "method call on the mock needed before setting matcher", 28 expected.getMessage()); 29 } 30 } 31 32 public void testSetMatcherTwice() { 33 mock.simpleMethod(); 34 control.setMatcher(MockControl.ARRAY_MATCHER); 35 try { 36 control.setMatcher(MockControl.EQUALS_MATCHER); 37 fail(); 38 } catch (IllegalStateException expected) { 39 assertEquals( 40 "for method simpleMethod(), a matcher has already been set", 41 expected.getMessage()); 42 } 43 } 44 45 public void testSetMatcherTwice2() { 46 mock.simpleMethodWithArgument(""); 47 control.setMatcher(MockControl.ARRAY_MATCHER); 48 try { 49 control.setMatcher(MockControl.EQUALS_MATCHER); 50 fail(); 51 } catch (IllegalStateException expected) { 52 assertEquals( 53 "for method simpleMethodWithArgument(...), a matcher has already been set", 54 expected.getMessage()); 55 } 56 } 57 58 public void testSetSameMatcherTwice() { 59 mock.simpleMethod(); 60 control.setMatcher(MockControl.ARRAY_MATCHER); 61 try { 62 control.setMatcher(MockControl.ARRAY_MATCHER); 63 } catch (IllegalStateException unexpected) { 64 fail("setting the same matcher should work"); 65 } 66 } 67 } 68
| Popular Tags
|