Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18987/input/javasrc/biz/xsoftware/test/mock2
Modified Files:
FakeSystem.java TestMockCreator.java
Log Message:
add more to the test to aide in understanding.
Index: FakeSystem.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/FakeSystem.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FakeSystem.java 19 Mar 2006 14:27:59 -0000 1.1
--- FakeSystem.java 19 Mar 2006 14:49:28 -0000 1.2
***************
*** 4,10 ****
private ListenerOne list;
! public FakeSystem(ListenerOne list) {
this.list = list;
}
public int runSystem(byte[] data) {
int retVal = list.write(data);
--- 4,14 ----
private ListenerOne list;
! private byte zeroByte;
!
! public FakeSystem(ListenerOne list, byte zeroByte) {
this.list = list;
+ this.zeroByte = zeroByte;
}
+
public int runSystem(byte[] data) {
int retVal = list.write(data);
***************
*** 15,18 ****
--- 19,31 ----
data[i] = -1;
}
+
+ //there are two paths in the system.....if listenerOne
+ //changed the byte[] array to have zeroByte as the
+ //first byte, then we take this path, other wise we
+ //return what listenerOne returned....user who
+ //wrote FakeSystem will want to test both scenarios.
+ if(data[0] == zeroByte) {
+ return 100;
+ }
return retVal;
}
Index: TestMockCreator.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** TestMockCreator.java 19 Mar 2006 14:37:55 -0000 1.8
--- TestMockCreator.java 19 Mar 2006 14:49:28 -0000 1.9
***************
*** 212,224 ****
int expectedAnswer = 20;
//we are expecting this array to be modified so clone it here...
byte[] expected = new byte[] { 4, 5, 6, 7 };
byte[] clone = cloneBytes(expected);
String methodName = "callWithRetVal";
! CalledMethod method = m.expect(methodName, new MyBehavior(expectedAnswer));
!
!
! FakeSystem systemUnderTest = new FakeSystem(l);
int answer = systemUnderTest.runSystem(clone);
--- 212,223 ----
int expectedAnswer = 20;
+ byte zeroByte = 30;
//we are expecting this array to be modified so clone it here...
byte[] expected = new byte[] { 4, 5, 6, 7 };
byte[] clone = cloneBytes(expected);
String methodName = "callWithRetVal";
! CalledMethod method = m.expect(methodName, new MyBehavior(expectedAnswer, zeroByte));
! FakeSystem systemUnderTest = new FakeSystem(l, zeroByte);
int answer = systemUnderTest.runSystem(clone);
***************
*** 230,234 ****
assertEquals(expected[2], actual[2]);
assertEquals(expected[3], actual[3]);
! assertEquals(expectedAnswer, answer);
}
--- 229,233 ----
assertEquals(expected[2], actual[2]);
assertEquals(expected[3], actual[3]);
! assertEquals(100, answer);
}
***************
*** 244,249 ****
private int answer;
! public MyBehavior(int expectedAnswer) {
this.answer = expectedAnswer;
}
--- 243,251 ----
private int answer;
! private byte zeroByte;
!
! public MyBehavior(int expectedAnswer, byte zeroByte) {
this.answer = expectedAnswer;
+ this.zeroByte = zeroByte;
}
***************
*** 254,260 ****
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;
}
--- 256,261 ----
public int write(byte[] data) {
! data[0] = zeroByte;
!
return answer;
}
|