mocklib-checkins Mailing List for mocklib (Page 17)
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: Christopher B. W. <da...@us...> - 2006-05-02 16:50:14
|
Update of /cvsroot/mocklib/mocklib2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6945 Modified Files: .classpath Log Message: corrected location of eclipse generated classes Index: .classpath =================================================================== RCS file: /cvsroot/mocklib/mocklib2/.classpath,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** .classpath 18 Sep 2005 17:10:23 -0000 1.3 --- .classpath 2 May 2006 16:50:09 -0000 1.4 *************** *** 4,7 **** <classpathentry kind="lib" path="tools/ant-junit/junit.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> ! <classpathentry kind="output" path="output/eclipsegen"/> </classpath> --- 4,7 ---- <classpathentry kind="lib" path="tools/ant-junit/junit.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> ! <classpathentry kind="output" path="eclipsegen"/> </classpath> |
From: Jay <ja...@us...> - 2006-04-06 15:38:13
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27729/input/javasrc/biz/xsoftware/mock2 Modified Files: ExpectFailedException.java Log Message: edit expectFailedException to add a new constructor Index: ExpectFailedException.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/ExpectFailedException.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ExpectFailedException.java 5 Apr 2006 23:51:38 -0000 1.3 --- ExpectFailedException.java 6 Apr 2006 15:37:55 -0000 1.4 *************** *** 57,60 **** --- 57,67 ---- } + + public ExpectFailedException(String message) { + super(message); + + } + + /** * Gets the reason expecting the call(s) failed. |
From: Jay <ja...@us...> - 2006-04-06 15:25:48
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19153/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: get dean's 2 test pass , add expectFailedException to mocklib2 Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** TestMockCreator.java 5 Apr 2006 23:55:16 -0000 1.17 --- TestMockCreator.java 6 Apr 2006 15:25:06 -0000 1.18 *************** *** 120,124 **** } ! public void xxxtestTwoMethodsWrongOrder() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; --- 120,124 ---- } ! public void testTwoMethodsWrongOrder() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; *************** *** 142,146 **** } ! public void xxxtestTooManyMethodsCalled() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; --- 142,146 ---- } ! public void testTooManyMethodsCalled() throws Exception { MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; *************** *** 155,158 **** --- 155,159 ---- int var1 = 4; l.callMeFirst(var1); + //this last one should make verify fail as we don't expect it l.callMeFirst(var1); *************** *** 318,323 **** CalledMethod callMeFirst=m.expect(methodName1); ! m.addIgnoreMethod(methodName1); ! m.setDefaultReturnValue("retval",methodName1); CalledMethod callMeLast=m.expect(methodName2); CalledMethod callAgain=m.expect(methodName1); --- 319,323 ---- CalledMethod callMeFirst=m.expect(methodName1); ! CalledMethod callMeLast=m.expect(methodName2); CalledMethod callAgain=m.expect(methodName1); *************** *** 325,330 **** CalledMethod callLastAgain=m.expect(methodName2); CalledMethod callThirdTime=m.expect(methodName1); ! l.callMeFirst(param1); l.callMeLast(param2); l.callMeFirst(param1); --- 325,332 ---- CalledMethod callLastAgain=m.expect(methodName2); CalledMethod callThirdTime=m.expect(methodName1); ! l.callMeFirst(param1); + m.addIgnoreMethod(methodName1); + m.setDefaultReturnValue("retval",methodName1); l.callMeLast(param2); l.callMeFirst(param1); *************** *** 332,337 **** l.callMeFirst(param1); ! ! m.verify(); --- 334,343 ---- l.callMeFirst(param1); ! try{ ! m.verify(); ! }catch(RuntimeException e){ ! fail("should fail if goes here"); ! ! } |
From: Jay <ja...@us...> - 2006-04-06 15:25:40
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19153/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectSuperImpl.java Log Message: get dean's 2 test pass , add expectFailedException to mocklib2 Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** MockObjectSuperImpl.java 5 Apr 2006 15:27:08 -0000 1.12 --- MockObjectSuperImpl.java 6 Apr 2006 15:25:03 -0000 1.13 *************** *** 1,5 **** package biz.xsoftware.mock2.impl; - import java.lang.reflect.Method; import java.util.HashMap; --- 1,4 ---- *************** *** 12,15 **** --- 11,15 ---- import biz.xsoftware.mock2.Behavior; import biz.xsoftware.mock2.CalledMethod; + import biz.xsoftware.mock2.ExpectFailedException; import biz.xsoftware.mock2.MockObject; import biz.xsoftware.mock2.Messages; *************** *** 18,22 **** * * @author huajie.zeng ! * */ public abstract class MockObjectSuperImpl implements MockObject { --- 18,22 ---- * * @author huajie.zeng ! * */ public abstract class MockObjectSuperImpl implements MockObject { *************** *** 30,64 **** /** ! * List of the current methods that have been called. ! */ private List<CalledMethod> methodsCalled = new LinkedList<CalledMethod>(); /** ! * a Map of return value which the method with return value has ! */ private Map<String, Object> retVal = new HashMap<String, Object>(); /** ! * List of the methods that have been expected ! */ private List<CalledMethod> methodsExpected = new LinkedList<CalledMethod>(); /** ! * A map of methods which will throw exception ! */ 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>(); /** ! * A Map of methods which are ignored by tester ! */ private Map<String,CalledMethod> methodsIgnored=new HashMap<String,CalledMethod>(); --- 30,64 ---- /** ! * List of the current methods that have been called. ! */ private List<CalledMethod> methodsCalled = new LinkedList<CalledMethod>(); /** ! * a Map of return value which the method with return value has ! */ private Map<String, Object> retVal = new HashMap<String, Object>(); /** ! * List of the methods that have been expected ! */ private List<CalledMethod> methodsExpected = new LinkedList<CalledMethod>(); /** ! * A map of methods which will throw exception ! */ 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>(); /** ! * A Map of methods which are ignored by tester ! */ private Map<String,CalledMethod> methodsIgnored=new HashMap<String,CalledMethod>(); *************** *** 186,194 **** 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()); --- 186,209 ---- while (methodsCalled.size() != 0) { CalledMethod calledMethod = methodsCalled.remove(0); ! CalledMethodImpl m=new CalledMethodImpl(); ! if(methodsExpected.size()!=0){ ! m = (CalledMethodImpl) methodsExpected.remove(0); ! while(m.getMethodName()!=calledMethod.getMethodName()){ ! if(methodsIgnored.containsKey(m.getMethodName())){ ! calledMethod=methodsCalled.remove(0); ! }else ! { ! throw new ExpectFailedException(Messages.ORDER_EXCEPTION); ! } ! ! } ! }else if(methodsIgnored.containsKey(calledMethod.getMethodName())){ ! continue; ! }else ! { ! throw new ExpectFailedException(Messages.TOO_MANY_METHODS_CALLED); } + m.setParameters(calledMethod.getParameters()); |
From: Jay <ja...@us...> - 2006-04-06 15:25:28
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19153/input/javasrc/biz/xsoftware/mock2 Modified Files: Messages.java Log Message: get dean's 2 test pass , add expectFailedException to mocklib2 Index: Messages.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/Messages.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Messages.java 21 Mar 2006 09:25:33 -0000 1.4 --- Messages.java 6 Apr 2006 15:25:09 -0000 1.5 *************** *** 10,13 **** --- 10,15 ---- 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"; + public static final String TOO_MANY_METHODS_CALLED="too many methods called while less method expected"; + public static final String ORDER_EXCEPTION="methods called or methods expected is in wrong order"; } |
From: Nobody <fas...@us...> - 2006-04-05 23:55:26
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22444/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: add another test that is broken. Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** TestMockCreator.java 5 Apr 2006 23:51:38 -0000 1.16 --- TestMockCreator.java 5 Apr 2006 23:55:16 -0000 1.17 *************** *** 141,144 **** --- 141,168 ---- } } + + public void xxxtestTooManyMethodsCalled() throws Exception { + MockObject m = MockObjectFactory.createMock(ListenerOne.class); + ListenerOne l = (ListenerOne) m; + + String methodName1 = "callMeFirst"; + String methodName2 = "callMeSecond"; + m.expect(methodName1); + m.expect(methodName2); + + String param = "some params"; + l.callMeSecond(param); + int var1 = 4; + l.callMeFirst(var1); + //this last one should make verify fail as we don't expect it + l.callMeFirst(var1); + + try { + m.verify(); + fail("Should have thrown exception and did not, methods were called in wrong order"); + } catch(ExpectFailedException e) { + //expect should fail, methods were called in wrong order. + } + } public void testTwoMethodsOnThread() throws Exception { |
From: Nobody <fas...@us...> - 2006-04-05 23:51:49
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19885/input/javasrc/biz/xsoftware/mock2 Added Files: ExpectFailedException.java Log Message: add test that should fail and passes --- NEW FILE: ExpectFailedException.java --- /* * Created on Apr 24, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package biz.xsoftware.mock2; /** * This Exception is thrown when something is expected to happen * and doesn't. It is basically the assert failing. When * MockSuperclass.expectEvent is called and the event doesn't come, * this exception is thrown. * * @author Dean Hiller */ public class ExpectFailedException extends RuntimeException { /** * */ private static final long serialVersionUID = 1L; /** * Expect failed because an event never came and waiting finally timed out. */ public static final String TIMED_OUT = "timed out waiting for method"; /** * Expect failed because a method you did not list in expected methods was called after * all your expected methods were called. */ public static final String UNEXPECTED_CALL_AFTER = "Another method that was not expected nor ignored was called after all the expected method calls"; /** * Expect failed because a method you did not list in expected methods was called * before or during the other methods you did expect. */ public static final String UNEXPECTED_CALL_BEFORE = "Another method that was not expected nor ignored was called before all the expected method calls were called"; /** * Expect failed because you expected no methods to be called, but a method was called. */ public static final String UNEXPECTED_ON_NONE = "Another method was called when no methods should have been called"; private String reason; private CalledMethod[] methods; /** * Constructor for Expects that fail with a reason and message. * * @param message */ public ExpectFailedException(String message, CalledMethod[] methods, String reason) { super(message); this.reason = reason; this.methods = methods; } /** * Gets the reason expecting the call(s) failed. * * Returns either * <ol> * <li>{@link #TIMED_OUT}</li> * <li>{@link #UNEXPECTED_CALL_AFTER}</li> * <li>{@link #UNEXPECTED_CALL_BEFORE}</li> * <li>{@link #UNEXPECTED_ON_NONE}</li> * </ol> * @return The reason for the failure. One of */ public String getReason() { return reason; } /** * Gives you back the CalledMethods giving you access to the * parameters that were passed in and the stack traces of how * they were called. * * @return */ public CalledMethod[] getCalledMethods() { return methods; } } |
From: Nobody <fas...@us...> - 2006-04-05 23:51:46
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19885/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: add test that should fail and passes Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** TestMockCreator.java 5 Apr 2006 15:27:12 -0000 1.15 --- TestMockCreator.java 5 Apr 2006 23:51:38 -0000 1.16 *************** *** 7,10 **** --- 7,11 ---- import junit.framework.TestCase; import biz.xsoftware.mock2.CalledMethod; + import biz.xsoftware.mock2.ExpectFailedException; import biz.xsoftware.mock2.Messages; import biz.xsoftware.mock2.MockObject; *************** *** 119,122 **** --- 120,145 ---- } + public void xxxtestTwoMethodsWrongOrder() throws Exception { + MockObject m = MockObjectFactory.createMock(ListenerOne.class); + ListenerOne l = (ListenerOne) m; + + String methodName1 = "callMeFirst"; + String methodName2 = "callMeSecond"; + m.expect(methodName1); + m.expect(methodName2); + + String param = "some params"; + l.callMeSecond(param); + int var1 = 4; + l.callMeFirst(var1); + + try { + m.verify(); + fail("Should have thrown exception and did not, methods were called in wrong order"); + } catch(ExpectFailedException e) { + //expect should fail, methods were called in wrong order. + } + } + public void testTwoMethodsOnThread() throws Exception { MockObject m = MockObjectFactory.createMock("5",ListenerOne.class); |
From: Jay <ja...@us...> - 2006-04-05 15:27:50
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12903/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectImpl.java MockObjectFactoryImpl.java MockObjectSuperImpl.java Log Message: add log to mocklib2 , add ID to mocklib2 , correct wait time to mocklib2 Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectImpl.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MockObjectImpl.java 21 Mar 2006 15:01:25 -0000 1.5 --- MockObjectImpl.java 5 Apr 2006 15:27:08 -0000 1.6 *************** *** 35,43 **** } } ! public MockObjectImpl(Class[] interfacesToMock) { this.classes=interfacesToMock; } ! public MockObjectImpl(Class interfaceToMock, Object realObject) { this.c=interfaceToMock; this.realObject=realObject; --- 35,45 ---- } } ! public MockObjectImpl(String id,Class[] interfacesToMock) { ! super(id); this.classes=interfacesToMock; } ! public MockObjectImpl( String id,Class interfaceToMock, Object realObject) { ! super(id); this.c=interfaceToMock; this.realObject=realObject; *************** *** 51,55 **** } Object o=methodCalledImpl(method.getName(),args); ! return o; } --- 53,57 ---- } 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.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MockObjectFactoryImpl.java 21 Mar 2006 09:25:32 -0000 1.4 --- MockObjectFactoryImpl.java 5 Apr 2006 15:27:08 -0000 1.5 *************** *** 8,12 **** public class MockObjectFactoryImpl extends MockObjectFactory { ! public MockObject createMockImpl(Class[] interfacesToMock) { Class[] interfacesPlusMock = new Class[interfacesToMock.length + 1]; interfacesPlusMock[0] = MockObject.class; --- 8,12 ---- public class MockObjectFactoryImpl extends MockObjectFactory { ! public MockObject createMockImpl( String id,Class[] interfacesToMock) { Class[] interfacesPlusMock = new Class[interfacesToMock.length + 1]; interfacesPlusMock[0] = MockObject.class; *************** *** 16,20 **** ClassLoader cl = MockObjectFactoryImpl.class.getClassLoader(); ! MockObjectImpl impl = new MockObjectImpl(interfacesToMock); Object o = Proxy.newProxyInstance(cl, interfacesPlusMock, impl); MockObject m = (MockObject) o; --- 16,20 ---- ClassLoader cl = MockObjectFactoryImpl.class.getClassLoader(); ! MockObjectImpl impl = new MockObjectImpl(id,interfacesToMock); Object o = Proxy.newProxyInstance(cl, interfacesPlusMock, impl); MockObject m = (MockObject) o; *************** *** 22,26 **** } ! public MockObject createMockImpl(Class interfaceToMock, Object realObject) { Class[] interfacePlusMock = new Class[1]; --- 22,26 ---- } ! public MockObject createMockImpl(String id,Class interfaceToMock, Object realObject) { Class[] interfacePlusMock = new Class[1]; *************** *** 28,32 **** ClassLoader cl = MockObjectFactoryImpl.class.getClassLoader(); ! MockObjectImpl impl = new MockObjectImpl(interfaceToMock, realObject); Object o = Proxy.newProxyInstance(cl, interfacePlusMock, impl); MockObject m = (MockObject) o; --- 28,32 ---- ClassLoader cl = MockObjectFactoryImpl.class.getClassLoader(); ! MockObjectImpl impl = new MockObjectImpl(id,interfaceToMock, realObject); Object o = Proxy.newProxyInstance(cl, interfacePlusMock, impl); MockObject m = (MockObject) o; Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** MockObjectSuperImpl.java 27 Mar 2006 15:44:31 -0000 1.11 --- MockObjectSuperImpl.java 5 Apr 2006 15:27:08 -0000 1.12 *************** *** 7,10 **** --- 7,12 ---- import java.util.List; import java.util.Map; + import java.util.logging.Logger; + import java.util.logging.Level; import biz.xsoftware.mock2.Behavior; *************** *** 20,24 **** public abstract class MockObjectSuperImpl implements MockObject { ! private static final long DEFAULT_TIME_OUT = 10000; --- 22,29 ---- public abstract class MockObjectSuperImpl implements MockObject { ! private static final Logger log=Logger.getLogger(MockObjectSuperImpl.class.getName()); ! ! private String id; ! private long delayTime=0; private static final long DEFAULT_TIME_OUT = 10000; *************** *** 59,63 **** ! public CalledMethod expect(String methodName, Class... vargs) { return expect(methodName, DEFAULT_TIME_OUT, vargs); } --- 64,72 ---- ! public MockObjectSuperImpl(String id) { ! this.id=id; ! } ! ! public CalledMethod expect(String methodName, Class... vargs) { return expect(methodName, DEFAULT_TIME_OUT, vargs); } *************** *** 83,89 **** --- 92,103 ---- if (methodName == null) throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); + delayTime=timeout; CalledMethod calledMethod = new CalledMethodImpl(methodName); if(!methodsIgnored.containsKey(methodName)) methodsExpected.add(calledMethod); + + if(log.isLoggable(Level.FINE)){ + log.log(Level.FINE,"ID="+id+" "+methodName+"is expected"); + } return calledMethod; } *************** *** 93,96 **** --- 107,111 ---- if (methodName == null) throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); + delayTime=timeout; CalledMethod calledMethod = new CalledMethodImpl(methodName); if(!methodsIgnored.containsKey(methodName)){ *************** *** 98,101 **** --- 113,119 ---- retVal.put(methodName, returnValue); } + if(log.isLoggable(Level.FINE)){ + log.log(Level.FINE,"ID="+id+" "+methodName+" is expected with return value="+returnValue.toString()); + } return calledMethod; } *************** *** 105,108 **** --- 123,127 ---- if (methodName == null) throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); + delayTime=timeout; CalledMethod calledMethod = new CalledMethodImpl(methodName); if(!methodsIgnored.containsKey(methodName)){ *************** *** 110,113 **** --- 129,137 ---- methodWithException.put(methodName, throwable); } + + if(log.isLoggable(Level.FINE)){ + log.log(Level.FINE,"ID="+id+" "+methodName+" is expected and expect this method to throw exception="+throwable.toString()); + } + return calledMethod; } *************** *** 117,125 **** if(methodName==null) 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 { --- 141,149 ---- if(methodName==null) throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); + delayTime=timeout; CalledMethod calledMethod=new CalledMethodImpl(methodName); if(!methodsIgnored.containsKey(methodName)){ methodsExpected.add(calledMethod); behaviorMap.put(methodName,behavior); try { *************** *** 134,137 **** --- 158,165 ---- } + if(log.isLoggable(Level.FINE)){ + log.log(Level.FINE,"ID="+id+" "+methodName+" is expected with behavior="+behavior.toString()); + } + return calledMethod; } *************** *** 142,149 **** if (methodsCalled.size() == 0) { synchronized (this) { - try { ! this.wait(DEFAULT_TIME_OUT); } catch (InterruptedException e) { e.getMessage(); --- 170,181 ---- if (methodsCalled.size() == 0) { + + if(log.isLoggable(Level.FINE)){ + log.log(Level.FINE,"called methods may be delayed,waitting methods to call..."); + } synchronized (this) { try { ! ! this.wait(delayTime); } catch (InterruptedException e) { e.getMessage(); *************** *** 182,188 **** } ! String stackTrace = "method Called=" + methodName + "(" + params ! + "on object" + this + ")"; ! CalledMethod calledMethod = new CalledMethodImpl(methodName, parameters, stackTrace); --- 214,223 ---- } ! String stackTrace = "method Called=" + methodName + ",params=" + params ! + " on object" + this + ")"; ! if(log.isLoggable(Level.FINE)){ ! ! log.log(Level.FINE,"ID="+id+" "+stackTrace); ! } CalledMethod calledMethod = new CalledMethodImpl(methodName, parameters, stackTrace); |
From: Jay <ja...@us...> - 2006-04-05 15:27:24
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12903/input/javasrc/biz/xsoftware/mock2 Modified Files: MockObjectFactory.java Log Message: add log to mocklib2 , add ID to mocklib2 , correct wait time to mocklib2 Index: MockObjectFactory.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/MockObjectFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MockObjectFactory.java 16 Feb 2006 15:37:35 -0000 1.5 --- MockObjectFactory.java 5 Apr 2006 15:27:14 -0000 1.6 *************** *** 29,46 **** } ! public static MockObject createMock(Class[] interfacesToMock) { ! return singleton().createMockImpl(interfacesToMock); } public static MockObject createMock(Class interfaceToMock) { ! return createMock(new Class[] { interfaceToMock }); } public static MockObject createMock(Class interfaceToMock, Object realObject) { ! return singleton().createMockImpl(interfaceToMock, realObject); } ! public abstract MockObject createMockImpl(Class[] interfacesToMock); ! public abstract MockObject createMockImpl(Class interfaceToMock, Object realObject); } --- 29,54 ---- } ! public static MockObject createMock(String id,Class[] interfacesToMock) { ! return singleton().createMockImpl(id,interfacesToMock); } + public static MockObject createMock( String id,Class interfaceToMock) { + return createMock(id,new Class[] {interfaceToMock }); + } + public static MockObject createMock(Class interfaceToMock) { ! return createMock("No ID Specified",new Class[] {interfaceToMock }); } + public static MockObject createMock(String id,Class interfaceToMock, Object realObject) { + return singleton().createMockImpl(id,interfaceToMock, realObject); + } + public static MockObject createMock(Class interfaceToMock, Object realObject) { ! return singleton().createMockImpl("No ID Specified",interfaceToMock, realObject); } ! public abstract MockObject createMockImpl(String id,Class[] interfacesToMock); ! public abstract MockObject createMockImpl(String id,Class interfaceToMock, Object realObject); } |
From: Jay <ja...@us...> - 2006-04-05 15:27:22
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12903/input/javasrc/biz/xsoftware/examples/mock2/basic Modified Files: TestExample.java Log Message: add log to mocklib2 , add ID to mocklib2 , correct wait time to mocklib2 Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic/TestExample.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TestExample.java 28 Mar 2006 15:25:02 -0000 1.3 --- TestExample.java 5 Apr 2006 15:27:14 -0000 1.4 *************** *** 20,24 **** public void setUp() { ! mockCreditSvc = MockObjectFactory.createMock(CreditAuthorizationSvc.class); mockGiftSvc = MockObjectFactory.createMock(GiftCardAccountSvc.class); --- 20,24 ---- public void setUp() { ! mockCreditSvc = MockObjectFactory.createMock("1",CreditAuthorizationSvc.class); mockGiftSvc = MockObjectFactory.createMock(GiftCardAccountSvc.class); |
From: Jay <ja...@us...> - 2006-04-05 15:27:22
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12903/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: add log to mocklib2 , add ID to mocklib2 , correct wait time to mocklib2 Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** TestMockCreator.java 27 Mar 2006 15:44:31 -0000 1.14 --- TestMockCreator.java 5 Apr 2006 15:27:12 -0000 1.15 *************** *** 24,28 **** public void testMockCreator() throws Exception { ! MockObject m = MockObjectFactory.createMock(ListenerOne.class); // ListenerOne l=(ListenerOne)m; --- 24,28 ---- public void testMockCreator() throws Exception { ! MockObject m = MockObjectFactory.createMock("1",ListenerOne.class); // ListenerOne l=(ListenerOne)m; *************** *** 48,52 **** public void testNoVerifyCalled() throws Exception { ! MockObject m = MockObjectFactory.createMock(ListenerOne.class); // ListenerOne l=(ListenerOne)m; String methodName1 = "callMeFirst"; --- 48,52 ---- public void testNoVerifyCalled() throws Exception { ! MockObject m = MockObjectFactory.createMock("2",ListenerOne.class); // ListenerOne l=(ListenerOne)m; String methodName1 = "callMeFirst"; *************** *** 66,70 **** public void testExpectWithRetVal() throws Exception { ! MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; --- 66,70 ---- public void testExpectWithRetVal() throws Exception { ! MockObject m = MockObjectFactory.createMock("3",ListenerOne.class); ListenerOne l = (ListenerOne) m; *************** *** 89,93 **** public void testTwoMethods() throws Exception { ! MockObject m = MockObjectFactory.createMock(ListenerOne.class); ListenerOne l = (ListenerOne) m; --- 89,93 ---- public void testTwoMethods() throws Exception { ! MockObject m = MockObjectFactory.createMock("4",ListenerOne.class); ListenerOne l = (ListenerOne) m; *************** *** 120,130 **** public void testTwoMethodsOnThread() throws Exception { ! MockObject m = MockObjectFactory.createMock(ListenerOne.class); final ListenerOne l = (ListenerOne) m; String methodName1 = "callMeFirst"; String methodName2 = "callMeSecond"; ! CalledMethod callMeFirst = m.expect(methodName1); ! CalledMethod callMeSecond = m.expect(methodName2); final int var1 = 4; --- 120,130 ---- public void testTwoMethodsOnThread() throws Exception { ! MockObject m = MockObjectFactory.createMock("5",ListenerOne.class); final ListenerOne l = (ListenerOne) m; String methodName1 = "callMeFirst"; String methodName2 = "callMeSecond"; ! CalledMethod callMeFirst = m.expect(methodName1,4000); ! CalledMethod callMeSecond = m.expect(methodName2,4000); final int var1 = 4; *************** *** 133,137 **** public void run() { try { ! Thread.sleep(1000); l.callMeFirst(var1); l.callMeSecond(param); --- 133,137 ---- public void run() { try { ! Thread.sleep(3000); l.callMeFirst(var1); l.callMeSecond(param); |
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/advanced In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9237/input/javasrc/biz/xsoftware/examples/mock2/advanced Added Files: TestExample.java SysUnderTest.java Location.java User.java TaskRecordService.java TaskSystem.java Log Message: check in due to finished advanced test --- NEW FILE: TaskSystem.java --- /* * Created on Jul 15, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package biz.xsoftware.examples.mock2.advanced; import biz.xsoftware.examples.timer.ScheduleListener; /** * * @author Dean Hiller */ public interface TaskSystem { public void addScheduleListener(ScheduleListener l); public void removeScheduleListener(ScheduleListener l); } --- NEW FILE: TestExample.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.examples.mock2.advanced; import junit.framework.TestCase; import biz.xsoftware.examples.timer.ScheduleListener; import biz.xsoftware.mock2.CalledMethod; import biz.xsoftware.mock2.MockObjectFactory; import biz.xsoftware.mock2.MockObject; /** * JUnit Suite of TestCases for demonstrating mocking out a more * complex api. * * @author Dean Hiller */ public class TestExample extends TestCase { private SysUnderTest sysUnderTest; private MockObject mockTaskSvc; private MockObject mockRecord; /** * @showcode */ public TestExample(String name) { super(name); } /** * @showcode */ public void setUp() { mockTaskSvc = MockObjectFactory.createMock(TaskSystem.class); mockRecord = MockObjectFactory.createMock(TaskRecordService.class); sysUnderTest = new SysUnderTest((TaskRecordService)mockRecord, (TaskSystem)mockTaskSvc); } /** * Some api's can be more OO oriented then others and have no * one facade into the whole subsystem as it may be too large, * so this demonstrates how even those api's can be mocked out. * * This also demonstrates a susbystem that relies on two subsystems * such that you can trigger an event in one subsystem and test * the interaction with the other subsystem. * * @showcode */ public void testSystemInteractionWithSubsytemsAPI() { String expectedName = "joe"; String expectedTask = "printpaper"; CalledMethod addScheduleListener=mockTaskSvc.expect("addScheduleListener"); sysUnderTest.sendUserMailWhenTaskStarted(expectedName, expectedTask); mockTaskSvc.verify(); Object o =addScheduleListener.getParameters()[0]; ScheduleListener l = (ScheduleListener)o; //set an object to return from mockRecord as we know we are testing //that a call to getUser results from an event MockObject mockUser = MockObjectFactory.createMock(User.class); CalledMethod getUser=mockRecord.expect("getUser"); CalledMethod addTaskDone=mockUser.expect("addTaskDone"); mockRecord.setDefaultReturnValue( mockUser,"getUser"); //have mockTaskSvc fire an event that should cause sysUnderTest //to interact with mockMessaging l.eventStarted(null); mockRecord.verify(); mockUser.verify(); String actualUserId = (String)getUser.getParameters()[0]; assertEquals("User id was incorrect", expectedName, actualUserId); String actualTask = (String)addTaskDone.getParameters()[0]; assertEquals("task name was incorrect", expectedTask, actualTask); } } --- 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.examples.mock2.advanced; import biz.xsoftware.examples.timer.ScheduleListener; /** * The SysUnderTest here is a WebStore or something which needs * to authorize purchases. */ public class SysUnderTest { private TaskRecordService msgSystem; private TaskSystem taskSystem; /** * @showcode */ public SysUnderTest(TaskRecordService msgSystem, TaskSystem t) { this.msgSystem = msgSystem; this.taskSystem = t; } /** * @showcode */ public void sendUserMailWhenTaskStarted(String id, String taskName) { taskSystem.addScheduleListener(new TaskStartedListener(id, taskName)); } private class TaskStartedListener implements ScheduleListener { private String name; private String userId; /** * @showcode */ public TaskStartedListener(String userId, String name) { this.name = name; this.userId = userId; } /** * @showcode * @see biz.xsoftware.examples.timer.ScheduleListener#eventStarted(java.lang.String) */ public void eventStarted(String title) { User u = msgSystem.getUser(userId); u.addTaskDone(name); } } } --- NEW FILE: TaskRecordService.java --- /* * Created on Jul 15, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package biz.xsoftware.examples.mock2.advanced; /** * @author Dean Hiller * * To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */ public interface TaskRecordService { public User getUser(String id); } --- NEW FILE: User.java --- /* * Created on Jul 15, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package biz.xsoftware.examples.mock2.advanced; /** * An interface defining the more complex api we are mocking out. * * @author Dean Hiller */ public interface User { public String addTaskDone(String taskName); } --- NEW FILE: Location.java --- /* * Created on Jul 15, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package biz.xsoftware.examples.mock2.advanced; /** * @author Dean Hiller * * To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */ public interface Location { public String getOfficeNumber(); public String getStreet(); public String getStreetNumber(); public String getZipCode(); } |
From: Jay <ja...@us...> - 2006-03-28 15:50:01
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/advanced In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9034/input/javasrc/biz/xsoftware/examples/mock2/advanced Log Message: Directory /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/advanced added to the repository |
From: Jay <ja...@us...> - 2006-03-28 15:25:13
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28267/input/javasrc/biz/xsoftware/examples/mock2/basic Modified Files: TestExample.java Log Message: check in due to check style failure Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic/TestExample.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TestExample.java 28 Mar 2006 15:08:04 -0000 1.2 --- TestExample.java 28 Mar 2006 15:25:02 -0000 1.3 *************** *** 2,6 **** import junit.framework.TestCase; - import biz.xsoftware.examples.mock2.basic.PurchaseException; import biz.xsoftware.mock2.CalledMethod; import biz.xsoftware.mock2.MockObject; --- 2,5 ---- |
From: Jay <ja...@us...> - 2006-03-28 15:08:15
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18686/input/javasrc/biz/xsoftware/examples/mock2/basic Modified Files: TestExample.java Log Message: finished basic test for using mocklib2 Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic/TestExample.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestExample.java 28 Mar 2006 00:38:15 -0000 1.1 --- TestExample.java 28 Mar 2006 15:08:04 -0000 1.2 *************** *** 2,9 **** 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; --- 2,14 ---- import junit.framework.TestCase; + import biz.xsoftware.examples.mock2.basic.PurchaseException; import biz.xsoftware.mock2.CalledMethod; import biz.xsoftware.mock2.MockObject; import biz.xsoftware.mock2.MockObjectFactory; ! /** ! * basic test for using mocklib version 2 ! * @author Jay ! * ! */ public class TestExample extends TestCase{ private SysUnderTest sysUnderTest; *************** *** 35,37 **** --- 40,78 ---- assertEquals("Amount should have been the same", new Double(amount), authorize.getParameters()[1]); } + + public void testFailureOfAuthorization() { + String user = "user1"; + double amount = 340.99; + mockCreditSvc.expect("authorize",new RuntimeException("authorize failed!!!")); + try { + sysUnderTest.purchase("itemA", user, amount); + fail(" test failed due to the exception is not correctly been caught"); + } catch(PurchaseException e) {} + + mockCreditSvc.verify(); + } + + public void testFailureOfBuyingGiftCard() { + + mockGiftSvc.expect("putMoneyOnCard",new RuntimeException("system crashed!!!")); + String[] calls = new String[2]; + calls[0] = "takeMoney"; + calls[1] = "returnMoney"; + CalledMethod takeMoney= mockCreditSvc.expect(calls[0]); + CalledMethod returnMoney=mockCreditSvc.expect(calls[1]); + + String user = "userXXX"; + double amount = 40.01; + try { + sysUnderTest.buyGiftCard(user, amount); + fail("Should have thrown exception"); + } catch(PurchaseException e) {} + + mockCreditSvc.verify(); + + assertEquals("Took from correct user", user, takeMoney.getParameters()[0]); + assertEquals("Took 40 dollars", new Double(amount), takeMoney.getParameters()[1]); + assertEquals("Gave money back to correct user", user, returnMoney.getParameters()[0]); + assertEquals("amount put back on card is correct", new Double(amount), returnMoney.getParameters()[1]); + } } |
From: Nobody <fas...@us...> - 2006-03-28 11:12:59
|
Update of /cvsroot/mocklib/mocklib2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11455 Removed Files: tmp Log Message: delete tmp from repository. --- tmp DELETED --- |
From: Jay <ja...@us...> - 2006-03-28 02:52:53
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5423/input/javasrc/biz/xsoftware/test/mock2 Modified Files: FakeSystem.java Log Message: Index: FakeSystem.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/FakeSystem.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FakeSystem.java 28 Mar 2006 01:32:19 -0000 1.6 --- FakeSystem.java 28 Mar 2006 02:52:49 -0000 1.7 *************** *** 12,16 **** public FakeSystem() { ! // TODO Auto-generated constructor stub } --- 12,16 ---- public FakeSystem() { ! System.out.println("Hello world"); } |
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/example1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16224/input/javasrc/biz/xsoftware/mock2/example1 Removed Files: PurchaseException.java SysUnderTest.java CreditAuthorizationSvc.java TestExample.java GiftCardAccountSvc.java Log Message: delete mock2/example . --- PurchaseException.java DELETED --- --- GiftCardAccountSvc.java DELETED --- --- TestExample.java DELETED --- --- CreditAuthorizationSvc.java DELETED --- --- SysUnderTest.java DELETED --- |
From: Jay <ja...@us...> - 2006-03-28 01:32:40
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31115/input/javasrc/biz/xsoftware/test/mock2 Modified Files: FakeSystem.java Log Message: Index: FakeSystem.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/FakeSystem.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FakeSystem.java 25 Mar 2006 08:17:25 -0000 1.5 --- FakeSystem.java 28 Mar 2006 01:32:19 -0000 1.6 *************** *** 11,14 **** --- 11,18 ---- } + public FakeSystem() { + // TODO Auto-generated constructor stub + } + public int runSystem(byte[] data) { int retVal = list.write(data); |
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5534/input/javasrc/biz/xsoftware/examples/mock2/basic Added Files: TestExample.java SysUnderTest.java CreditAuthorizationSvc.java PurchaseException.java GiftCardAccountSvc.java Log Message: change test package and design.xml to follow the design --- 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.examples.mock2.basic; /** * 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.examples.mock2.basic; /** * 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.examples.mock2.basic; 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.examples.mock2.basic; /** * 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.examples.mock2.basic; /** * 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-28 00:38:22
|
Update of /cvsroot/mocklib/mocklib2/bldfiles In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5534/bldfiles Modified Files: design.xml Log Message: change test package and design.xml to follow the design Index: design.xml =================================================================== RCS file: /cvsroot/mocklib/mocklib2/bldfiles/design.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** design.xml 16 Feb 2006 15:37:35 -0000 1.4 --- design.xml 28 Mar 2006 00:38:16 -0000 1.5 *************** *** 18,21 **** --- 18,24 ---- <depends>junit</depends> </package> + + <package name="api2" package="biz.xsoftware.mock2"/> + <package name="testapi" package="biz.xsoftware.test.mock" subpackages="include"> <depends>apiAndImpl</depends> *************** *** 24,31 **** <package name="examples" package="biz.xsoftware.examples" subpackages="include"> <depends>apiAndImpl</depends> <depends>junit</depends> </package> ! <package name="api2" package="biz.xsoftware.mock2"/> <package name="impl2" package="biz.xsoftware.mock2.impl"> <depends>api2</depends> --- 27,35 ---- <package name="examples" package="biz.xsoftware.examples" subpackages="include"> <depends>apiAndImpl</depends> + <depends>api2</depends> <depends>junit</depends> </package> ! <package name="impl2" package="biz.xsoftware.mock2.impl"> <depends>api2</depends> |
From: Jay <ja...@us...> - 2006-03-28 00:38:10
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5487/input/javasrc/biz/xsoftware/examples/mock2 Log Message: Directory /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2 added to the repository |
From: Jay <ja...@us...> - 2006-03-28 00:38:10
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5487/input/javasrc/biz/xsoftware/examples/mock2/basic Log Message: Directory /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic added to the repository |
From: Jay <ja...@us...> - 2006-03-27 15:44:46
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22874/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TestMockCreator.java 25 Mar 2006 08:17:25 -0000 1.13 --- TestMockCreator.java 27 Mar 2006 15:44:31 -0000 1.14 *************** *** 258,262 **** } ! public void testIgnoreMethod(){ MockObject m=MockObjectFactory.createMock(ListenerOne.class); ListenerOne l=(ListenerOne)m; --- 258,262 ---- } ! public void testIgnoreAndDefaultRetValMethod(){ MockObject m=MockObjectFactory.createMock(ListenerOne.class); ListenerOne l=(ListenerOne)m; *************** *** 269,304 **** 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) { --- 269,300 ---- + + CalledMethod callMeFirst=m.expect(methodName1); m.addIgnoreMethod(methodName1); ! m.setDefaultReturnValue("retval",methodName1); CalledMethod callMeLast=m.expect(methodName2); + CalledMethod callAgain=m.expect(methodName1); m.removeIgnoreMethod(methodName1); ! CalledMethod callLastAgain=m.expect(methodName2); ! CalledMethod callThirdTime=m.expect(methodName1); l.callMeFirst(param1); l.callMeLast(param2); l.callMeFirst(param1); ! l.callMeLast(param2); ! l.callMeFirst(param1); ! m.verify(); + ! ! } ! ! ! // private static byte[] cloneBytes(byte[] data) { |