1 5 package org.easymock.tests; 6 7 import junit.framework.TestCase; 8 9 import org.easymock.MockControl; 10 11 public class RecordStateInvalidReturnValueTest 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 testSetInvalidBooleanReturnValue() { 22 mock.oneArgumentMethod(false); 23 try { 24 control.setReturnValue(false); 25 fail("IllegalStateException expected"); 26 } catch (IllegalStateException e) { 27 assertEquals("incompatible return value type", e.getMessage()); 28 } 29 30 } 31 32 public void testSetInvalidLongReturnValue() { 33 mock.oneArgumentMethod(false); 34 try { 35 control.setReturnValue((long) 0); 36 fail("IllegalStateException expected"); 37 } catch (IllegalStateException e) { 38 assertEquals("incompatible return value type", e.getMessage()); 39 } 40 } 41 42 public void testSetInvalidFloatReturnValue() { 43 mock.oneArgumentMethod(false); 44 try { 45 control.setReturnValue((float) 0); 46 fail("IllegalStateException expected"); 47 } catch (IllegalStateException e) { 48 assertEquals("incompatible return value type", e.getMessage()); 49 } 50 } 51 52 public void testSetInvalidDoubleReturnValue() { 53 mock.oneArgumentMethod(false); 54 try { 55 control.setReturnValue((double) 0); 56 fail("IllegalStateException expected"); 57 } catch (IllegalStateException e) { 58 assertEquals("incompatible return value type", e.getMessage()); 59 } 60 } 61 62 public void testSetInvalidObjectReturnValue() { 63 mock.oneArgumentMethod(false); 64 try { 65 control.setReturnValue(new Object ()); 66 fail("IllegalStateException expected"); 67 } catch (IllegalStateException e) { 68 assertEquals("incompatible return value type", e.getMessage()); 69 } 70 } 71 72 public void testSetInvalidBooleanReturnValueCount() { 73 mock.oneArgumentMethod(false); 74 try { 75 control.setReturnValue(false, 3); 76 fail("IllegalStateException expected"); 77 } catch (IllegalStateException e) { 78 assertEquals("incompatible return value type", e.getMessage()); 79 } 80 81 } 82 83 public void testSetInvalidLongReturnValueCount() { 84 mock.oneArgumentMethod(false); 85 try { 86 control.setReturnValue((long) 0, 3); 87 fail("IllegalStateException expected"); 88 } catch (IllegalStateException e) { 89 assertEquals("incompatible return value type", e.getMessage()); 90 } 91 } 92 93 public void testSetInvalidFloatReturnValueCount() { 94 mock.oneArgumentMethod(false); 95 try { 96 control.setReturnValue((float) 0, 3); 97 fail("IllegalStateException expected"); 98 } catch (IllegalStateException e) { 99 assertEquals("incompatible return value type", e.getMessage()); 100 } 101 } 102 103 public void testSetInvalidDoubleReturnValueCount() { 104 mock.oneArgumentMethod(false); 105 try { 106 control.setReturnValue((double) 0, 3); 107 fail("IllegalStateException expected"); 108 } catch (IllegalStateException e) { 109 assertEquals("incompatible return value type", e.getMessage()); 110 } 111 } 112 113 public void testSetInvalidObjectReturnValueCount() { 114 mock.oneArgumentMethod(false); 115 try { 116 control.setReturnValue(new Object (), 3); 117 fail("IllegalStateException expected"); 118 } catch (IllegalStateException e) { 119 assertEquals("incompatible return value type", e.getMessage()); 120 } 121 } 122 123 public void testSetReturnValueForVoidMethod() { 124 mock.simpleMethod(); 125 try { 126 control.setReturnValue(null); 127 fail("IllegalStateException expected"); 128 } catch (IllegalStateException e) { 129 assertEquals("void method cannot return a value", e.getMessage()); 130 } 131 } 132 } 133 | Popular Tags |