1 5 package org.easymock.tests; 6 7 import junit.framework.TestCase; 8 9 import org.easymock.MockControl; 10 11 public class DefaultMatcherTest extends TestCase { 12 13 public static interface ArrayInterface { 14 void methodA(int[] argument); 15 16 void methodB(int[] argument); 17 } 18 19 private MockControl<ArrayInterface> control; 20 21 private ArrayInterface mock; 22 23 protected void setUp() { 24 control = MockControl.createControl(ArrayInterface.class); 25 mock = control.getMock(); 26 } 27 28 public void testDefaultMatcher() { 29 control.setDefaultMatcher(MockControl.ARRAY_MATCHER); 30 31 mock.methodA(new int[] { 1, 1 }); 32 mock.methodB(new int[] { 2, 2 }); 33 34 control.replay(); 35 36 mock.methodA(new int[] { 1, 1 }); 37 mock.methodB(new int[] { 2, 2 }); 38 39 control.verify(); 40 } 41 42 public void testFailInReplayState() { 43 control.replay(); 44 try { 45 control.setDefaultMatcher(MockControl.ARRAY_MATCHER); 46 fail(); 47 } catch (IllegalStateException expected) { 48 } 49 } 50 51 public void testFailIfDefaultMatcherSetTwice() { 52 control.setDefaultMatcher(MockControl.ARRAY_MATCHER); 53 try { 54 control.setDefaultMatcher(MockControl.ARRAY_MATCHER); 55 fail(); 56 } catch (IllegalStateException expected) { 57 assertEquals( 58 "default matcher can only be set once directly after creation of the MockControl", 59 expected.getMessage()); 60 } 61 } 62 63 public void testFailIfDefaultMatcherSetTooLate() { 64 mock.methodA(new int[] { 1, 1 }); 65 control.setVoidCallable(); 66 try { 67 control.setDefaultMatcher(MockControl.ARRAY_MATCHER); 68 fail(); 69 } catch (IllegalStateException expected) { 70 assertEquals( 71 "default matcher can only be set once directly after creation of the MockControl", 72 expected.getMessage()); 73 } 74 } 75 } 76 | Popular Tags |