Update of /cvsroot/mocklib/mocklib/input/javasrc/biz/xsoftware/test
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv16469/input/javasrc/biz/xsoftware/test
Modified Files:
TestMockCreator.java MockOne.java Car.java
TestOrderedCalls.java
Added Files:
OldBehavior.java CarImpl.java Identical.java
Log Message:
clean up mocklib 1. It is not 1.4 compatible and is pretty much the final mocklib1
Index: TestMockCreator.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib/input/javasrc/biz/xsoftware/test/TestMockCreator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TestMockCreator.java 8 May 2005 05:19:05 -0000 1.2
--- TestMockCreator.java 10 Sep 2006 18:01:12 -0000 1.3
***************
*** 8,11 ****
--- 8,12 ----
import java.io.IOException;
+
import junit.framework.TestCase;
import junit.framework.TestSuite;
***************
*** 13,24 ****
import biz.xsoftware.mock.CalledMethod;
import biz.xsoftware.mock.ExpectFailedException;
- import biz.xsoftware.mock.MockObjectFactory;
import biz.xsoftware.mock.MockObject;
/**
* @author Dean Hiller
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
*/
public class TestMockCreator extends TestCase {
--- 14,22 ----
import biz.xsoftware.mock.CalledMethod;
import biz.xsoftware.mock.ExpectFailedException;
import biz.xsoftware.mock.MockObject;
+ import biz.xsoftware.mock.MockObjectFactory;
/**
* @author Dean Hiller
*/
public class TestMockCreator extends TestCase {
***************
*** 40,44 ****
String methodName = "callMeSecond";
! CalledMethod method = m.expectCall(methodName);
assertEquals("method name should be the same", methodName, method.getMethodName());
--- 38,42 ----
String methodName = "callMeSecond";
! CalledMethod method = m.expect(methodName);
assertEquals("method name should be the same", methodName, method.getMethodName());
***************
*** 64,68 ****
try {
! m.expectCall(MockObject.NONE);
fail("Should have failed with ExpectFailedException");
} catch(ExpectFailedException e) {
--- 62,66 ----
try {
! m.expect(MockObject.NONE);
fail("Should have failed with ExpectFailedException");
} catch(ExpectFailedException e) {
***************
*** 78,82 ****
l.multipleParams(param1, param2);
! CalledMethod method = m.expectCall("multipleParams");
assertEquals("param1 is not correct", param1, method.getParameter(0));
assertEquals("param2 is not correct", param2, method.getParameter(1));
--- 76,80 ----
l.multipleParams(param1, param2);
! CalledMethod method = m.expect("multipleParams");
assertEquals("param1 is not correct", param1, method.getParameter(0));
assertEquals("param2 is not correct", param2, method.getParameter(1));
***************
*** 88,92 ****
l.callMeSecond("dummy");
try {
! m.expectCall("callMeFirst");
fail("should have thrown exception");
} catch(ExpectFailedException e) {}
--- 86,90 ----
l.callMeSecond("dummy");
try {
! m.expect("callMeFirst");
fail("should have thrown exception");
} catch(ExpectFailedException e) {}
***************
*** 97,109 ****
MockObject car = MockObjectFactory.createMock(Car.class);
! factory.addReturnValue("createCar", (Car)car);
//now we would normally tweak code on the subsystem which
//would call createcar but we are only unit testing MockCreator
Car c = ((FactoryInterface)factory).createCar("someid");
! factory.expectCall("createCar");
c.openDoor();
! car.expectCall("openDoor");
}
--- 95,107 ----
MockObject car = MockObjectFactory.createMock(Car.class);
! factory.addReturnValue("createCar", car);
//now we would normally tweak code on the subsystem which
//would call createcar but we are only unit testing MockCreator
Car c = ((FactoryInterface)factory).createCar("someid");
! factory.expect("createCar");
c.openDoor();
! car.expect("openDoor");
}
***************
*** 126,130 ****
l.callMeFirst(expected);
! CalledMethod m = mockList.expectCall(MockObject.ANY);
Integer i = (Integer)m.getAllParams()[0];
assertEquals("param should be 1", new Integer(expected), i);
--- 124,128 ----
l.callMeFirst(expected);
! CalledMethod m = mockList.expect(MockObject.ANY);
Integer i = (Integer)m.getAllParams()[0];
assertEquals("param should be 1", new Integer(expected), i);
***************
*** 139,143 ****
String[] methods = new String[] { MockObject.ANY, "callMeSecond" };
! mockList.expectOrderedCalls(methods);
}
--- 137,141 ----
String[] methods = new String[] { MockObject.ANY, "callMeSecond" };
! mockList.expect(methods);
}
***************
*** 146,150 ****
try {
! mock.expectCall("noSuchMethod");
fail("This should throw an exception");
} catch(IllegalArgumentException e) {
--- 144,148 ----
try {
! mock.expect("noSuchMethod");
fail("This should throw an exception");
} catch(IllegalArgumentException e) {
***************
*** 152,156 ****
}
! public static void main(String[] args) {
TestSuite suite = new TestSuite();
suite.addTest(new TestMockCreator("testWrongMethod"));
--- 150,298 ----
}
! public void testDefaultRetVal() {
! MockObject mock = MockObjectFactory.createMock(Identical.class);
!
! mock.setDefaultReturnValue("doThat", new byte[] {4});
!
! Identical ident = (Identical)mock;
! byte[] retVal = ident.doThat(null);
!
! mock.expect("doThat");
!
! assertEquals(1, retVal.length);
! assertEquals(4, retVal[0]);
! }
!
! public void testDefaultReturnWithOtherReturns()
! {
! MockObject mock = MockObjectFactory.createMock(Identical.class);
! mock.addReturnValue("doThat", new byte[] {3});
! mock.setDefaultReturnValue("doThat", new byte[] {4});
! mock.addReturnValue("doThat", new byte[] {5});
!
! Identical ident = (Identical)mock;
! byte[] retVal = ident.doThat(null);
! mock.expect("doThat");
!
! assertEquals(1, retVal.length);
! assertEquals(3, retVal[0]);
!
! retVal = ident.doThat(null);
! mock.expect("doThat");
!
! assertEquals(1, retVal.length);
! assertEquals(5, retVal[0]);
!
! retVal = ident.doThat(null);
! mock.expect("doThat");
!
! assertEquals(1, retVal.length);
! assertEquals(4, retVal[0]);
! }
!
!
! public void testReturnInterface() {
! MockObject mock = MockObjectFactory.createMock(FactoryInterface.class);
!
! FactoryInterface factory = (FactoryInterface)mock;
!
! mock.addReturnValue("createCar", new CarImpl());
! Car car = factory.createCar("id");
!
! assertEquals(car.getClass(), CarImpl.class);
!
! mock.expect("createCar");
! }
!
!
! public void testReturnNull() {
! MockObject mock = MockObjectFactory.createMock(FactoryInterface.class);
!
! FactoryInterface factory = (FactoryInterface)mock;
!
! factory.createCar("aaa");
!
! mock.expect("createCar");
! }
!
! public void testBadPrimitive() {
! MockObject mock = MockObjectFactory.createMock(Car.class);
!
! Car car = (Car)mock;
! try {
! mock.addReturnValue("getWheelCount", new Long(56));
! car.getWheelCount();
! fail("should have thrown exception");
! } catch(IllegalArgumentException e) {
! }
! }
!
! public void testNullPrimitive() {
! MockObject mock = MockObjectFactory.createMock(Car.class);
!
! Car car = (Car)mock;
! try {
! car.getWheelCount();
! fail("should have thrown exception");
! } catch(IllegalArgumentException e) {
! }
! }
!
! public void testPrimitive() {
! MockObject mock = MockObjectFactory.createMock(Car.class);
!
! Car car = (Car)mock;
! mock.addReturnValue("getWheelCount", new Integer(5));
! car.getWheelCount();
!
! mock.expect("getWheelCount");
! }
!
! public void testBehavior() {
! MockObject mock = MockObjectFactory.createMock(Identical.class);
!
! mock.addBehavior("doThat", new OldBehavior());
!
! 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()
! {
! MockObject mock = MockObjectFactory.createMock(Car.class);
! mock.addIgnore(new String[]{"openDoor", "closeDoor"});
!
! Car car = (Car)mock;
! car.openDoor();
! car.closeDoor();
!
! mock.expect(MockObject.NONE);
!
! mock.removeIgnore("closeDoor");
! car.closeDoor();
!
! mock.expect("closeDoor");
! }
!
! public static void main(String[] args) {
TestSuite suite = new TestSuite();
suite.addTest(new TestMockCreator("testWrongMethod"));
--- NEW FILE: CarImpl.java ---
/**
* Copyright (C) 2006 Carrier Access, Corp.
*/
package biz.xsoftware.test;
/**
*/
public class CarImpl implements Car
{
/**
* @see biz.xsoftware.test.mock.Car#openDoor()
*/
public void openDoor()
{
}
/**
* @see biz.xsoftware.test.mock.Car#closeDoor()
*/
public void closeDoor()
{
}
/**
* @see biz.xsoftware.test.mock.Car#getWheelCount()
*/
public int getWheelCount()
{
return 0;
}
}
--- NEW FILE: Identical.java ---
/**
* Copyright (C) 2006 Carrier Access, Corp.
*/
package biz.xsoftware.test;
/**
*/
public interface Identical
{
public byte[] doThat(byte[] data);
}
--- NEW FILE: OldBehavior.java ---
/**
*
*/
package biz.xsoftware.test;
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: MockOne.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib/input/javasrc/biz/xsoftware/test/MockOne.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MockOne.java 7 May 2005 18:26:17 -0000 1.1
--- MockOne.java 10 Sep 2006 18:01:12 -0000 1.2
***************
*** 52,57 ****
* @see biz.xsoftware.mock.MockSuperclass#getClasses()
*/
! public Class[] getClasses() {
return new Class[] { MockOne.class };
}
}
--- 52,61 ----
* @see biz.xsoftware.mock.MockSuperclass#getClasses()
*/
! public Class[] getClasses() {
return new Class[] { MockOne.class };
}
+ public Object inst() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
Index: Car.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib/input/javasrc/biz/xsoftware/test/Car.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Car.java 7 May 2005 18:26:17 -0000 1.1
--- Car.java 10 Sep 2006 18:01:12 -0000 1.2
***************
*** 18,20 ****
--- 18,21 ----
public void closeDoor();
+ public int getWheelCount();
}
Index: TestOrderedCalls.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib/input/javasrc/biz/xsoftware/test/TestOrderedCalls.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TestOrderedCalls.java 8 May 2005 05:19:05 -0000 1.2
--- TestOrderedCalls.java 10 Sep 2006 18:01:12 -0000 1.3
***************
*** 38,42 ****
final MockOne one = new MockOne(3000);
Thread r = new Thread() {
! public void run() {
delay(1000);
one.callMeFirst(4);
--- 38,42 ----
final MockOne one = new MockOne(3000);
Thread r = new Thread() {
! public void run() {
delay(1000);
one.callMeFirst(4);
***************
*** 59,63 ****
final MockOne one = new MockOne(3000);
Thread r = new Thread() {
! public void run() {
delay(1000);
one.callMeFirst(4);
--- 59,63 ----
final MockOne one = new MockOne(3000);
Thread r = new Thread() {
! public void run() {
delay(1000);
one.callMeFirst(4);
***************
*** 86,90 ****
final MockOne one = new MockOne(3000);
Thread r = new Thread() {
! public void run() {
delay(1000);
one.callMeFirst(14);
--- 86,90 ----
final MockOne one = new MockOne(3000);
Thread r = new Thread() {
! public void run() {
delay(1000);
one.callMeFirst(14);
***************
*** 94,97 ****
--- 94,98 ----
String[] evts = new String[] { MockOne.SECOND, MockOne.FIRST };
try {
+ r.run();
one.expectOrderedCalls(evts);
fail("Should have failed this test case");
|