Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv30736/input/javasrc/biz/xsoftware/test/mock
Modified Files:
TestMockCreator.java
Added Files:
OldBehavior.java NewBehavior.java
Log Message:
starting addition of newbehavior.
--- NEW FILE: OldBehavior.java ---
/**
*
*/
package biz.xsoftware.test.mock;
import biz.xsoftware.mock.Behavior;
class OldBehavior implements Behavior {
/**
* @see biz.xsoftware.mock.Behavior#clone(java.lang.Object[])
*/
public Object[] clone(Object[] params)
{
Object[] retVal = new Object[params.length];
for(int i = 0; i < retVal.length; i++) {
Object val = params[i];
if(val instanceof byte[]) {
retVal[i] = cloneBytes((byte[])val);
}
}
return retVal;
}
private Object cloneBytes(byte[] bytes)
{
byte[] newBytes = new byte[bytes.length];
for(int i = 0; i < newBytes.length; i++) {
newBytes[i] = bytes[i];
}
return newBytes;
}
/**
* @see biz.xsoftware.mock.Behavior#runMethod(java.lang.Object[])
*/
public Object runMethod(Object[] params)
{
//we know the test does an 4 byte array, so do that
byte[] bytes = (byte[])params[0];
for(int i = 0; i < 4; i++) {
bytes[i+4] = bytes[i];
}
//make sure to return the same byte buffer so we are really testing this...
return bytes;
}
}
Index: TestMockCreator.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** TestMockCreator.java 1 Sep 2006 17:07:23 -0000 1.9
--- TestMockCreator.java 10 Sep 2006 17:18:39 -0000 1.10
***************
*** 12,16 ****
import junit.framework.TestSuite;
import junit.textui.TestRunner;
- import biz.xsoftware.mock.Behavior;
import biz.xsoftware.mock.CalledMethod;
import biz.xsoftware.mock.ExpectFailedException;
--- 12,15 ----
***************
*** 253,257 ****
MockObject mock = MockObjectFactory.createMock(Identical.class);
! mock.addBehavior("doThat", new MyBehavior());
Identical ident = (Identical)mock;
--- 252,256 ----
MockObject mock = MockObjectFactory.createMock(Identical.class);
! mock.addBehavior("doThat", new OldBehavior());
Identical ident = (Identical)mock;
***************
*** 278,281 ****
--- 277,309 ----
}
+ public void testNewBehavior() {
+ // MockObject mock = MockObjectFactory.createMock(Identical.class);
+ //
+ // mock.addBehavior("doThat", new NewBehavior());
+ //
+ // Identical ident = (Identical)mock;
+ //
+ // byte[] original = new byte[] { 1, 2, 3, 4, 0, 0, 0, 0};
+ // byte[] bytes = new byte[] { 1, 2, 3, 4, 0 ,0,0,0};
+ //
+ // byte[] newBytes = ident.doThat(bytes);
+ //
+ // CalledMethod m = mock.expect("doThat");
+ // byte[] passedIn = (byte[])m.getAllParams()[0];
+ //
+ // assertEquals(original.length, passedIn.length);
+ // for(int i = 0; i < original.length; i++) {
+ // assertEquals(original[i], passedIn[i]);
+ // }
+ //
+ // //make sure this is the same byte array we passed in
+ // assertSame(bytes, newBytes);
+ //
+ // for(int i = 0; i < 4; i++) {
+ // assertEquals(newBytes[i], newBytes[i+4]);
+ // }
+ }
+
+
public void testAddRemoveIgnore()
{
***************
*** 295,342 ****
}
! private static class MyBehavior implements Behavior {
!
! /**
! * @see biz.xsoftware.mock.Behavior#clone(java.lang.Object[])
! */
! public Object[] clone(Object[] params)
! {
! Object[] retVal = new Object[params.length];
! for(int i = 0; i < retVal.length; i++) {
! Object val = params[i];
! if(val instanceof byte[]) {
! retVal[i] = cloneBytes((byte[])val);
! }
! }
! return retVal;
! }
!
! private Object cloneBytes(byte[] bytes)
! {
! byte[] newBytes = new byte[bytes.length];
! for(int i = 0; i < newBytes.length; i++) {
! newBytes[i] = bytes[i];
! }
! return newBytes;
! }
!
! /**
! * @see biz.xsoftware.mock.Behavior#runMethod(java.lang.Object[])
! */
! public Object runMethod(Object[] params)
! {
! //we know the test does an 4 byte array, so do that
! byte[] bytes = (byte[])params[0];
! for(int i = 0; i < 4; i++) {
! bytes[i+4] = bytes[i];
! }
!
! //make sure to return the same byte buffer so we are really testing this...
! return bytes;
! }
!
! }
!
! public static void main(String[] args) {
TestSuite suite = new TestSuite();
suite.addTest(new TestMockCreator("testWrongMethod"));
--- 323,327 ----
}
! public static void main(String[] args) {
TestSuite suite = new TestSuite();
suite.addTest(new TestMockCreator("testWrongMethod"));
--- NEW FILE: NewBehavior.java ---
/**
*
*/
package biz.xsoftware.test.mock;
import biz.xsoftware.mock.MethodBehavior;
class NewBehavior implements MethodBehavior {
/**
* @see biz.xsoftware.mock.Behavior#clone(java.lang.Object[])
*/
public Object[] doThatClone(Object[] params)
{
Object[] retVal = new Object[params.length];
for(int i = 0; i < retVal.length; i++) {
Object val = params[i];
if(val instanceof byte[]) {
retVal[i] = cloneBytes((byte[])val);
}
}
return retVal;
}
private Object cloneBytes(byte[] bytes)
{
byte[] newBytes = new byte[bytes.length];
for(int i = 0; i < newBytes.length; i++) {
newBytes[i] = bytes[i];
}
return newBytes;
}
/**
* @see biz.xsoftware.mock.Behavior#runMethod(java.lang.Object[])
*/
public byte[] doThat(byte[] bytes)
{
for(int i = 0; i < 4; i++) {
bytes[i+4] = bytes[i];
}
//make sure to return the same byte buffer so we are really testing this...
return bytes;
}
}
|