Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23471/input/javasrc/biz/xsoftware/test/mock2
Modified Files:
FakeSystem.java TestMockCreator.java
Added Files:
TestIgnoredMethods.java
Log Message:
Fixed some bugs with method not being ignored correctly. general cleanup
--- NEW FILE: TestIgnoredMethods.java ---
/**
* Copyright (C) 2006 Carrier Access, Corp.
*/
package biz.xsoftware.test.mock2;
import biz.xsoftware.mock2.CalledMethod;
import biz.xsoftware.mock2.MockObject;
import biz.xsoftware.mock2.MockObjectFactory;
import junit.framework.TestCase;
/**
*/
public class TestIgnoredMethods extends TestCase
{
private MockObject mock;
private FakeSystem fake;
private byte zeroByte = 30;
/**
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception
{
mock = MockObjectFactory.createMock(ListenerOne.class);
fake = new FakeSystem((ListenerOne)mock, zeroByte);
}
/**
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception
{
super.tearDown();
}
public void testIgnoredMethods()
{
//we are expecting this array to be modified so clone it here...
byte[] expected = new byte[] { 4, 5, 6, 7 };
int expectedAnswer = 20;
String methodName = "write";
MyBehavior mb = new MyBehavior(expectedAnswer, zeroByte);
byte[] clone = mb.cloneWrite(expected);
CalledMethod method = mock.expect(methodName, mb, byte[].class); // ??behavior ??valledMethod
// mock.addIgnoredMethod("callMeLast");
// mock.expect("callMeFirst");
mock.expect("callMeLast");
mock.addIgnoredMethod("callMeFirst");
int answer = fake.runSystem(clone);
mock.verify();
byte[] actual = (byte[])method.getParameters()[0];
assertEquals(zeroByte, actual[0]);
assertEquals(expected[1], actual[1]);
assertEquals(expected[2], actual[2]);
assertEquals(expected[3], actual[3]);
assertEquals(100, answer);
}
public void testIgnoredLastMethod()
{
//we are expecting this array to be modified so clone it here...
byte[] expected = new byte[] { 4, 5, 6, 7 };
int expectedAnswer = 20;
String methodName = "write";
MyBehavior mb = new MyBehavior(expectedAnswer, zeroByte);
byte[] clone = mb.cloneWrite(expected);
CalledMethod method = mock.expect(methodName, mb, byte[].class); // ??behavior ??valledMethod
mock.addIgnoredMethod("callMeLast");
mock.expect("callMeFirst");
int answer = fake.runSystem(clone);
mock.verify();
byte[] actual = (byte[])method.getParameters()[0];
assertEquals(zeroByte, actual[0]);
assertEquals(expected[1], actual[1]);
assertEquals(expected[2], actual[2]);
assertEquals(expected[3], actual[3]);
assertEquals(100, answer);
}
}
Index: TestMockCreator.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** TestMockCreator.java 6 Apr 2006 15:25:06 -0000 1.18
--- TestMockCreator.java 2 May 2006 23:26:34 -0000 1.19
***************
*** 289,295 ****
String methodName = "write";
! MyBehavior mb=new MyBehavior(expectedAnswer, zeroByte);
! byte[] clone =(byte[])mb.cloneWrite(expected);
CalledMethod method = m.expect(methodName,mb,byte[].class); // ??behavior ??valledMethod
FakeSystem systemUnderTest = new FakeSystem(l, zeroByte); // ??call ????
--- 289,297 ----
String methodName = "write";
! MyBehavior mb = new MyBehavior(expectedAnswer, zeroByte);
! byte[] clone = mb.cloneWrite(expected);
CalledMethod method = m.expect(methodName,mb,byte[].class); // ??behavior ??valledMethod
+ m.addIgnoredMethod("callMeFirst");
+ m.addIgnoredMethod("callMeLast");
FakeSystem systemUnderTest = new FakeSystem(l, zeroByte); // ??call ????
***************
*** 322,331 ****
CalledMethod callMeLast=m.expect(methodName2);
CalledMethod callAgain=m.expect(methodName1);
! m.removeIgnoreMethod(methodName1);
CalledMethod callLastAgain=m.expect(methodName2);
CalledMethod callThirdTime=m.expect(methodName1);
l.callMeFirst(param1);
! m.addIgnoreMethod(methodName1);
m.setDefaultReturnValue("retval",methodName1);
l.callMeLast(param2);
--- 324,333 ----
CalledMethod callMeLast=m.expect(methodName2);
CalledMethod callAgain=m.expect(methodName1);
! m.removeIgnoredMethod(methodName1);
CalledMethod callLastAgain=m.expect(methodName2);
CalledMethod callThirdTime=m.expect(methodName1);
l.callMeFirst(param1);
! m.addIgnoredMethod(methodName1);
m.setDefaultReturnValue("retval",methodName1);
l.callMeLast(param2);
Index: FakeSystem.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/FakeSystem.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** FakeSystem.java 28 Mar 2006 02:52:49 -0000 1.7
--- FakeSystem.java 2 May 2006 23:26:34 -0000 1.8
***************
*** 16,22 ****
public int runSystem(byte[] data) {
int retVal = list.write(data);
!
//now modify data....if mocklib did not clone, the
//test will fail
--- 16,26 ----
public int runSystem(byte[] data) {
+
int retVal = list.write(data);
! list.callMeFirst(retVal);
! // list.callMeSecond("foo");
! list.callMeLast("bar");
!
//now modify data....if mocklib did not clone, the
//test will fail
|