Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9474/input/javasrc/biz/xsoftware/test/mock2
Modified Files:
ListenerOne.java TestMockCreator.java
Added Files:
FakeSystem.java
Log Message:
add an example test for Jay.
--- NEW FILE: FakeSystem.java ---
package biz.xsoftware.test.mock2;
public class FakeSystem {
private ListenerOne list;
public FakeSystem(ListenerOne list) {
this.list = list;
}
public int runSystem(byte[] data) {
int retVal = list.write(data);
//now modify data....if mocklib did not clone, the
//test will fail
for(int i = 0; i < data.length; i++) {
data[i] = -1;
}
return retVal;
}
}
Index: ListenerOne.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/ListenerOne.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ListenerOne.java 17 Feb 2006 15:07:40 -0000 1.3
--- ListenerOne.java 19 Mar 2006 14:27:59 -0000 1.4
***************
*** 26,29 ****
--- 26,31 ----
public int getField();
+
+ public int write(byte[] data);
}
Index: TestMockCreator.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** TestMockCreator.java 2 Mar 2006 10:52:34 -0000 1.6
--- TestMockCreator.java 19 Mar 2006 14:27:59 -0000 1.7
***************
*** 6,9 ****
--- 6,10 ----
import junit.framework.TestCase;
+ import biz.xsoftware.mock2.Behavior;
import biz.xsoftware.mock2.CalledMethod;
import biz.xsoftware.mock2.Messages;
***************
*** 206,211 ****
}
! public void testExpectWithBehavior() throws Exception {
! //MockObject m = MockObjectFactory.createMock(ListenerOne.class);
}
}
--- 207,256 ----
}
! public void xxxtestExpectWithBehavior() throws Exception {
! MockObject m = MockObjectFactory.createMock(ListenerOne.class);
! ListenerOne l = (ListenerOne) m;
!
! int expectedAnswer = 20;
! byte[] expected = new byte[] { 4, 5, 6, 7 };
! String methodName = "callWithRetVal";
! CalledMethod method = m.expect(methodName, new MyBehavior(expectedAnswer));
!
!
!
! FakeSystem systemUnderTest = new FakeSystem(l);
! int answer = systemUnderTest.runSystem(expected);
!
! m.verify();
!
! byte[] actual = (byte[])method.getParameters()[0];
! assertEquals(expected[0], actual[0]);
! assertEquals(expected[1], actual[1]);
! assertEquals(expected[2], actual[2]);
! assertEquals(expected[3], actual[3]);
! assertEquals(expectedAnswer, answer);
! }
!
! private static class MyBehavior implements Behavior {
!
! private int answer;
! public MyBehavior(int expectedAnswer) {
! this.answer = expectedAnswer;
! }
!
! public Object[] cloneWrite(byte[] data) {
! byte[] clone = new byte[data.length];
! for(int i = 0; i < data.length; i++) {
! clone[i] = data[i];
! }
! return new Object[] { clone };
! }
!
! public int write(byte[] data) {
! //for now, don't need to add much behavior here, but we could
! //change the byte aray given to the client if that was the
! //contract
! return answer;
! }
!
}
}
|