mocklib-checkins Mailing List for mocklib (Page 18)
Brought to you by:
bittwidler,
fastdragon
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(6) |
Jul
(1) |
Aug
(5) |
Sep
(3) |
Oct
|
Nov
|
Dec
(46) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(54) |
Feb
(120) |
Mar
(31) |
Apr
(11) |
May
(8) |
Jun
(5) |
Jul
|
Aug
(22) |
Sep
(295) |
Oct
(6) |
Nov
(10) |
Dec
|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
|
Jul
(2) |
Aug
(2) |
Sep
|
Oct
|
Nov
(2) |
Dec
(8) |
2008 |
Jan
|
Feb
(1) |
Mar
|
Apr
(8) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
2009 |
Jan
|
Feb
(17) |
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Jay <ja...@us...> - 2006-03-27 15:44:40
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22874/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectSuperImpl.java Log Message: Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** MockObjectSuperImpl.java 25 Mar 2006 08:17:22 -0000 1.10 --- MockObjectSuperImpl.java 27 Mar 2006 15:44:31 -0000 1.11 *************** *** 84,87 **** --- 84,88 ---- throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod = new CalledMethodImpl(methodName); + if(!methodsIgnored.containsKey(methodName)) methodsExpected.add(calledMethod); return calledMethod; *************** *** 93,98 **** throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod = new CalledMethodImpl(methodName); ! methodsExpected.add(calledMethod); ! retVal.put(methodName, returnValue); return calledMethod; } --- 94,101 ---- throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod = new CalledMethodImpl(methodName); ! if(!methodsIgnored.containsKey(methodName)){ ! methodsExpected.add(calledMethod); ! retVal.put(methodName, returnValue); ! } return calledMethod; } *************** *** 103,108 **** throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod = new CalledMethodImpl(methodName); ! methodsExpected.add(calledMethod); ! methodWithException.put(methodName, throwable); return calledMethod; } --- 106,113 ---- throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod = new CalledMethodImpl(methodName); ! if(!methodsIgnored.containsKey(methodName)){ ! methodsExpected.add(calledMethod); ! methodWithException.put(methodName, throwable); ! } return calledMethod; } *************** *** 113,129 **** throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod=new CalledMethodImpl(methodName); ! methodsExpected.add(calledMethod); ! behaviorMap.put(methodName,behavior); ! try { ! Class c=behavior.getClass(); ! Method method = c.getMethod(methodName,params); ! methodList.add(method); ! } catch (SecurityException e) { ! throw new IllegalArgumentException(Messages.METHOD_CAN_NOT_ACCESS); ! } catch (NoSuchMethodException e) { ! throw new IllegalArgumentException(methodName+"is not defined in your Behvior Implemetation"); ! } return calledMethod; --- 118,136 ---- throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod=new CalledMethodImpl(methodName); ! if(!methodsIgnored.containsKey(methodName)){ ! methodsExpected.add(calledMethod); ! behaviorMap.put(methodName,behavior); ! try { ! Class c=behavior.getClass(); ! Method method = c.getMethod(methodName,params); ! methodList.add(method); ! } catch (SecurityException e) { ! throw new IllegalArgumentException(Messages.METHOD_CAN_NOT_ACCESS); ! } catch (NoSuchMethodException e) { ! throw new IllegalArgumentException(methodName+"is not defined in your Behvior Implemetation"); ! } ! } return calledMethod; *************** *** 147,152 **** while (methodsCalled.size() != 0) { ! CalledMethod calledMethod = methodsCalled.remove(0); ! CalledMethodImpl m = (CalledMethodImpl) methodsExpected.remove(0); m.setParameters(calledMethod.getParameters()); m.setStackTrace(calledMethod.getStackTrace()); --- 154,163 ---- while (methodsCalled.size() != 0) { ! CalledMethodImpl m = (CalledMethodImpl) methodsExpected.remove(0); ! CalledMethod calledMethod = methodsCalled.remove(0); ! while(m.getMethodName()!=calledMethod.getMethodName()){ ! calledMethod=methodsCalled.remove(0); ! } ! m.setParameters(calledMethod.getParameters()); m.setStackTrace(calledMethod.getStackTrace()); *************** *** 220,224 **** public void setDefaultReturnValue(Object returnValue, String methodName, Class... vargs) { ! --- 231,237 ---- public void setDefaultReturnValue(Object returnValue, String methodName, Class... vargs) { ! if(methodName==null) ! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); ! retVal.put(methodName,returnValue); *************** *** 226,233 **** public Object instance() { ! CalledMethod calledMethod=new CalledMethodImpl(); ! ! return calledMethod; ! } --- 239,243 ---- public Object instance() { ! return this; } |
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/example1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13396/input/javasrc/biz/xsoftware/mock2/example1 Added Files: GiftCardAccountSvc.java TestExample.java SysUnderTest.java CreditAuthorizationSvc.java PurchaseException.java Log Message: the first example --- NEW FILE: PurchaseException.java --- /* * Created on Jul 3, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package biz.xsoftware.mock2.example1; /** * An Exception the SysUnderTest(WebStore) generates when a purchase goes * bad. * @author Dean Hiller */ public class PurchaseException extends RuntimeException { /** * */ private static final long serialVersionUID = 1L; /** * @param e */ public PurchaseException(Throwable e) { super(e); } } --- NEW FILE: GiftCardAccountSvc.java --- /* * Created on Jul 3, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package biz.xsoftware.mock2.example1; /** * Interface to what would normally be a real GiftCarAccountSvc. * @author Dean Hiller */ public interface GiftCardAccountSvc { public void putMoneyOnCard(int cardId, double money); public void takeMoneyFromCard(int cardId, double money); } --- NEW FILE: TestExample.java --- package biz.xsoftware.mock2.example1; import junit.framework.TestCase; import biz.xsoftware.mock2.CalledMethod; import biz.xsoftware.mock2.MockObject; import biz.xsoftware.mock2.MockObjectFactory; public class TestExample extends TestCase{ private SysUnderTest sysUnderTest; private MockObject mockCreditSvc; private MockObject mockGiftSvc; public TestExample(String name) { super(name); } public void setUp() { mockCreditSvc = MockObjectFactory.createMock(CreditAuthorizationSvc.class); mockGiftSvc = MockObjectFactory.createMock(GiftCardAccountSvc.class); CreditAuthorizationSvc credit = (CreditAuthorizationSvc)mockCreditSvc; GiftCardAccountSvc gift = (GiftCardAccountSvc)mockGiftSvc; sysUnderTest = new SysUnderTest(credit, gift); } public void testBasicSysUnderTest() { String user = "user1"; double amount = 340.99; CalledMethod authorize=mockCreditSvc.expect("authorize"); sysUnderTest.purchase("itemA", user, amount); mockCreditSvc.verify(); assertEquals("user should be the same",user,authorize.getParameters()[0]); assertEquals("Amount should have been the same", new Double(amount), authorize.getParameters()[1]); } } --- NEW FILE: CreditAuthorizationSvc.java --- /* * Created on Jun 28, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package biz.xsoftware.mock2.example1; /** * Interface to what would normally be a real Credit Authorization Service. * * @author Dean Hiller */ public interface CreditAuthorizationSvc { /** * @param user * @param usDollars */ public void authorize(String user, double usDollars); public void takeMoney(String user, double usDollars); public void returnMoney(String user, double usDollars); } --- NEW FILE: SysUnderTest.java --- /* * Created on Jun 28, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package biz.xsoftware.mock2.example1; /** * The SysUnderTest here is a WebStore or something which needs * to authorize purchases. */ public class SysUnderTest { private CreditAuthorizationSvc creditSvc; private GiftCardAccountSvc giftSvc; /** * @showcode */ public SysUnderTest(CreditAuthorizationSvc c, GiftCardAccountSvc g) { creditSvc = c; giftSvc = g; } /** * @showcode */ public void purchase(String item, String user, double usDollars) { try { creditSvc.authorize(user, usDollars); } catch(RuntimeException e) { throw new PurchaseException(e); } //if authorize succeeded, go delete an item from the //Inventory as we successfully sold it. } /** * @showcode */ public void buyGiftCard(String user, double usDollars) { creditSvc.takeMoney(user, usDollars); try { giftSvc.putMoneyOnCard(456, usDollars); } catch(Throwable e) { creditSvc.returnMoney(user, usDollars); throw new PurchaseException(e); } return; } } |
From: Jay <ja...@us...> - 2006-03-26 14:49:58
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/example1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13361/input/javasrc/biz/xsoftware/mock2/example1 Log Message: Directory /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/example1 added to the repository |
From: Jay <ja...@us...> - 2006-03-25 08:17:39
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv393/input/javasrc/biz/xsoftware/test/mock2 Modified Files: FakeSystem.java ListenerOne.java TestMockCreator.java Log Message: checkin for reintall eclipse Index: FakeSystem.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/FakeSystem.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FakeSystem.java 21 Mar 2006 09:25:33 -0000 1.4 --- FakeSystem.java 25 Mar 2006 08:17:25 -0000 1.5 *************** *** 31,33 **** --- 31,37 ---- return retVal; } + + public String getId(){ + return "ID"; + } } Index: ListenerOne.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/ListenerOne.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ListenerOne.java 20 Mar 2006 15:01:20 -0000 1.5 --- ListenerOne.java 25 Mar 2006 08:17:25 -0000 1.6 *************** *** 20,23 **** --- 20,27 ---- public void callMeSecond(String s) throws IOException; + + public void callMeLast(String s); + + public FakeSystem getFakeSystem(); public String callWithRetVal(String s); Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TestMockCreator.java 21 Mar 2006 15:01:27 -0000 1.12 --- TestMockCreator.java 25 Mar 2006 08:17:25 -0000 1.13 *************** *** 257,260 **** --- 257,304 ---- assertEquals(100, answer); } + + public void testIgnoreMethod(){ + MockObject m=MockObjectFactory.createMock(ListenerOne.class); + ListenerOne l=(ListenerOne)m; + + int param1=4; + String param2="someParam"; + + String methodName1="callMeFirst"; + String methodName2="callMeLast"; + + + m.addIgnoreMethod(methodName1); + CalledMethod callWithRetVal=m.expect(methodName1); + CalledMethod callMeLast=m.expect(methodName2); + m.removeIgnoreMethod(methodName1); + CalledMethod backCall=m.expect(methodName1); + + l.callMeFirst(param1); + l.callMeLast(param2); + l.callMeFirst(param1); + + m.verify(); + + } + + + public void testSetDefaultRetVal(){ + MockObject m1=MockObjectFactory.createMock(ListenerOne.class); + ListenerOne l=(ListenerOne)m1; + + FakeSystem fm=new FakeSystem(); + + + String methodName1="getFake"; + m1.setDefaultReturnValue(new FakeSystem(),methodName1); + CalledMethod getFake=m1.expect(methodName1); + + FakeSystem fs=l.getFakeSystem(); + fs.getId(); + + + + } // private static byte[] cloneBytes(byte[] data) { |
From: Jay <ja...@us...> - 2006-03-25 08:17:37
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv393/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectSuperImpl.java CalledMethodImpl.java Log Message: checkin for reintall eclipse Index: CalledMethodImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/CalledMethodImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CalledMethodImpl.java 16 Feb 2006 15:37:34 -0000 1.2 --- CalledMethodImpl.java 25 Mar 2006 08:17:24 -0000 1.3 *************** *** 24,34 **** } ! public String getMethodName() { ! // TODO Auto-generated method stub return methodName; } public Object[] getParameters() { ! // TODO Auto-generated method stub if(parameters==null) { --- 24,38 ---- } ! public CalledMethodImpl() { ! ! } ! ! public String getMethodName() { ! return methodName; } public Object[] getParameters() { ! if(parameters==null) { *************** *** 39,43 **** public String getStackTrace() { ! // TODO Auto-generated method stub return stackTrace; } --- 43,47 ---- public String getStackTrace() { ! return stackTrace; } Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** MockObjectSuperImpl.java 21 Mar 2006 09:25:32 -0000 1.9 --- MockObjectSuperImpl.java 25 Mar 2006 08:17:22 -0000 1.10 *************** *** 53,56 **** --- 53,61 ---- */ private Map<String,Behavior> behaviorMap=new HashMap<String,Behavior>(); + /** + * A Map of methods which are ignored by tester + */ + private Map<String,CalledMethod> methodsIgnored=new HashMap<String,CalledMethod>(); + public CalledMethod expect(String methodName, Class... vargs) { *************** *** 198,207 **** public void addIgnoreMethod(String methodName, Class... vargs) { ! // TODO Auto-generated method stub } public void removeIgnoreMethod(String methodName, Class... vargs) { ! // TODO Auto-generated method stub } --- 203,218 ---- public void addIgnoreMethod(String methodName, Class... vargs) { ! if(methodName==null) ! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); ! CalledMethod calledMethod=new CalledMethodImpl(methodName); ! methodsIgnored.put(methodName,calledMethod); ! } public void removeIgnoreMethod(String methodName, Class... vargs) { ! if(methodName==null) ! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); ! methodsIgnored.remove(methodName); } *************** *** 209,218 **** public void setDefaultReturnValue(Object returnValue, String methodName, Class... vargs) { ! } public Object instance() { ! // TODO Auto-generated method stub ! return null; } --- 220,233 ---- public void setDefaultReturnValue(Object returnValue, String methodName, Class... vargs) { ! ! ! } public Object instance() { ! CalledMethod calledMethod=new CalledMethodImpl(); ! ! return calledMethod; ! } |
From: Jay <ja...@us...> - 2006-03-21 15:01:47
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24192/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: clean code Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TestMockCreator.java 21 Mar 2006 09:25:33 -0000 1.11 --- TestMockCreator.java 21 Mar 2006 15:01:27 -0000 1.12 *************** *** 26,30 **** MockObject m = MockObjectFactory.createMock(ListenerOne.class); // ListenerOne l=(ListenerOne)m; ! String methodName = "callMeSecond"; --- 26,30 ---- MockObject m = MockObjectFactory.createMock(ListenerOne.class); // ListenerOne l=(ListenerOne)m; ! String methodName = "callMeSecond"; *************** *** 234,238 **** public void testExpectWithBehavior() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! ListenerOne l = (ListenerOne) m; int expectedAnswer = 20; byte zeroByte = 30; --- 234,238 ---- public void testExpectWithBehavior() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! ListenerOne l = (ListenerOne) m; int expectedAnswer = 20; byte zeroByte = 30; |
From: Jay <ja...@us...> - 2006-03-21 15:01:39
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24192/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectImpl.java Log Message: clean code Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectImpl.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MockObjectImpl.java 21 Mar 2006 09:25:32 -0000 1.4 --- MockObjectImpl.java 21 Mar 2006 15:01:25 -0000 1.5 *************** *** 20,23 **** --- 20,25 ---- private static Set<Method> isMethodInSuper=new HashSet<Method>(); private Class[] classes; + private Class c; + private Object realObject; static { *************** *** 38,42 **** public MockObjectImpl(Class interfaceToMock, Object realObject) { ! // what is the situation when needed to provide a realObject } --- 40,45 ---- public MockObjectImpl(Class interfaceToMock, Object realObject) { ! this.c=interfaceToMock; ! this.realObject=realObject; } *************** *** 68,75 **** } ! public Class[] getClasses(){ ! return this.classes; } ! --- 71,87 ---- } ! public Class getC(){ ! return this.c; } ! ! public Class[] getClasses(){ ! return this.classes; ! } ! ! public Object getRealObject(){ ! return this.realObject; ! } ! ! |
From: Jay <ja...@us...> - 2006-03-21 09:25:37
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13102/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java FakeSystem.java Log Message: changed and cleaned some code Index: FakeSystem.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/FakeSystem.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FakeSystem.java 20 Mar 2006 15:01:20 -0000 1.3 --- FakeSystem.java 21 Mar 2006 09:25:33 -0000 1.4 *************** *** 12,16 **** public int runSystem(byte[] data) { ! int retVal = list.write(data); //now modify data....if mocklib did not clone, the --- 12,17 ---- public int runSystem(byte[] data) { ! int retVal = list.write(data); ! //now modify data....if mocklib did not clone, the Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TestMockCreator.java 20 Mar 2006 15:01:20 -0000 1.10 --- TestMockCreator.java 21 Mar 2006 09:25:33 -0000 1.11 *************** *** 11,14 **** --- 11,17 ---- import biz.xsoftware.mock2.MockObjectFactory; + /** + * @author huajie.zeng + */ public class TestMockCreator extends TestCase { *************** *** 232,236 **** MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; - int expectedAnswer = 20; byte zeroByte = 30; --- 235,238 ---- *************** *** 245,253 **** FakeSystem systemUnderTest = new FakeSystem(l, zeroByte); // ??call ???? int answer = systemUnderTest.runSystem(clone); ! m.verify(); byte[] actual = (byte[])method.getParameters()[0]; ! assertEquals(30, actual[0]); assertEquals(expected[1], actual[1]); assertEquals(expected[2], actual[2]); --- 247,255 ---- FakeSystem systemUnderTest = new FakeSystem(l, zeroByte); // ??call ???? int answer = systemUnderTest.runSystem(clone); ! m.verify(); byte[] actual = (byte[])method.getParameters()[0]; ! assertEquals(zeroByte, actual[0]); assertEquals(expected[1], actual[1]); assertEquals(expected[2], actual[2]); |
From: Jay <ja...@us...> - 2006-03-21 09:25:36
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13102/input/javasrc/biz/xsoftware/mock2 Modified Files: Messages.java Log Message: changed and cleaned some code Index: Messages.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/Messages.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Messages.java 19 Feb 2006 19:20:54 -0000 1.3 --- Messages.java 21 Mar 2006 09:25:33 -0000 1.4 *************** *** 5,10 **** --- 5,13 ---- private Messages() {} + public static final String METHOD_NAME_CANT_BE_NULL="method name can not be null, please provide a method name"; public static final String VERIFY_NOT_CALLED = "MockObject.verify() must be called before accessing and of the methods on CalledMethod object"; + public static final String METHOD_CAN_NOT_ACCESS="Mocklib can not retrive the method you defined in your "+ + "Behavior Implementation class, Please make sure the method is accessable"; } |
From: Jay <ja...@us...> - 2006-03-21 09:25:36
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13102/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectImpl.java MockObjectFactoryImpl.java MockObjectSuperImpl.java Log Message: changed and cleaned some code Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MockObjectImpl.java 19 Feb 2006 19:20:52 -0000 1.3 --- MockObjectImpl.java 21 Mar 2006 09:25:32 -0000 1.4 *************** *** 38,60 **** public MockObjectImpl(Class interfaceToMock, Object realObject) { ! // TODO Auto-generated constructor stub } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { ! // TODO Auto-generated method stub if(isMethodInSuper.contains(method)){ return callSuperMethod(proxy,method,args); } - Object o=methodCalledImpl(method.getName(),args); - - if(o == null) { - Class c = method.getReturnType(); - if(!Object.class.isAssignableFrom(c) && !"void".equals(c.getName())) { - throw new RuntimeException("Must call addReturnValue " + - "and specify a non-null value as method="+method.getName()+" returns a primitive value"); - } - } return o; --- 38,51 ---- public MockObjectImpl(Class interfaceToMock, Object realObject) { ! // what is the situation when needed to provide a realObject } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { ! if(isMethodInSuper.contains(method)){ return callSuperMethod(proxy,method,args); } Object o=methodCalledImpl(method.getName(),args); return o; Index: MockObjectFactoryImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectFactoryImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MockObjectFactoryImpl.java 16 Feb 2006 15:37:34 -0000 1.3 --- MockObjectFactoryImpl.java 21 Mar 2006 09:25:32 -0000 1.4 *************** *** 23,27 **** public MockObject createMockImpl(Class interfaceToMock, Object realObject) { ! // TODO: Implement me! Class[] interfacePlusMock = new Class[1]; interfacePlusMock[0] = MockObject.class; --- 23,27 ---- public MockObject createMockImpl(Class interfaceToMock, Object realObject) { ! Class[] interfacePlusMock = new Class[1]; interfacePlusMock[0] = MockObject.class; Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** MockObjectSuperImpl.java 20 Mar 2006 15:01:20 -0000 1.8 --- MockObjectSuperImpl.java 21 Mar 2006 09:25:32 -0000 1.9 *************** *** 11,25 **** import biz.xsoftware.mock2.CalledMethod; import biz.xsoftware.mock2.MockObject; ! public abstract class MockObjectSuperImpl implements MockObject { ! // private static final Logger logger = Logger ! // .getLogger(MockObjectSuperImpl.class.getName()); private static final long DEFAULT_TIME_OUT = 10000; - // private static int Index=0; - /** * List of the current methods that have been called. --- 11,27 ---- import biz.xsoftware.mock2.CalledMethod; import biz.xsoftware.mock2.MockObject; + import biz.xsoftware.mock2.Messages; ! /** ! * ! * @author huajie.zeng ! * ! */ public abstract class MockObjectSuperImpl implements MockObject { ! private static final long DEFAULT_TIME_OUT = 10000; /** * List of the current methods that have been called. *************** *** 75,79 **** public CalledMethod expect(String methodName, long timeout, Class... vargs) { if (methodName == null) ! throw new IllegalArgumentException("methd name can not be null"); CalledMethod calledMethod = new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); --- 77,81 ---- public CalledMethod expect(String methodName, long timeout, Class... vargs) { if (methodName == null) ! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod = new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); *************** *** 84,88 **** long timeout, Class... vargs) { if (methodName == null) ! throw new IllegalArgumentException("method name can not be null"); CalledMethod calledMethod = new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); --- 86,90 ---- long timeout, Class... vargs) { if (methodName == null) ! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod = new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); *************** *** 94,98 **** long timeout, Class... vargs) { if (methodName == null) ! throw new IllegalArgumentException("method name can not be null"); CalledMethod calledMethod = new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); --- 96,100 ---- long timeout, Class... vargs) { if (methodName == null) ! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod = new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); *************** *** 104,108 **** long timeout, Class... params){ if(methodName==null) ! throw new IllegalArgumentException("method name can not be null"); CalledMethod calledMethod=new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); --- 106,110 ---- long timeout, Class... params){ if(methodName==null) ! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); CalledMethod calledMethod=new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); *************** *** 115,122 **** methodList.add(method); } catch (SecurityException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); } catch (NoSuchMethodException e) { ! throw new IllegalArgumentException("method:"+methodName+"is not defined in your Behvior Implemetation"); } --- 117,123 ---- methodList.add(method); } catch (SecurityException e) { ! throw new IllegalArgumentException(Messages.METHOD_CAN_NOT_ACCESS); } catch (NoSuchMethodException e) { ! throw new IllegalArgumentException(methodName+"is not defined in your Behvior Implemetation"); } *************** *** 134,138 **** this.wait(DEFAULT_TIME_OUT); } catch (InterruptedException e) { - // TODO Auto-generated catch block e.getMessage(); } --- 135,138 ---- *************** *** 151,174 **** } - public void addIgnoreMethod(String methodName, Class... vargs) { - // TODO Auto-generated method stub - - } - - public void removeIgnoreMethod(String methodName, Class... vargs) { - // TODO Auto-generated method stub - - } - - public void setDefaultReturnValue(Object returnValue, String methodName, - Class... vargs) { - - } - - public Object instance() { - // TODO Auto-generated method stub - return null; - } - protected Object methodCalledImpl(String methodName, Object[] parameters) throws Throwable{ --- 151,154 ---- *************** *** 202,206 **** Method m=methodList.get(i); Behavior b=behaviorMap.get(calledMethod.getMethodName()); - // m.setAccessible(true); Object retValue=m.invoke(b,calledMethod.getParameters()); retVal.put(methodName,retValue); --- 182,185 ---- *************** *** 212,227 **** private Object getReturnValue(String methodName) { - if (retVal.size() == 0) { - String returnValue = "No return value is set"; - // setDefaultReturnValue(returnValue, methodName); - - return returnValue; - } if (retVal.containsKey(methodName)) { return retVal.get(methodName); } - return null; } --- 191,218 ---- private Object getReturnValue(String methodName) { if (retVal.containsKey(methodName)) { return retVal.get(methodName); } return null; + } + + public void addIgnoreMethod(String methodName, Class... vargs) { + // TODO Auto-generated method stub + + } + + public void removeIgnoreMethod(String methodName, Class... vargs) { + // TODO Auto-generated method stub + + } + public void setDefaultReturnValue(Object returnValue, String methodName, + Class... vargs) { + + } + + public Object instance() { + // TODO Auto-generated method stub + return null; } |
From: Jay <ja...@us...> - 2006-03-20 15:01:35
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32291/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectSuperImpl.java Log Message: check in for further modify , the build is successful , but the test is not totally right right now Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MockObjectSuperImpl.java 23 Feb 2006 11:36:32 -0000 1.7 --- MockObjectSuperImpl.java 20 Mar 2006 15:01:20 -0000 1.8 *************** *** 2,5 **** --- 2,6 ---- + import java.lang.reflect.Method; import java.util.HashMap; import java.util.LinkedList; *************** *** 11,14 **** --- 12,16 ---- import biz.xsoftware.mock2.MockObject; + public abstract class MockObjectSuperImpl implements MockObject { *************** *** 26,30 **** /** ! * List of the methods been called ,and store them */ private Map<String, Object> retVal = new HashMap<String, Object>(); --- 28,32 ---- /** ! * a Map of return value which the method with return value has */ private Map<String, Object> retVal = new HashMap<String, Object>(); *************** *** 39,48 **** */ private Map<String, Throwable> methodWithException = new HashMap<String, Throwable>(); ! /** ! * a with the ignore method */ ! // private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>(); ! public CalledMethod expect(String methodName, Class... vargs) { return expect(methodName, DEFAULT_TIME_OUT, vargs); --- 41,55 ---- */ private Map<String, Throwable> methodWithException = new HashMap<String, Throwable>(); ! /** ! * A List of Method */ ! private List<Method> methodList=new LinkedList<Method>(); ! ! /** ! * a Map of behavior impl which is passed in by expect method ! */ ! private Map<String,Behavior> behaviorMap=new HashMap<String,Behavior>(); ! public CalledMethod expect(String methodName, Class... vargs) { return expect(methodName, DEFAULT_TIME_OUT, vargs); *************** *** 61,65 **** public CalledMethod expect(String methodName, Behavior behavior, ! Class... params) { return expect(methodName, behavior, DEFAULT_TIME_OUT, params); --- 68,72 ---- public CalledMethod expect(String methodName, Behavior behavior, ! Class... params){ return expect(methodName, behavior, DEFAULT_TIME_OUT, params); *************** *** 95,103 **** public CalledMethod expect(String methodName, Behavior behavior, ! long timeout, Class... params) { ! // TODO Auto-generated method stub ! return null; } public void verify(){ --- 102,129 ---- public CalledMethod expect(String methodName, Behavior behavior, ! long timeout, Class... params){ ! if(methodName==null) ! throw new IllegalArgumentException("method name can not be null"); ! CalledMethod calledMethod=new CalledMethodImpl(methodName); ! methodsExpected.add(calledMethod); ! behaviorMap.put(methodName,behavior); ! ! ! try { ! Class c=behavior.getClass(); ! Method method = c.getMethod(methodName,params); ! methodList.add(method); ! } catch (SecurityException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } catch (NoSuchMethodException e) { ! throw new IllegalArgumentException("method:"+methodName+"is not defined in your Behvior Implemetation"); ! } ! ! return calledMethod; } + + public void verify(){ *************** *** 118,122 **** CalledMethod calledMethod = methodsCalled.remove(0); CalledMethodImpl m = (CalledMethodImpl) methodsExpected.remove(0); - m.setParameters(calledMethod.getParameters()); m.setStackTrace(calledMethod.getStackTrace()); --- 144,147 ---- *************** *** 172,178 **** throw t; } ! ! ! return getReturnValue(methodName); } --- 197,212 ---- throw t; } ! ! for(int i=0;i<methodList.size();i++){ ! if(methodList.get(i).getName()==calledMethod.getMethodName()){ ! Method m=methodList.get(i); ! Behavior b=behaviorMap.get(calledMethod.getMethodName()); ! // m.setAccessible(true); ! Object retValue=m.invoke(b,calledMethod.getParameters()); ! retVal.put(methodName,retValue); ! } ! } ! ! return getReturnValue(methodName); } *************** *** 180,184 **** if (retVal.size() == 0) { String returnValue = "No return value is set"; ! setDefaultReturnValue(returnValue, methodName); } if (retVal.containsKey(methodName)) { --- 214,220 ---- if (retVal.size() == 0) { String returnValue = "No return value is set"; ! // setDefaultReturnValue(returnValue, methodName); ! ! return returnValue; } if (retVal.containsKey(methodName)) { |
From: Jay <ja...@us...> - 2006-03-20 15:01:35
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32291/input/javasrc/biz/xsoftware/mock2 Modified Files: MockObject.java Log Message: check in for further modify , the build is successful , but the test is not totally right right now Index: MockObject.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/MockObject.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MockObject.java 23 Feb 2006 11:36:32 -0000 1.4 --- MockObject.java 20 Mar 2006 15:01:20 -0000 1.5 *************** *** 64,67 **** --- 64,68 ---- * @return the CalledMethod information that will be filled after the method * is called + * @throws NoSuchMethodException */ public CalledMethod expect(String methodName, Behavior behavior, *************** *** 135,141 **** * @return the CalledMethod information that will be filled after the method * is called */ public CalledMethod expect(String methodName, Behavior behavior, ! long timeout, Class... params); /** --- 136,143 ---- * @return the CalledMethod information that will be filled after the method * is called + * @throws NoSuchMethodException */ public CalledMethod expect(String methodName, Behavior behavior, ! long timeout, Class... params) ; /** |
From: Jay <ja...@us...> - 2006-03-20 15:01:35
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32291/input/javasrc/biz/xsoftware/test/mock2 Modified Files: FakeSystem.java ListenerOne.java TestMockCreator.java Added Files: MyBehavior.java Log Message: check in for further modify , the build is successful , but the test is not totally right right now Index: FakeSystem.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/FakeSystem.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FakeSystem.java 19 Mar 2006 14:49:28 -0000 1.2 --- FakeSystem.java 20 Mar 2006 15:01:20 -0000 1.3 *************** *** 16,22 **** //now modify data....if mocklib did not clone, the //test will fail ! for(int i = 0; i < data.length; i++) { ! data[i] = -1; ! } //there are two paths in the system.....if listenerOne --- 16,22 ---- //now modify data....if mocklib did not clone, the //test will fail ! // for(int i = 0; i < data.length; i++) { ! // data[i] = -1; ! // } //there are two paths in the system.....if listenerOne Index: ListenerOne.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/ListenerOne.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ListenerOne.java 19 Mar 2006 14:27:59 -0000 1.4 --- ListenerOne.java 20 Mar 2006 15:01:20 -0000 1.5 *************** *** 24,27 **** --- 24,29 ---- public void noParams(); + + public void readByte(byte[] b); public int getField(); Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TestMockCreator.java 19 Mar 2006 14:49:28 -0000 1.9 --- TestMockCreator.java 20 Mar 2006 15:01:20 -0000 1.10 *************** *** 6,10 **** import junit.framework.TestCase; - import biz.xsoftware.mock2.Behavior; import biz.xsoftware.mock2.CalledMethod; import biz.xsoftware.mock2.Messages; --- 6,9 ---- *************** *** 63,67 **** } ! public void testTwoMethods() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; --- 62,89 ---- } ! public void testExpectWithRetVal() throws Exception { ! MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! ListenerOne l = (ListenerOne) m; ! ! Object returnVal = "OK"; ! String methodName = "callWithRetVal"; ! CalledMethod method = m.expect(returnVal, methodName); ! ! String param = "some params"; ! String retVal = l.callWithRetVal(param); ! ! m.verify(); ! ! assertEquals("The method name should be equal", method.getMethodName(), ! methodName); ! assertEquals("the params should be the same ", ! method.getParameters()[0], param); ! assertEquals("the length of param should be equal", 1, method ! .getParameters().length); ! assertEquals("the return value should be the same", returnVal, retVal); ! ! } ! ! public void testTwoMethods() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; *************** *** 152,182 **** fail("This should fail since m.verify() is not called"); } catch (IllegalStateException e) { assertEquals(Messages.VERIFY_NOT_CALLED, e.getMessage()); } } - public void testExpectWithRetVal() throws Exception { - MockObject m = MockObjectFactory.createMock(ListenerOne.class); - ListenerOne l = (ListenerOne) m; - - Object returnVal = "OK"; - String methodName = "callWithRetVal"; - CalledMethod method = m.expect(returnVal, methodName); - - String param = "some params"; - String retVal = l.callWithRetVal(param); - - m.verify(); - - assertEquals("The method name should be equal", method.getMethodName(), - methodName); - assertEquals("the params should be the same ", - method.getParameters()[0], param); - assertEquals("the length of param should be equal", 1, method - .getParameters().length); - assertEquals("the return value should be the same", returnVal, retVal); - - } - public void testRemoveCalledMethod() { --- 174,183 ---- fail("This should fail since m.verify() is not called"); } catch (IllegalStateException e) { + + assertEquals(Messages.VERIFY_NOT_CALLED, e.getMessage()); } } public void testRemoveCalledMethod() { *************** *** 207,211 **** } ! public void xxxtestExpectWithBehavior() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; --- 208,233 ---- } ! ! // public void testExpectWithBehavior() { ! // MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! // ListenerOne l=(ListenerOne)m; ! // ! // byte[] b=new byte[]{1,2,3,4}; ! // String methodName="readByte"; ! // MyBehavior bh=new MyBehavior(20); ! // ! // CalledMethod readByte= m.expect(methodName,bh,byte[].class); ! // ! // l.readByte(b); ! // // byte[] bt= bh.cloneByte(b); ! // ! // m.verify(); ! // // System.out.print(readByte.getParameters()[1]); ! // ! // assertEquals("the first param should be 2",2,readByte.getParameters()[0]); ! // ! // } ! ! public void testExpectWithBehavior() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; *************** *** 215,223 **** //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); --- 237,247 ---- //we are expecting this array to be modified so clone it here... byte[] expected = new byte[] { 4, 5, 6, 7 }; ! ! 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 ???? int answer = systemUnderTest.runSystem(clone); *************** *** 225,229 **** byte[] actual = (byte[])method.getParameters()[0]; ! assertEquals(expected[0], actual[0]); assertEquals(expected[1], actual[1]); assertEquals(expected[2], actual[2]); --- 249,253 ---- byte[] actual = (byte[])method.getParameters()[0]; ! assertEquals(30, actual[0]); assertEquals(expected[1], actual[1]); assertEquals(expected[2], actual[2]); *************** *** 232,264 **** } ! private static byte[] cloneBytes(byte[] data) { ! byte[] clone = new byte[data.length]; ! for(int i = 0; i < data.length; i++) { ! clone[i] = data[i]; ! } ! return clone; ! } ! private static class MyBehavior implements Behavior { ! ! private int answer; ! private byte zeroByte; ! ! public MyBehavior(int expectedAnswer, byte zeroByte) { ! this.answer = expectedAnswer; ! this.zeroByte = zeroByte; ! } ! ! public Object[] cloneWrite(byte[] data) { ! byte[] clone = cloneBytes(data); ! return new Object[] { clone }; ! } ! ! public int write(byte[] data) { ! data[0] = zeroByte; ! ! return answer; ! } ! ! } } --- 256,292 ---- } ! // private static byte[] cloneBytes(byte[] data) { ! // byte[] clone = new byte[data.length]; ! // for(int i = 0; i < data.length; i++) { ! // clone[i] = data[i]; ! // } ! // return clone; ! // } ! // static class MyBehavior implements Behavior { ! // ! // private int answer; ! // private byte zeroByte; ! // ! // public MyBehavior(int expectedAnswer, byte zeroByte) { ! // this.answer = expectedAnswer; ! // this.zeroByte = zeroByte; ! // } ! // ! // public byte[] cloneWrite(byte[] data) { ! // byte[] clone = new byte[data.length]; ! // for(int i = 0; i < data.length; i++) { ! // clone[i] = data[i]; ! // } ! // return clone; ! // } ! // ! // public int write(byte[] data) { ! // data[0] = zeroByte; ! // ! // return answer; ! // } ! // ! // ! // } } --- NEW FILE: MyBehavior.java --- package biz.xsoftware.test.mock2; import biz.xsoftware.mock2.Behavior; public class MyBehavior implements Behavior { // // public byte[] cloneByte(byte[] b){ // byte[] bt=new byte[b.length]; // for(int i=0;i<b.length;i++){ // bt[i]=b[i]; // } // return bt; // // } // // public void readByte(byte[] b){ // b[0]=2; // } private int answer; // private byte zeroByte; public MyBehavior(int expectedAnswer, byte zeroByte) { this.answer = expectedAnswer; //20 this.zeroByte = zeroByte; } // public Object[] cloneWrite(byte[] data) { // // byte[] clone = cloneBytes(data); // // return new Object[] { clone }; // } public byte[] cloneWrite(byte[] data) { byte[] clone = new byte[data.length]; for(int i = 0; i < data.length; i++) { clone[i] = data[i]; } return clone; } public int write(byte[] data) { data[0] = zeroByte; //30 return answer; //20 } } |
From: Nobody <fas...@us...> - 2006-03-19 14:49:33
|
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; } |
From: Nobody <fas...@us...> - 2006-03-19 14:38:03
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13674/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: fix the test. Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TestMockCreator.java 19 Mar 2006 14:27:59 -0000 1.7 --- TestMockCreator.java 19 Mar 2006 14:37:55 -0000 1.8 *************** *** 212,216 **** --- 212,218 ---- 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)); *************** *** 219,223 **** FakeSystem systemUnderTest = new FakeSystem(l); ! int answer = systemUnderTest.runSystem(expected); m.verify(); --- 221,225 ---- FakeSystem systemUnderTest = new FakeSystem(l); ! int answer = systemUnderTest.runSystem(clone); m.verify(); *************** *** 231,234 **** --- 233,244 ---- } + private static byte[] cloneBytes(byte[] data) { + byte[] clone = new byte[data.length]; + for(int i = 0; i < data.length; i++) { + clone[i] = data[i]; + } + return clone; + } + private static class MyBehavior implements Behavior { *************** *** 239,246 **** 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 }; } --- 249,253 ---- public Object[] cloneWrite(byte[] data) { ! byte[] clone = cloneBytes(data); return new Object[] { clone }; } |
From: Nobody <fas...@us...> - 2006-03-19 14:28:06
|
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; ! } ! } } |
From: Nobody <fas...@us...> - 2006-03-02 10:52:48
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31747/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: whoops, accidentally deleted some code. Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TestMockCreator.java 2 Mar 2006 10:47:18 -0000 1.5 --- TestMockCreator.java 2 Mar 2006 10:52:34 -0000 1.6 *************** *** 1,4 **** --- 1,5 ---- package biz.xsoftware.test.mock2; + import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; *************** *** 11,85 **** public class TestMockCreator extends TestCase { ! ! private static final Logger log = Logger.getLogger(TestMockCreator.class.getName()); ! ! public TestMockCreator(String name){ super(name); } ! ! public void testMockCreator()throws Exception{ MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! // ListenerOne l=(ListenerOne)m; ! ! ! ! String methodName="callMeSecond"; ! ! CalledMethod method=m.expect(methodName); ! ! // String param="some params"; ! // l.callMeSecond(param); ! try { method.getParameters(); fail("Since verify was not called, CalledMethod methods should not work"); ! } catch(IllegalStateException e) { } ! //assertEquals("the methodName should be the same",methodName,method.getMethodName()); ! //assertEquals("params should equal", param, method.getParameters()[0]); ! //assertEquals("param count should be 1", 1, method.getParameters().length); } public void testNoVerifyCalled() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! // ListenerOne l=(ListenerOne)m; String methodName1 = "callMeFirst"; ! String methodName2="callMeSecond"; ! CalledMethod callMeFirst =m.expect(methodName1); ! //eclipse complains this is never read so don't bother having it for now... ! //CalledMethod callMeSecond= ! m.expect(methodName2); ! try { callMeFirst.getParameters(); fail("The method was not called yet and verify() was not called, so above should throw exceptoin"); ! } catch(IllegalStateException e) { } } ! public void testTwoMethods() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! ListenerOne l=(ListenerOne)m; String methodName1 = "callMeFirst"; ! String methodName2="callMeSecond"; ! CalledMethod callMeFirst =m.expect(methodName1); ! CalledMethod callMeSecond=m.expect(methodName2); ! int var1 = 4; l.callMeFirst(var1); ! String param="some params"; l.callMeSecond(param); m.verify(); ! ! assertEquals("the methodName should be the same",methodName1,callMeFirst.getMethodName()); Object[] array = callMeFirst.getParameters(); assertEquals("params should equal", var1, array[0]); ! assertEquals("param count should be 1", 1, callMeFirst.getParameters().length); ! ! assertEquals("the methodName should be the same",methodName2,callMeSecond.getMethodName()); ! assertEquals("params should equal", param, callMeSecond.getParameters()[0]); ! assertEquals("param count should be 1", 1, callMeSecond.getParameters().length); } --- 12,94 ---- public class TestMockCreator extends TestCase { ! ! private static final Logger log = Logger.getLogger(TestMockCreator.class ! .getName()); ! ! public TestMockCreator(String name) { super(name); } ! ! public void testMockCreator() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! // ListenerOne l=(ListenerOne)m; ! ! String methodName = "callMeSecond"; ! ! CalledMethod method = m.expect(methodName); ! ! // String param="some params"; ! // l.callMeSecond(param); ! try { method.getParameters(); fail("Since verify was not called, CalledMethod methods should not work"); ! } catch (IllegalStateException e) { } ! // assertEquals("the methodName should be the ! // same",methodName,method.getMethodName()); ! // assertEquals("params should equal", param, ! // method.getParameters()[0]); ! // assertEquals("param count should be 1", 1, ! // method.getParameters().length); } public void testNoVerifyCalled() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! // ListenerOne l=(ListenerOne)m; String methodName1 = "callMeFirst"; ! String methodName2 = "callMeSecond"; ! CalledMethod callMeFirst = m.expect(methodName1); ! // eclipse complains this is never read so don't bother having it for ! // now... ! // CalledMethod callMeSecond= ! m.expect(methodName2); ! try { callMeFirst.getParameters(); fail("The method was not called yet and verify() was not called, so above should throw exceptoin"); ! } catch (IllegalStateException e) { } } ! public void testTwoMethods() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! ListenerOne l = (ListenerOne) m; String methodName1 = "callMeFirst"; ! String methodName2 = "callMeSecond"; ! CalledMethod callMeFirst = m.expect(methodName1); ! CalledMethod callMeSecond = m.expect(methodName2); ! int var1 = 4; l.callMeFirst(var1); ! String param = "some params"; l.callMeSecond(param); m.verify(); ! ! assertEquals("the methodName should be the same", methodName1, ! callMeFirst.getMethodName()); Object[] array = callMeFirst.getParameters(); assertEquals("params should equal", var1, array[0]); ! assertEquals("param count should be 1", 1, ! callMeFirst.getParameters().length); ! ! assertEquals("the methodName should be the same", methodName2, ! callMeSecond.getMethodName()); ! assertEquals("params should equal", param, ! callMeSecond.getParameters()[0]); ! assertEquals("param count should be 1", 1, ! callMeSecond.getParameters().length); } *************** *** 104,108 **** log.log(Level.WARNING, "exception", e); throw new RuntimeException(e); ! } } }; --- 113,117 ---- log.log(Level.WARNING, "exception", e); throw new RuntimeException(e); ! } } }; *************** *** 125,171 **** callMeSecond.getParameters().length); } ! public void testFailure() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! ListenerOne l=(ListenerOne)m; ! ! String param="some params"; l.callMeSecond(param); ! ! String methodName="callMeSecond"; ! ! CalledMethod method=m.expect(methodName); ! try { ! assertEquals("params should equal", param, method.getParameters()[0]); fail("This should fail since m.verify() is not called"); ! } catch(IllegalStateException e) { assertEquals(Messages.VERIFY_NOT_CALLED, e.getMessage()); } } - - public void testExpectWithRetVal() throws Exception{ - MockObject m=MockObjectFactory.createMock(ListenerOne.class); - ListenerOne l=(ListenerOne)m; - - Object returnVal="OK"; - String methodName="callWithRetVal"; - CalledMethod method=m.expect(returnVal,methodName); - - String param="some params"; - String retVal=l.callWithRetVal(param); - - m.verify(); - - assertEquals("The method name should be equal",method.getMethodName(),methodName); - assertEquals("the params should be the same ",method.getParameters()[0],param); - assertEquals("the length of param should be equal",1,method.getParameters().length); - assertEquals("the return value should be the same",returnVal,retVal); - - } - - public void testRemoveCalledMethod(){ - - } } --- 134,211 ---- callMeSecond.getParameters().length); } ! public void testFailure() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ! ListenerOne l = (ListenerOne) m; ! ! String param = "some params"; l.callMeSecond(param); ! ! String methodName = "callMeSecond"; ! ! CalledMethod method = m.expect(methodName); ! try { ! assertEquals("params should equal", param, ! method.getParameters()[0]); fail("This should fail since m.verify() is not called"); ! } catch (IllegalStateException e) { assertEquals(Messages.VERIFY_NOT_CALLED, e.getMessage()); } } + public void testExpectWithRetVal() throws Exception { + MockObject m = MockObjectFactory.createMock(ListenerOne.class); + ListenerOne l = (ListenerOne) m; + + Object returnVal = "OK"; + String methodName = "callWithRetVal"; + CalledMethod method = m.expect(returnVal, methodName); + + String param = "some params"; + String retVal = l.callWithRetVal(param); + + m.verify(); + + assertEquals("The method name should be equal", method.getMethodName(), + methodName); + assertEquals("the params should be the same ", + method.getParameters()[0], param); + assertEquals("the length of param should be equal", 1, method + .getParameters().length); + assertEquals("the return value should be the same", returnVal, retVal); + + } + + public void testRemoveCalledMethod() { + + } + + public void testExceptionThrows() throws Exception { + MockObject m = MockObjectFactory.createMock(ListenerOne.class); + ListenerOne l = (ListenerOne) m; + + String methodName = "callMeSecond"; + String message = "Make sure systemUnderTest handles exception"; + + //variable never used. eclipse is complaining... + //CalledMethod calledMethod = + m.expect(methodName, new IOException( + message)); + + String param = "params"; + try { + l.callMeSecond(param); + fail("Exception should be thrown earlier, try to find why it did not!!!"); + } catch (IOException e) { + + assertEquals(message, e.getMessage()); + } + + m.verify(); + } + + public void testExpectWithBehavior() throws Exception { + //MockObject m = MockObjectFactory.createMock(ListenerOne.class); + } } |
From: Nobody <fas...@us...> - 2006-03-02 10:47:24
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28901/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: get rid of eclipse warnings. Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TestMockCreator.java 23 Feb 2006 11:36:32 -0000 1.4 --- TestMockCreator.java 2 Mar 2006 10:47:18 -0000 1.5 *************** *** 1,5 **** package biz.xsoftware.test.mock2; - import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; --- 1,4 ---- *************** *** 48,52 **** String methodName2="callMeSecond"; CalledMethod callMeFirst =m.expect(methodName1); ! CalledMethod callMeSecond=m.expect(methodName2); try { --- 47,53 ---- String methodName2="callMeSecond"; CalledMethod callMeFirst =m.expect(methodName1); ! //eclipse complains this is never read so don't bother having it for now... ! //CalledMethod callMeSecond= ! m.expect(methodName2); try { *************** *** 167,195 **** } - - public void testExceptionThrows() throws Exception{ - MockObject m=MockObjectFactory.createMock(ListenerOne.class); - ListenerOne l=(ListenerOne)m; - - String methodName="callMeSecond"; - String message="Make sure systemUnderTest handles exception"; - CalledMethod calledMethod=m.expect(methodName,new IOException(message)); - - - String param="params"; - try{ - l.callMeSecond(param); - fail("Exception should be thrown earlier, try to find why it did not!!!"); - } catch (IOException e) { - - assertEquals(message,e.getMessage()); - } - - m.verify(); - } - - public void testExpectWithBehavior()throws Exception { - MockObject m=MockObjectFactory.createMock(ListenerOne.class); - } } --- 168,171 ---- |
From: Jay <ja...@us...> - 2006-02-23 11:36:40
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6177/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectSuperImpl.java Log Message: changed implementation from branch and merged the second one to HEAD Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MockObjectSuperImpl.java 19 Feb 2006 19:20:52 -0000 1.6 --- MockObjectSuperImpl.java 23 Feb 2006 11:36:32 -0000 1.7 *************** *** 1,4 **** --- 1,5 ---- package biz.xsoftware.mock2.impl; + import java.util.HashMap; import java.util.LinkedList; *************** *** 12,17 **** public abstract class MockObjectSuperImpl implements MockObject { ! // private static final Logger logger = Logger ! // .getLogger(MockObjectSuperImpl.class.getName()); private static final long DEFAULT_TIME_OUT = 10000; --- 13,18 ---- public abstract class MockObjectSuperImpl implements MockObject { ! // private static final Logger logger = Logger ! // .getLogger(MockObjectSuperImpl.class.getName()); private static final long DEFAULT_TIME_OUT = 10000; *************** *** 27,31 **** * List of the methods been called ,and store them */ ! private Map retVal=new HashMap(); /** * List of the methods that have been expected --- 28,33 ---- * List of the methods been called ,and store them */ ! private Map<String, Object> retVal = new HashMap<String, Object>(); ! /** * List of the methods that have been expected *************** *** 34,47 **** /** ! * A map of queues, containing objects to return when methods are called */ ! // private Map<String, List<Object>> methodToReturnVal = new HashMap<String, List<Object>>(); /** ! * A map of default return values, which are used to return if the queue for ! * the method is empty. */ ! // private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>(); ! public CalledMethod expect(String methodName, Class... vargs) { return expect(methodName, DEFAULT_TIME_OUT, vargs); --- 36,48 ---- /** ! * A map of methods which will throw exception */ ! private Map<String, Throwable> methodWithException = new HashMap<String, Throwable>(); /** ! * a with the ignore method */ ! // private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>(); ! public CalledMethod expect(String methodName, Class... vargs) { return expect(methodName, DEFAULT_TIME_OUT, vargs); *************** *** 75,83 **** public CalledMethod expect(Object returnValue, String methodName, long timeout, Class... vargs) { ! if(methodName==null) throw new IllegalArgumentException("method name can not be null"); ! CalledMethod calledMethod=new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); ! retVal.put(methodName,returnValue); return calledMethod; } --- 76,84 ---- public CalledMethod expect(Object returnValue, String methodName, long timeout, Class... vargs) { ! if (methodName == null) throw new IllegalArgumentException("method name can not be null"); ! CalledMethod calledMethod = new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); ! retVal.put(methodName, returnValue); return calledMethod; } *************** *** 85,90 **** public CalledMethod expect(String methodName, Throwable throwable, long timeout, Class... vargs) { ! // TODO Auto-generated method stub ! return null; } --- 86,95 ---- public CalledMethod expect(String methodName, Throwable throwable, long timeout, Class... vargs) { ! if (methodName == null) ! throw new IllegalArgumentException("method name can not be null"); ! CalledMethod calledMethod = new CalledMethodImpl(methodName); ! methodsExpected.add(calledMethod); ! methodWithException.put(methodName, throwable); ! return calledMethod; } *************** *** 94,118 **** return null; } ! ! ! public void verify() { if (methodsCalled.size() == 0) { ! synchronized(this){ try { this.wait(DEFAULT_TIME_OUT); } catch (InterruptedException e) { // TODO Auto-generated catch block ! e.printStackTrace(); } } } ! while (methodsCalled.size() != 0) { CalledMethod calledMethod = methodsCalled.remove(0); CalledMethodImpl m = (CalledMethodImpl) methodsExpected.remove(0); m.setParameters(calledMethod.getParameters()); ! m.setStackTrace(calledMethod.getStackTrace()); ! } --- 99,125 ---- return null; } ! ! public void verify(){ if (methodsCalled.size() == 0) { ! synchronized (this) { ! try { this.wait(DEFAULT_TIME_OUT); } catch (InterruptedException e) { // TODO Auto-generated catch block ! e.getMessage(); } + } } ! while (methodsCalled.size() != 0) { CalledMethod calledMethod = methodsCalled.remove(0); CalledMethodImpl m = (CalledMethodImpl) methodsExpected.remove(0); + m.setParameters(calledMethod.getParameters()); ! m.setStackTrace(calledMethod.getStackTrace()); ! } *************** *** 131,135 **** public void setDefaultReturnValue(Object returnValue, String methodName, Class... vargs) { - } --- 138,141 ---- *************** *** 140,145 **** } ! protected synchronized Object methodCalledImpl(String methodName, ! Object[] parameters) { methodName = methodName.intern(); --- 146,151 ---- } ! protected Object methodCalledImpl(String methodName, ! Object[] parameters) throws Throwable{ methodName = methodName.intern(); *************** *** 157,167 **** String stackTrace = "method Called=" + methodName + "(" + params + "on object" + this + ")"; ! // if(methodsExpected.size()!=0){ CalledMethod calledMethod = new CalledMethodImpl(methodName, parameters, stackTrace); - methodsCalled.add(calledMethod); ! ! // } return getReturnValue(methodName); --- 163,176 ---- String stackTrace = "method Called=" + methodName + "(" + params + "on object" + this + ")"; ! CalledMethod calledMethod = new CalledMethodImpl(methodName, parameters, stackTrace); methodsCalled.add(calledMethod); ! ! if(methodWithException.containsKey(calledMethod.getMethodName())){ ! Throwable t=methodWithException.get(calledMethod.getMethodName()); ! throw t; ! } ! return getReturnValue(methodName); *************** *** 169,182 **** private Object getReturnValue(String methodName) { ! if(retVal.size()==0){ ! String returnValue="No return value is set"; ! setDefaultReturnValue(returnValue,methodName); } ! if(retVal.containsKey(methodName)){ return retVal.get(methodName); } ! ! return null; ! } --- 178,190 ---- private Object getReturnValue(String methodName) { ! if (retVal.size() == 0) { ! String returnValue = "No return value is set"; ! setDefaultReturnValue(returnValue, methodName); } ! if (retVal.containsKey(methodName)) { return retVal.get(methodName); } ! ! return null; } |
From: Jay <ja...@us...> - 2006-02-23 11:36:37
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6177/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: changed implementation from branch and merged the second one to HEAD Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TestMockCreator.java 17 Feb 2006 15:07:40 -0000 1.3 --- TestMockCreator.java 23 Feb 2006 11:36:32 -0000 1.4 *************** *** 1,4 **** --- 1,5 ---- package biz.xsoftware.test.mock2; + import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; *************** *** 166,169 **** --- 167,195 ---- } + + public void testExceptionThrows() throws Exception{ + MockObject m=MockObjectFactory.createMock(ListenerOne.class); + ListenerOne l=(ListenerOne)m; + + String methodName="callMeSecond"; + String message="Make sure systemUnderTest handles exception"; + CalledMethod calledMethod=m.expect(methodName,new IOException(message)); + + + String param="params"; + try{ + l.callMeSecond(param); + fail("Exception should be thrown earlier, try to find why it did not!!!"); + } catch (IOException e) { + + assertEquals(message,e.getMessage()); + } + + m.verify(); + } + + public void testExpectWithBehavior()throws Exception { + MockObject m=MockObjectFactory.createMock(ListenerOne.class); + } } |
From: Jay <ja...@us...> - 2006-02-23 11:36:36
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6177/input/javasrc/biz/xsoftware/mock2 Modified Files: MockObject.java Log Message: changed implementation from branch and merged the second one to HEAD Index: MockObject.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/MockObject.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MockObject.java 16 Feb 2006 15:37:35 -0000 1.3 --- MockObject.java 23 Feb 2006 11:36:32 -0000 1.4 *************** *** 143,149 **** * @param timeout * the time set for waitting the call - * @throws InterruptedException */ ! public void verify() throws InterruptedException; /** --- 143,148 ---- * @param timeout * the time set for waitting the call */ ! public void verify(); /** |
From: Jay <ja...@us...> - 2006-02-23 11:06:51
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21376/input/javasrc/biz/xsoftware/test/mock2 Modified Files: Tag: branchForOffice TestMockCreator.java Log Message: change implementation , Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.1.2.13 retrieving revision 1.1.2.14 diff -C2 -d -r1.1.2.13 -r1.1.2.14 *** TestMockCreator.java 22 Feb 2006 14:14:45 -0000 1.1.2.13 --- TestMockCreator.java 23 Feb 2006 11:06:46 -0000 1.1.2.14 *************** *** 179,191 **** String param="params"; try{ ! l.callMeSecond(param); ! m.verify(); fail("Exception should be thrown earlier, try to find why it did not!!!"); } catch (IOException e) { assertEquals(message,e.getMessage()); } ! ! } --- 179,193 ---- String param="params"; try{ ! l.callMeSecond(param); fail("Exception should be thrown earlier, try to find why it did not!!!"); } catch (IOException e) { + m.verify(); assertEquals(message,e.getMessage()); } ! } ! ! public void testExpectWithBehavior()throws Exception { ! MockObject m=MockObjectFactory.createMock(ListenerOne.class); } |
From: Jay <ja...@us...> - 2006-02-23 11:06:51
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21376/input/javasrc/biz/xsoftware/mock2 Modified Files: Tag: branchForOffice MockObject.java Log Message: change implementation , Index: MockObject.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/MockObject.java,v retrieving revision 1.2.2.5 retrieving revision 1.2.2.6 diff -C2 -d -r1.2.2.5 -r1.2.2.6 *** MockObject.java 22 Feb 2006 14:14:00 -0000 1.2.2.5 --- MockObject.java 23 Feb 2006 11:06:47 -0000 1.2.2.6 *************** *** 147,151 **** * @throws Throwable */ ! public void verify() throws Exception; /** --- 147,151 ---- * @throws Throwable */ ! public void verify(); /** |
From: Jay <ja...@us...> - 2006-02-23 11:06:50
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21376/input/javasrc/biz/xsoftware/mock2/impl Modified Files: Tag: branchForOffice MockObjectSuperImpl.java Log Message: change implementation , Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.3.2.9 retrieving revision 1.3.2.10 diff -C2 -d -r1.3.2.9 -r1.3.2.10 *** MockObjectSuperImpl.java 22 Feb 2006 14:20:29 -0000 1.3.2.9 --- MockObjectSuperImpl.java 23 Feb 2006 11:06:46 -0000 1.3.2.10 *************** *** 100,109 **** } ! public void verify() throws Exception{ if (methodsCalled.size() == 0) { synchronized (this) { ! this.wait(DEFAULT_TIME_OUT); } --- 100,114 ---- } ! public void verify(){ if (methodsCalled.size() == 0) { synchronized (this) { ! try { ! this.wait(DEFAULT_TIME_OUT); ! } catch (InterruptedException e) { ! // TODO Auto-generated catch block ! e.getMessage(); ! } } *************** *** 115,125 **** m.setParameters(calledMethod.getParameters()); ! m.setStackTrace(calledMethod.getStackTrace()); ! ! if(methodWithException.containsKey(m.getMethodName())){ ! Throwable t=methodWithException.get(m.getMethodName()); ! throw (Exception)t; ! } ! } --- 120,124 ---- m.setParameters(calledMethod.getParameters()); ! m.setStackTrace(calledMethod.getStackTrace()); } *************** *** 147,152 **** } ! synchronized protected Object methodCalledImpl(String methodName, ! Object[] parameters) { methodName = methodName.intern(); --- 146,151 ---- } ! protected Object methodCalledImpl(String methodName, ! Object[] parameters) throws Throwable{ methodName = methodName.intern(); *************** *** 167,172 **** CalledMethod calledMethod = new CalledMethodImpl(methodName, parameters, stackTrace); - methodsCalled.add(calledMethod); return getReturnValue(methodName); --- 166,176 ---- CalledMethod calledMethod = new CalledMethodImpl(methodName, parameters, stackTrace); methodsCalled.add(calledMethod); + + if(methodWithException.containsKey(calledMethod.getMethodName())){ + Throwable t=methodWithException.get(calledMethod.getMethodName()); + throw t; + } + return getReturnValue(methodName); |
From: Jay <ja...@us...> - 2006-02-22 14:20:33
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30703/input/javasrc/biz/xsoftware/mock2/impl Modified Files: Tag: branchForOffice MockObjectSuperImpl.java Log Message: implement exception handling. i am not so sure this implementation is the best one Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.3.2.8 retrieving revision 1.3.2.9 diff -C2 -d -r1.3.2.8 -r1.3.2.9 *** MockObjectSuperImpl.java 18 Feb 2006 08:09:16 -0000 1.3.2.8 --- MockObjectSuperImpl.java 22 Feb 2006 14:20:29 -0000 1.3.2.9 *************** *** 1,4 **** --- 1,5 ---- package biz.xsoftware.mock2.impl; + import java.io.IOException; import java.util.HashMap; import java.util.LinkedList; *************** *** 12,17 **** public abstract class MockObjectSuperImpl implements MockObject { ! // private static final Logger logger = Logger ! // .getLogger(MockObjectSuperImpl.class.getName()); private static final long DEFAULT_TIME_OUT = 10000; --- 13,18 ---- public abstract class MockObjectSuperImpl implements MockObject { ! // private static final Logger logger = Logger ! // .getLogger(MockObjectSuperImpl.class.getName()); private static final long DEFAULT_TIME_OUT = 10000; *************** *** 27,31 **** * List of the methods been called ,and store them */ ! Map retVal=new HashMap(); /** * List of the methods that have been expected --- 28,33 ---- * List of the methods been called ,and store them */ ! private Map<String, Object> retVal = new HashMap<String, Object>(); ! /** * List of the methods that have been expected *************** *** 34,47 **** /** ! * A map of queues, containing objects to return when methods are called */ ! // private Map<String, List<Object>> methodToReturnVal = new HashMap<String, List<Object>>(); /** ! * A map of default return values, which are used to return if the queue for ! * the method is empty. */ ! // private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>(); ! public CalledMethod expect(String methodName, Class... vargs) { return expect(methodName, DEFAULT_TIME_OUT, vargs); --- 36,48 ---- /** ! * A map of methods which will throw exception */ ! private Map<String, Throwable> methodWithException = new HashMap<String, Throwable>(); /** ! * a with the ignore method */ ! // private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>(); ! public CalledMethod expect(String methodName, Class... vargs) { return expect(methodName, DEFAULT_TIME_OUT, vargs); *************** *** 75,83 **** public CalledMethod expect(Object returnValue, String methodName, long timeout, Class... vargs) { ! if(methodName==null) throw new IllegalArgumentException("method name can not be null"); ! CalledMethod calledMethod=new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); ! retVal.put(methodName,returnValue); return calledMethod; } --- 76,84 ---- public CalledMethod expect(Object returnValue, String methodName, long timeout, Class... vargs) { ! if (methodName == null) throw new IllegalArgumentException("method name can not be null"); ! CalledMethod calledMethod = new CalledMethodImpl(methodName); methodsExpected.add(calledMethod); ! retVal.put(methodName, returnValue); return calledMethod; } *************** *** 85,90 **** public CalledMethod expect(String methodName, Throwable throwable, long timeout, Class... vargs) { ! // TODO Auto-generated method stub ! return null; } --- 86,95 ---- public CalledMethod expect(String methodName, Throwable throwable, long timeout, Class... vargs) { ! if (methodName == null) ! throw new IllegalArgumentException("method name can not be null"); ! CalledMethod calledMethod = new CalledMethodImpl(methodName); ! methodsExpected.add(calledMethod); ! methodWithException.put(methodName, throwable); ! return calledMethod; } *************** *** 94,118 **** return null; } ! ! ! public void verify() { if (methodsCalled.size() == 0) { ! synchronized(this){ ! try { ! this.wait(DEFAULT_TIME_OUT); ! } catch (InterruptedException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } } } ! while (methodsCalled.size() != 0) { CalledMethod calledMethod = methodsCalled.remove(0); CalledMethodImpl m = (CalledMethodImpl) methodsExpected.remove(0); m.setParameters(calledMethod.getParameters()); m.setStackTrace(calledMethod.getStackTrace()); ! } --- 99,126 ---- return null; } ! ! public void verify() throws Exception{ if (methodsCalled.size() == 0) { ! synchronized (this) { ! ! this.wait(DEFAULT_TIME_OUT); ! } } ! while (methodsCalled.size() != 0) { CalledMethod calledMethod = methodsCalled.remove(0); CalledMethodImpl m = (CalledMethodImpl) methodsExpected.remove(0); + m.setParameters(calledMethod.getParameters()); m.setStackTrace(calledMethod.getStackTrace()); ! ! if(methodWithException.containsKey(m.getMethodName())){ ! Throwable t=methodWithException.get(m.getMethodName()); ! throw (Exception)t; ! } ! ! } *************** *** 131,135 **** public void setDefaultReturnValue(Object returnValue, String methodName, Class... vargs) { - } --- 139,142 ---- *************** *** 157,182 **** String stackTrace = "method Called=" + methodName + "(" + params + "on object" + this + ")"; ! // if(methodsExpected.size()!=0){ CalledMethod calledMethod = new CalledMethodImpl(methodName, parameters, stackTrace); ! methodsCalled.add(calledMethod); - // } - return getReturnValue(methodName); } private Object getReturnValue(String methodName) { ! if(retVal.size()==0){ ! String returnValue="No return value is set"; ! setDefaultReturnValue(returnValue,methodName); } ! if(retVal.containsKey(methodName)){ return retVal.get(methodName); } ! ! return null; ! } --- 164,186 ---- String stackTrace = "method Called=" + methodName + "(" + params + "on object" + this + ")"; ! CalledMethod calledMethod = new CalledMethodImpl(methodName, parameters, stackTrace); ! methodsCalled.add(calledMethod); return getReturnValue(methodName); } private Object getReturnValue(String methodName) { ! if (retVal.size() == 0) { ! String returnValue = "No return value is set"; ! setDefaultReturnValue(returnValue, methodName); } ! if (retVal.containsKey(methodName)) { return retVal.get(methodName); } ! ! return null; } |