mocklib-checkins Mailing List for mocklib (Page 16)
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: dadrox <da...@us...> - 2006-08-07 15:52:58
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/advanced In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/input/javasrc/biz/xsoftware/examples/mock2/advanced Modified Files: TestExample.java Log Message: fixed a bug in ignore... ported the examples Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/advanced/TestExample.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TestExample.java 5 May 2006 15:29:23 -0000 1.2 --- TestExample.java 7 Aug 2006 15:52:45 -0000 1.3 *************** *** 35,39 **** * @showcode */ ! public void setUp() { mockTaskSvc = MockObjectFactory.createMock(TaskSystem.class); mockRecord = MockObjectFactory.createMock(TaskRecordService.class); --- 35,40 ---- * @showcode */ ! @Override ! public void setUp() { mockTaskSvc = MockObjectFactory.createMock(TaskSystem.class); mockRecord = MockObjectFactory.createMock(TaskRecordService.class); |
From: dadrox <da...@us...> - 2006-08-07 15:52:52
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/timer2 In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/input/javasrc/biz/xsoftware/examples/timer2 Modified Files: SysUnderTest.java TestExample.java Log Message: fixed a bug in ignore... ported the examples Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/timer2/TestExample.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestExample.java 26 Jun 2005 12:19:52 -0000 1.1 --- TestExample.java 7 Aug 2006 15:52:45 -0000 1.2 *************** *** 36,40 **** * @showcode */ ! public void setUp() { mockTimer = MockObjectFactory.createMock(TimerInterface.class); calendar = new SysUnderTest((TimerInterface) mockTimer); --- 36,41 ---- * @showcode */ ! @Override ! public void setUp() { mockTimer = MockObjectFactory.createMock(TimerInterface.class); calendar = new SysUnderTest((TimerInterface) mockTimer); *************** *** 45,49 **** * @showcode */ ! public void tearDown() { calendar.removeScheduleListener((ScheduleListener)mockListener); } --- 46,51 ---- * @showcode */ ! @Override ! public void tearDown() { calendar.removeScheduleListener((ScheduleListener)mockListener); } *************** *** 56,60 **** calendar.addEvent(title, delay); ! CalledMethod method = mockTimer.expectCall("schedule"); //param[0] is a timer task TimerTask task = (TimerTask)method.getParameter(0); --- 58,62 ---- calendar.addEvent(title, delay); ! CalledMethod method = mockTimer.expect("schedule"); //param[0] is a timer task TimerTask task = (TimerTask)method.getParameter(0); *************** *** 64,68 **** task.run(); ! method = mockListener.expectCall("eventStarted"); assertEquals("title should be the same", title, method.getParameter(0)); } --- 66,70 ---- task.run(); ! method = mockListener.expect("eventStarted"); assertEquals("title should be the same", title, method.getParameter(0)); } Index: SysUnderTest.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/timer2/SysUnderTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SysUnderTest.java 26 Jun 2005 12:19:52 -0000 1.1 --- SysUnderTest.java 7 Aug 2006 15:52:45 -0000 1.2 *************** *** 57,61 **** * @showcode */ ! public void run() { fireEventStarted(title); } --- 57,62 ---- * @showcode */ ! @Override ! public void run() { fireEventStarted(title); } |
From: dadrox <da...@us...> - 2006-08-07 15:52:52
|
Update of /cvsroot/mocklib/mocklib2/bldfiles In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/bldfiles Modified Files: release.xml Log Message: fixed a bug in ignore... ported the examples Index: release.xml =================================================================== RCS file: /cvsroot/mocklib/mocklib2/bldfiles/release.xml,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** release.xml 4 Aug 2006 16:23:24 -0000 1.5 --- release.xml 7 Aug 2006 15:52:46 -0000 1.6 *************** *** 2,6 **** move the distribution built in createdist.xml and code coverage web pages anywhere you want after the build is done --> ! <project name="std_buildfile" default="createdist" basedir=".."> <property name="misc" value="${input}/misc"/> --- 2,6 ---- move the distribution built in createdist.xml and code coverage web pages anywhere you want after the build is done --> ! <project name="std_buildfile" default="release" basedir=".."> <property name="misc" value="${input}/misc"/> *************** *** 106,110 **** <zip zipfile="${dist}/${name}-${version}.zip" basedir="${staging}" includes="**" update="yes" /> <!--tar tarfile="${dist.dir}/${name}-${version}.tar" basedir="${dist.build.dir}" includes="**" /> ! <gzip zipfile="${dist.dir}/${name}-${version}.tar.gz" src="${dist.dir}/${name}-${version}.tar" /--> </target> --- 106,117 ---- <zip zipfile="${dist}/${name}-${version}.zip" basedir="${staging}" includes="**" update="yes" /> <!--tar tarfile="${dist.dir}/${name}-${version}.tar" basedir="${dist.build.dir}" includes="**" /> ! <gzip zipfile="${dist.dir}/${name}-${version}.tar.gz" src="${dist.dir}/${name}-${version}.tar" /--> ! ! <copy tofile="${dist}/${name}-${version}.jar"> ! <fileset dir="${jardist}"> ! <include name="${jar.name}"/> ! </fileset> ! </copy> ! </target> *************** *** 128,134 **** --- 135,145 ---- remotedir="incoming" userid="anonymous" + passive="true" + binary="true" + verbose="true" password="${user}@user.sourceforge.net"> <fileset dir="${dist}"> <include name="${name}-${version}.zip"/> + <include name="${name}-${version}.jar"/> </fileset> </ftp> |
From: dadrox <da...@us...> - 2006-08-07 15:52:51
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectSuperImpl.java Log Message: fixed a bug in ignore... ported the examples Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** MockObjectSuperImpl.java 5 May 2006 15:29:23 -0000 1.15 --- MockObjectSuperImpl.java 7 Aug 2006 15:52:45 -0000 1.16 *************** *** 348,352 **** { throw new RuntimeException("You must specify a return value for " + ! "ignored or expected method " + methodName + "()"); } else if(returnType != Void.TYPE && ret != null && (ret.getClass().isPrimitive() || returnType.isPrimitive())) --- 348,352 ---- { throw new RuntimeException("You must specify a return value for " + ! "ignored or expected method " + returnType + " " + methodName + "()"); } else if(returnType != Void.TYPE && ret != null && (ret.getClass().isPrimitive() || returnType.isPrimitive())) |
From: dadrox <da...@us...> - 2006-08-07 15:52:50
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/input/javasrc/biz/xsoftware/mock Modified Files: MockSuperclass.java CalledMethod.java MockObjectImpl.java Behavior.java Log Message: fixed a bug in ignore... ported the examples Index: Behavior.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/Behavior.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Behavior.java 10 Jun 2006 12:41:03 -0000 1.1 --- Behavior.java 7 Aug 2006 15:52:45 -0000 1.2 *************** *** 16,20 **** * * @param params - * @return */ public Object runMethod(Object[] params); --- 16,19 ---- Index: MockSuperclass.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockSuperclass.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** MockSuperclass.java 4 Aug 2006 16:20:52 -0000 1.9 --- MockSuperclass.java 7 Aug 2006 15:52:45 -0000 1.10 *************** *** 121,129 **** public void ignore(String method) { ! ignore(method); } public void ignore(String ... methods) { setIgnoredMethods(methods); } --- 121,134 ---- public void ignore(String method) { ! ignoreImpl(new String[] {method}); } public void ignore(String ... methods) { + ignoreImpl(methods); + } + + private void ignoreImpl(String[] methods) + { setIgnoredMethods(methods); } *************** *** 293,297 **** */ public CalledMethod expectCall(String method) { ! return expect(new String[] {method})[0]; } --- 298,302 ---- */ public CalledMethod expectCall(String method) { ! return expectImpl(new String[] {method})[0]; } *************** *** 300,304 **** */ public CalledMethod expect(String method) { ! return expect(new String[] {method})[0]; } --- 305,309 ---- */ public CalledMethod expect(String method) { ! return expectImpl(new String[] {method})[0]; } *************** *** 308,311 **** --- 313,321 ---- public synchronized CalledMethod[] expect(String ... methods) { + return expectImpl(methods); + } + + private synchronized CalledMethod[] expectImpl(String[] methods) + { return expectOrderedCalls(methods); } Index: CalledMethod.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/CalledMethod.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CalledMethod.java 26 Jun 2005 12:20:14 -0000 1.1 --- CalledMethod.java 7 Aug 2006 15:52:45 -0000 1.2 *************** *** 44,48 **** /** * - * @return */ public Object[] getAllParams() { --- 44,47 ---- *************** *** 53,57 **** return howItWasCalled; } ! public String toString() { List paramList = null; if(params != null) --- 52,57 ---- return howItWasCalled; } ! @Override ! public String toString() { List paramList = null; if(params != null) Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObjectImpl.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MockObjectImpl.java 4 Aug 2006 16:20:52 -0000 1.7 --- MockObjectImpl.java 7 Aug 2006 15:52:45 -0000 1.8 *************** *** 48,61 **** 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; } /** * --- 48,136 ---- Object o = methodCalledImpl(method.getName(), args); ! ! Class returnType = method.getReturnType(); ! if(o == null) { ! if(returnType == null || void.class != returnType) ! { ! String methodArgs = ""; ! Class<?>[] parameterTypes = method.getParameterTypes(); ! for(int ii = 0; ii < parameterTypes.length; ii++) ! { ! Class arg = method.getParameterTypes()[ii]; ! methodArgs += arg.getName(); ! if(ii < parameterTypes.length -1) ! methodArgs += ", "; ! } ! throw new RuntimeException("\nYou must specify a return value of type " + ! returnType.getCanonicalName() + ! " for ignored or expected method:\n" + ! " " + method.getName() + "(" + methodArgs + ")"); ! } ! else if(!Object.class.isAssignableFrom(returnType) && !"void".equals(returnType.getName())) { throw new RuntimeException("Must call addReturnValue and " + "specify a non-null value as method="+method.getName()+" returns a primitive value"); } } + else if(returnType != Void.TYPE && (o.getClass().isPrimitive() || returnType.isPrimitive())) + { + handlePrimitiveReturns(method.getName(), o, returnType); + } + else if(o instanceof MockObject) {} + else if(o.getClass() != returnType)// && !returnType.isPrimitive()) + { + throwTypeException(method.getName(), o, o.getClass().getName(), returnType.getName()); + } return o; } + + + private void handlePrimitiveReturns(String methodName, Object ret, Class<?> expectedReturnType) + { + Class<?>[] primitiveTypes = {Integer.TYPE, Double.TYPE, Float.TYPE, Boolean.TYPE, + Character.TYPE, Byte.TYPE, Short.TYPE, Long.TYPE}; + Object[] primitiveClasses = {Integer.class, Double.class, Float.class, Boolean.class, + Character.class, Byte.class, Short.class, Long.class}; + if(ret.getClass().isPrimitive() && expectedReturnType.isPrimitive()) + { + for(Class<?> currentType : primitiveTypes) + { + if(ret.getClass() == currentType && expectedReturnType != currentType) + { + throwTypeException(methodName, ret, ret.getClass().getName(), expectedReturnType.getName()); + } + } + } + else if(ret.getClass().isPrimitive()) + { + for(int ii = 0; ii < primitiveTypes.length; ii++) + { + if(ret.getClass() == primitiveTypes[ii] && expectedReturnType != primitiveClasses[ii]) + { + throwTypeException(methodName, ret, ret.getClass().getName(), expectedReturnType.getName()); + } + } + } + else + { + for(int ii = 0; ii < primitiveTypes.length; ii++) + { + if(expectedReturnType == primitiveTypes[ii] && ret.getClass() != primitiveClasses[ii]) + { + throwTypeException(methodName, ret, ret.getClass().getName(), expectedReturnType.getName()); + } + } + } + } + + private void throwTypeException(String methodName, Object returnValue, + String returnType, String expectedReturnType) + { + throw new RuntimeException("You specified an incorrect return type for " + + "ignored or expected method " + methodName + "()" + + "\nYou specified: \"" + returnValue + "\" of type " + + returnType + " but should have been of type " + expectedReturnType); + } + /** * *************** *** 64,68 **** * @param m This is the method that was invoked * @param args These are the arguments that were passed to the method - * @return * @throws Throwable */ --- 139,142 ---- *************** *** 78,83 **** if(e.getCause() != null) throw e.getCause(); ! else ! throw e; } } --- 152,156 ---- if(e.getCause() != null) throw e.getCause(); ! throw e; } } *************** *** 85,89 **** * @see biz.xsoftware.mock.MockSuperclass#getClasses() */ ! public Class[] getClasses() { return classes; } --- 158,163 ---- * @see biz.xsoftware.mock.MockSuperclass#getClasses() */ ! @Override ! public Class[] getClasses() { return classes; } |
From: dadrox <da...@us...> - 2006-08-07 15:52:49
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/listener In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/input/javasrc/biz/xsoftware/examples/listener Modified Files: TestExample.java Log Message: fixed a bug in ignore... ported the examples Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/listener/TestExample.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestExample.java 26 Jun 2005 12:02:25 -0000 1.1 --- TestExample.java 7 Aug 2006 15:52:45 -0000 1.2 *************** *** 34,38 **** * @showcode */ ! public void setUp() { mockLegacy = MockObjectFactory.createMock(LegacySystem.class); mockListener1 = MockObjectFactory.createMock(LegacySystemListener.class); --- 34,39 ---- * @showcode */ ! @Override ! public void setUp() { mockLegacy = MockObjectFactory.createMock(LegacySystem.class); mockListener1 = MockObjectFactory.createMock(LegacySystemListener.class); *************** *** 40,47 **** sysUnderTest = new SysUnderTest((LegacySystem)mockLegacy); ! Object[] params = mockLegacy.expectCall("setLegacyListener").getAllParams(); legacyListener = (LegacySystemListener)params[0]; } ! public void tearDown() { } --- 41,49 ---- sysUnderTest = new SysUnderTest((LegacySystem)mockLegacy); ! Object[] params = mockLegacy.expect("setLegacyListener").getAllParams(); legacyListener = (LegacySystemListener)params[0]; } ! @Override ! public void tearDown() { } *************** *** 66,71 **** legacyListener.legacyEventOccurred(5); ! mockListener1.expectCall("legacyEventOccurred"); ! mockListener2.expectCall("legacyEventOccurred"); } --- 68,73 ---- legacyListener.legacyEventOccurred(5); ! mockListener1.expect("legacyEventOccurred"); ! mockListener2.expect("legacyEventOccurred"); } |
From: dadrox <da...@us...> - 2006-08-07 15:52:49
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/input/javasrc/biz/xsoftware/test/mock Modified Files: TestOrderedCalls.java TestMockCreator.java Log Message: fixed a bug in ignore... ported the examples Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TestMockCreator.java 10 Jun 2006 12:54:36 -0000 1.3 --- TestMockCreator.java 7 Aug 2006 15:52:45 -0000 1.4 *************** *** 19,25 **** /** * @author Dean Hiller - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ public class TestMockCreator extends TestCase { --- 19,22 ---- *************** *** 41,45 **** String methodName = "callMeSecond"; ! CalledMethod method = m.expectCall(methodName); assertEquals("method name should be the same", methodName, method.getMethodName()); --- 38,42 ---- String methodName = "callMeSecond"; ! CalledMethod method = m.expect(methodName); assertEquals("method name should be the same", methodName, method.getMethodName()); *************** *** 65,69 **** try { ! m.expectCall(MockObject.NONE); fail("Should have failed with ExpectFailedException"); } catch(ExpectFailedException e) { --- 62,66 ---- try { ! m.expect(MockObject.NONE); fail("Should have failed with ExpectFailedException"); } catch(ExpectFailedException e) { *************** *** 79,83 **** l.multipleParams(param1, param2); ! CalledMethod method = m.expectCall("multipleParams"); assertEquals("param1 is not correct", param1, method.getParameter(0)); assertEquals("param2 is not correct", param2, method.getParameter(1)); --- 76,80 ---- l.multipleParams(param1, param2); ! CalledMethod method = m.expect("multipleParams"); assertEquals("param1 is not correct", param1, method.getParameter(0)); assertEquals("param2 is not correct", param2, method.getParameter(1)); *************** *** 89,93 **** l.callMeSecond("dummy"); try { ! m.expectCall("callMeFirst"); fail("should have thrown exception"); } catch(ExpectFailedException e) {} --- 86,90 ---- l.callMeSecond("dummy"); try { ! m.expect("callMeFirst"); fail("should have thrown exception"); } catch(ExpectFailedException e) {} *************** *** 103,110 **** //would call createcar but we are only unit testing MockCreator Car c = ((FactoryInterface)factory).createCar("someid"); ! factory.expectCall("createCar"); c.openDoor(); ! car.expectCall("openDoor"); } --- 100,107 ---- //would call createcar but we are only unit testing MockCreator Car c = ((FactoryInterface)factory).createCar("someid"); ! factory.expect("createCar"); c.openDoor(); ! car.expect("openDoor"); } *************** *** 127,131 **** l.callMeFirst(expected); ! CalledMethod m = mockList.expectCall(MockObject.ANY); Integer i = (Integer)m.getAllParams()[0]; assertEquals("param should be 1", new Integer(expected), i); --- 124,128 ---- l.callMeFirst(expected); ! CalledMethod m = mockList.expect(MockObject.ANY); Integer i = (Integer)m.getAllParams()[0]; assertEquals("param should be 1", new Integer(expected), i); *************** *** 140,144 **** String[] methods = new String[] { MockObject.ANY, "callMeSecond" }; ! mockList.expectOrderedCalls(methods); } --- 137,141 ---- String[] methods = new String[] { MockObject.ANY, "callMeSecond" }; ! mockList.expect(methods); } *************** *** 147,151 **** try { ! mock.expectCall("noSuchMethod"); fail("This should throw an exception"); } catch(IllegalArgumentException e) { --- 144,148 ---- try { ! mock.expect("noSuchMethod"); fail("This should throw an exception"); } catch(IllegalArgumentException e) { *************** *** 161,165 **** byte[] retVal = ident.doThat(null); ! mock.expectCall("doThat"); assertEquals(1, retVal.length); --- 158,162 ---- byte[] retVal = ident.doThat(null); ! mock.expect("doThat"); assertEquals(1, retVal.length); *************** *** 179,183 **** byte[] newBytes = ident.doThat(bytes); ! CalledMethod m = mock.expectCall("doThat"); byte[] passedIn = (byte[])m.getAllParams()[0]; --- 176,180 ---- byte[] newBytes = ident.doThat(bytes); ! CalledMethod m = mock.expect("doThat"); byte[] passedIn = (byte[])m.getAllParams()[0]; *************** *** 212,219 **** } - /** - * @param bs - * @return - */ private Object cloneBytes(byte[] bytes) { --- 209,212 ---- Index: TestOrderedCalls.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestOrderedCalls.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestOrderedCalls.java 1 Jan 2006 00:35:56 -0000 1.1 --- TestOrderedCalls.java 7 Aug 2006 15:52:45 -0000 1.2 *************** *** 38,42 **** final MockOne one = new MockOne(3000); Thread r = new Thread() { ! public void run() { delay(1000); one.callMeFirst(4); --- 38,43 ---- final MockOne one = new MockOne(3000); Thread r = new Thread() { ! @Override ! public void run() { delay(1000); one.callMeFirst(4); *************** *** 59,63 **** final MockOne one = new MockOne(3000); Thread r = new Thread() { ! public void run() { delay(1000); one.callMeFirst(4); --- 60,65 ---- final MockOne one = new MockOne(3000); Thread r = new Thread() { ! @Override ! public void run() { delay(1000); one.callMeFirst(4); *************** *** 86,90 **** final MockOne one = new MockOne(3000); Thread r = new Thread() { ! public void run() { delay(1000); one.callMeFirst(14); --- 88,93 ---- final MockOne one = new MockOne(3000); Thread r = new Thread() { ! @Override ! public void run() { delay(1000); one.callMeFirst(14); |
From: dadrox <da...@us...> - 2006-08-07 15:52:49
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/manifest In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/input/javasrc/biz/xsoftware/manifest Modified Files: TestManifestInfo.java ManifestInfo.java Log Message: fixed a bug in ignore... ported the examples Index: TestManifestInfo.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/manifest/TestManifestInfo.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TestManifestInfo.java 19 Feb 2006 19:20:51 -0000 1.2 --- TestManifestInfo.java 7 Aug 2006 15:52:45 -0000 1.3 *************** *** 29,33 **** super(arg0); } ! public void setUp() { String jarLoc = System.getProperty("jar.name"); if(jarLoc != null) //for tests run from ant --- 29,34 ---- super(arg0); } ! @Override ! public void setUp() { String jarLoc = System.getProperty("jar.name"); if(jarLoc != null) //for tests run from ant Index: ManifestInfo.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/manifest/ManifestInfo.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ManifestInfo.java 27 Jun 2005 03:40:35 -0000 1.1 --- ManifestInfo.java 7 Aug 2006 15:52:45 -0000 1.2 *************** *** 124,128 **** * from out of the manifest. Uses the class's package to retrieve * the manifest version info. - * @param c The Class on whose package to use to get version info. */ public ManifestInfo() throws IOException { --- 124,127 ---- *************** *** 171,175 **** * @see java.lang.Object#toString() */ ! public String toString() { String manifestInfo = "\nManifest information...\n"; --- 170,175 ---- * @see java.lang.Object#toString() */ ! @Override ! public String toString() { String manifestInfo = "\nManifest information...\n"; *************** *** 188,196 **** public interface ManifestUtil { public File getFile(URL url); ! /** ! * @param manifest ! * @return ! */ ! public String getMainClass(Manifest manifest); public void exit(int code); --- 188,193 ---- public interface ManifestUtil { public File getFile(URL url); ! ! public String getMainClass(Manifest manifest); public void exit(int code); |
From: dadrox <da...@us...> - 2006-08-07 15:52:49
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/advanced In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/input/javasrc/biz/xsoftware/examples/advanced Modified Files: TestExample.java Log Message: fixed a bug in ignore... ported the examples Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/advanced/TestExample.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestExample.java 26 Jun 2005 12:02:25 -0000 1.1 --- TestExample.java 7 Aug 2006 15:52:45 -0000 1.2 *************** *** 34,38 **** * @showcode */ ! public void setUp() { mockTaskSvc = MockObjectFactory.createMock(TaskSystem.class); mockRecord = MockObjectFactory.createMock(TaskRecordService.class); --- 34,39 ---- * @showcode */ ! @Override ! public void setUp() { mockTaskSvc = MockObjectFactory.createMock(TaskSystem.class); mockRecord = MockObjectFactory.createMock(TaskRecordService.class); *************** *** 57,61 **** sysUnderTest.sendUserMailWhenTaskStarted(expectedName, expectedTask); ! Object o = mockTaskSvc.expectCall("addScheduleListener").getAllParams()[0]; ScheduleListener l = (ScheduleListener)o; --- 58,62 ---- sysUnderTest.sendUserMailWhenTaskStarted(expectedName, expectedTask); ! Object o = mockTaskSvc.expect("addScheduleListener").getAllParams()[0]; ScheduleListener l = (ScheduleListener)o; *************** *** 63,66 **** --- 64,68 ---- //that a call to getUser results from an event MockObject mockUser = MockObjectFactory.createMock(User.class); + mockUser.addReturnValue("addTaskDone", "foo"); mockRecord.addReturnValue("getUser", mockUser); *************** *** 69,77 **** l.eventStarted(null); ! String actualUserId = (String)mockRecord.expectCall("getUser").getAllParams()[0]; assertEquals("User id was incorrect", expectedName, actualUserId); ! String actualTask = (String)mockUser.expectCall("addTaskDone").getAllParams()[0]; assertEquals("task name was incorrect", expectedTask, actualTask); --- 71,79 ---- l.eventStarted(null); ! String actualUserId = (String)mockRecord.expect("getUser").getAllParams()[0]; assertEquals("User id was incorrect", expectedName, actualUserId); ! String actualTask = (String)mockUser.expect("addTaskDone").getAllParams()[0]; assertEquals("task name was incorrect", expectedTask, actualTask); |
From: dadrox <da...@us...> - 2006-08-07 15:52:48
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/basic In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/input/javasrc/biz/xsoftware/examples/basic Modified Files: TestExample.java Log Message: fixed a bug in ignore... ported the examples Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/basic/TestExample.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestExample.java 26 Jun 2005 12:02:25 -0000 1.1 --- TestExample.java 7 Aug 2006 15:52:45 -0000 1.2 *************** *** 35,39 **** * @see junit.framework.TestCase#setUp() */ ! public void setUp() { mockCreditSvc = MockObjectFactory.createMock(CreditAuthorizationSvc.class); mockGiftSvc = MockObjectFactory.createMock(GiftCardAccountSvc.class); --- 35,40 ---- * @see junit.framework.TestCase#setUp() */ ! @Override ! public void setUp() { mockCreditSvc = MockObjectFactory.createMock(CreditAuthorizationSvc.class); mockGiftSvc = MockObjectFactory.createMock(GiftCardAccountSvc.class); *************** *** 57,61 **** sysUnderTest.purchase("itemA", user, amount); ! Object[] paramsToAuthorize = mockCreditSvc.expectCall("authorize").getAllParams(); assertEquals("User should be the same", user, paramsToAuthorize[0]); assertEquals("Amount should have been the same", new Double(amount), paramsToAuthorize[1]); --- 58,62 ---- sysUnderTest.purchase("itemA", user, amount); ! Object[] paramsToAuthorize = mockCreditSvc.expect("authorize").getAllParams(); assertEquals("User should be the same", user, paramsToAuthorize[0]); assertEquals("Amount should have been the same", new Double(amount), paramsToAuthorize[1]); *************** *** 105,112 **** //in a failure case. Also could have made takeMoney ignored instead so //we didn't test the takeMoney and just tested returnMoney. ! String[] calls = new String[2]; ! calls[0] = "takeMoney"; ! calls[1] = "returnMoney"; ! CalledMethod[] methods = mockCreditSvc.expectOrderedCalls(calls); CalledMethod takeMoney = methods[0]; assertEquals("Took from correct user", user, takeMoney.getParameter(0)); --- 106,110 ---- //in a failure case. Also could have made takeMoney ignored instead so //we didn't test the takeMoney and just tested returnMoney. ! CalledMethod[] methods = mockCreditSvc.expect("takeMoney", "returnMoney"); CalledMethod takeMoney = methods[0]; assertEquals("Took from correct user", user, takeMoney.getParameter(0)); |
From: dadrox <da...@us...> - 2006-08-07 15:52:48
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15882/input/javasrc/biz/xsoftware/examples/mock2/basic Modified Files: TestExample.java Log Message: fixed a bug in ignore... ported the examples Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic/TestExample.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TestExample.java 5 Apr 2006 15:27:14 -0000 1.4 --- TestExample.java 7 Aug 2006 15:52:45 -0000 1.5 *************** *** 19,23 **** } ! public void setUp() { mockCreditSvc = MockObjectFactory.createMock("1",CreditAuthorizationSvc.class); mockGiftSvc = MockObjectFactory.createMock(GiftCardAccountSvc.class); --- 19,24 ---- } ! @Override ! public void setUp() { mockCreditSvc = MockObjectFactory.createMock("1",CreditAuthorizationSvc.class); mockGiftSvc = MockObjectFactory.createMock(GiftCardAccountSvc.class); |
From: Christopher B. W. <da...@us...> - 2006-08-04 16:23:27
|
Update of /cvsroot/mocklib/mocklib2/bldfiles In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv22167/bldfiles Modified Files: release.xml Log Message: changed username Index: release.xml =================================================================== RCS file: /cvsroot/mocklib/mocklib2/bldfiles/release.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** release.xml 21 Dec 2005 19:34:44 -0000 1.4 --- release.xml 4 Aug 2006 16:23:24 -0000 1.5 *************** *** 10,14 **** <property name="taglet" value="${tool.dir}/taglet"/> ! <property name="user" value="fastdragon"/> <!-- --- 10,14 ---- <property name="taglet" value="${tool.dir}/taglet"/> ! <property name="user" value="dadrox"/> <!-- |
From: Christopher B. W. <da...@us...> - 2006-08-04 16:20:58
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv20724/input/javasrc/biz/xsoftware/mock Modified Files: MockObject.java MockSuperclass.java MockObjectImpl.java Log Message: changed the api to use varargs for expect and ignore. also added a single arg version of each for eclipse content assist happiness. Index: MockSuperclass.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockSuperclass.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** MockSuperclass.java 10 Jun 2006 12:54:36 -0000 1.8 --- MockSuperclass.java 4 Aug 2006 16:20:52 -0000 1.9 *************** *** 118,121 **** --- 118,131 ---- return waitTime; } + + public void ignore(String method) + { + ignore(method); + } + + public void ignore(String ... methods) + { + setIgnoredMethods(methods); + } public void setIgnoredMethods(String[] methods) { *************** *** 133,137 **** * * @param method ! * @param param * @return whatever the client has specified using addReturnValue */ --- 143,147 ---- * * @param method ! * @param parameters * @return whatever the client has specified using addReturnValue */ *************** *** 283,287 **** */ public CalledMethod expectCall(String method) { ! return expectOrderedCalls(new String[] {method})[0]; } --- 293,312 ---- */ public CalledMethod expectCall(String method) { ! return expect(new String[] {method})[0]; ! } ! ! /** ! * @see biz.xsoftware.mock.MockObject#expect(java.lang.String) ! */ ! public CalledMethod expect(String method) { ! return expect(new String[] {method})[0]; ! } ! ! /** ! * @see biz.xsoftware.mock.MockObject#expect(java.lang.String[]) ! */ ! public synchronized CalledMethod[] expect(String ... methods) ! { ! return expectOrderedCalls(methods); } Index: MockObject.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObject.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MockObject.java 10 Jun 2006 12:41:03 -0000 1.4 --- MockObject.java 4 Aug 2006 16:20:52 -0000 1.5 *************** *** 34,40 **** * @param method The expected method. * @return An array of params that were passed to the methods called */ public CalledMethod expectCall(String method); ! /** * Waits for all the methods to be called. If any of the methods --- 34,66 ---- * @param method The expected method. * @return An array of params that were passed to the methods called + * + * @deprecated please use expect(String method) */ public CalledMethod expectCall(String method); ! ! /** ! * Waits for one and only one method to be called. If any methods are ! * called before or after this one(after can sometimes be caught by ! * the MockObject when the threading is not synchronous), then ! * this call will throw an ExpectFailedException. ! * ! * @param method The expected method. ! * @return An array of params that were passed to the methods called ! */ ! public CalledMethod expect(String method); ! ! /** ! * Waits for all the methods to be called. If any of the methods ! * are not called or are called out of order, this method throws ! * an exception which will fail the test case. For each method, ! * this will wait WAIT_TIME milliseconds for each method to be called. ! * If the method is not called within this period, an exception will ! * be thrown saying 'method' was not called within timeout period. ! * ! * @param methods The expected method(s) in the correct order. ! * @return An array or arrays of params that were passed to the methods called ! */ ! public CalledMethod[] expect(String ... methods); ! /** * Waits for all the methods to be called. If any of the methods *************** *** 47,50 **** --- 73,78 ---- * @param methods The expected methods in the correct order. * @return An array or arrays of params that were passed to the methods called + * + * @deprecated please use expectCall(String ... methods) */ public CalledMethod[] expectOrderedCalls(String[] methods); *************** *** 57,60 **** --- 85,90 ---- * @return An array of params that were passed to the methods called. This * array lines up with the methods array passed in. + * + * @deprecated this will go away soon, unless you email me that you depend on it. */ public CalledMethod[] expectUnorderedCalls(String[] methods); *************** *** 101,106 **** --- 131,151 ---- * in 'methods' variable so if one of the methods in this array is * called, it will not result in an exception. + * + * @deprecated please use ignore(String ... methods) */ public void setIgnoredMethods(String[] methods); + + /** + * When calling expect, the MockObject will ignore this method, + * so it will not result in an exception. + */ + public void ignore(String method); + + /** + * When calling expect, the MockObject will ignore the methods + * in 'methods' variable so if one of the methods in this array is + * called, it will not result in an exception. + */ + public void ignore(String ... methods); public void setCloner(Cloner c); Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObjectImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MockObjectImpl.java 19 Feb 2006 19:20:52 -0000 1.6 --- MockObjectImpl.java 4 Aug 2006 16:20:52 -0000 1.7 *************** *** 14,24 **** - - /** * @author Dean Hiller - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ class MockObjectImpl extends MockSuperclass implements InvocationHandler { --- 14,19 ---- |
From: Nobody <fas...@us...> - 2006-06-10 12:54:39
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13507/input/javasrc/biz/xsoftware/mock Modified Files: MockSuperclass.java Log Message: fix the breakage of default return value not working. Index: MockSuperclass.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockSuperclass.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MockSuperclass.java 10 Jun 2006 12:41:03 -0000 1.7 --- MockSuperclass.java 10 Jun 2006 12:54:36 -0000 1.8 *************** *** 177,180 **** --- 177,184 ---- this.notifyAll(); + Object defaultVal = methodToDefaultRetVal.get(method); + if(defaultVal != null) + return defaultVal; + return findNextAction(method, parameters); } |
From: Nobody <fas...@us...> - 2006-06-10 12:54:39
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13507/input/javasrc/biz/xsoftware/test/mock Modified Files: TestMockCreator.java Log Message: fix the breakage of default return value not working. Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TestMockCreator.java 10 Jun 2006 12:41:03 -0000 1.2 --- TestMockCreator.java 10 Jun 2006 12:54:36 -0000 1.3 *************** *** 153,156 **** --- 153,170 ---- } + public void testDefaultRetVal() { + MockObject mock = MockObjectFactory.createMock(Identical.class); + + mock.setDefaultReturnValue("doThat", new byte[] {4}); + + Identical ident = (Identical)mock; + byte[] retVal = ident.doThat(null); + + mock.expectCall("doThat"); + + assertEquals(1, retVal.length); + assertEquals(4, retVal[0]); + } + public void testBehavior() { MockObject mock = MockObjectFactory.createMock(Identical.class); |
From: Nobody <fas...@us...> - 2006-06-10 12:41:31
|
Update of /cvsroot/mocklib/mocklib2 In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7753 Modified Files: .cvsignore Log Message: modify cvsignore slightly. Index: .cvsignore =================================================================== RCS file: /cvsroot/mocklib/mocklib2/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .cvsignore 19 Feb 2006 19:20:54 -0000 1.1 --- .cvsignore 10 Jun 2006 12:41:28 -0000 1.2 *************** *** 1 **** --- 1,2 ---- output + eclipsegen |
From: Nobody <fas...@us...> - 2006-06-10 12:41:09
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7561/input/javasrc/biz/xsoftware/test/mock Modified Files: TestMockCreator.java Added Files: Identical.java Log Message: add behavior to mock library. --- NEW FILE: Identical.java --- /** * Copyright (C) 2006 Carrier Access, Corp. */ package biz.xsoftware.test.mock; /** */ public interface Identical { public byte[] doThat(byte[] data); } Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestMockCreator.java 1 Jan 2006 00:35:56 -0000 1.1 --- TestMockCreator.java 10 Jun 2006 12:41:03 -0000 1.2 *************** *** 11,14 **** --- 11,15 ---- import junit.framework.TestSuite; import junit.textui.TestRunner; + import biz.xsoftware.mock.Behavior; import biz.xsoftware.mock.CalledMethod; import biz.xsoftware.mock.ExpectFailedException; *************** *** 152,155 **** --- 153,231 ---- } + public void testBehavior() { + MockObject mock = MockObjectFactory.createMock(Identical.class); + + mock.addBehavior("doThat", new MyBehavior()); + + Identical ident = (Identical)mock; + + byte[] original = new byte[] { 1, 2, 3, 4, 0, 0, 0, 0}; + byte[] bytes = new byte[] { 1, 2, 3, 4, 0 ,0,0,0}; + + byte[] newBytes = ident.doThat(bytes); + + CalledMethod m = mock.expectCall("doThat"); + byte[] passedIn = (byte[])m.getAllParams()[0]; + + assertEquals(original.length, passedIn.length); + for(int i = 0; i < original.length; i++) { + assertEquals(original[i], passedIn[i]); + } + + //make sure this is the same byte array we passed in + assertSame(bytes, newBytes); + + for(int i = 0; i < 4; i++) { + assertEquals(newBytes[i], newBytes[i+4]); + } + } + + private static class MyBehavior implements Behavior { + + /** + * @see biz.xsoftware.mock.Behavior#clone(java.lang.Object[]) + */ + public Object[] clone(Object[] params) + { + Object[] retVal = new Object[params.length]; + for(int i = 0; i < retVal.length; i++) { + Object val = params[i]; + if(val instanceof byte[]) { + retVal[i] = cloneBytes((byte[])val); + } + } + return retVal; + } + + /** + * @param bs + * @return + */ + private Object cloneBytes(byte[] bytes) + { + byte[] newBytes = new byte[bytes.length]; + for(int i = 0; i < newBytes.length; i++) { + newBytes[i] = bytes[i]; + } + return newBytes; + } + + /** + * @see biz.xsoftware.mock.Behavior#runMethod(java.lang.Object[]) + */ + public Object runMethod(Object[] params) + { + //we know the test does an 4 byte array, so do that + byte[] bytes = (byte[])params[0]; + for(int i = 0; i < 4; i++) { + bytes[i+4] = bytes[i]; + } + + //make sure to return the same byte buffer so we are really testing this... + return bytes; + } + + } + public static void main(String[] args) { TestSuite suite = new TestSuite(); |
From: Nobody <fas...@us...> - 2006-06-10 12:41:09
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7561/input/javasrc/biz/xsoftware/mock Modified Files: MockObject.java MockSuperclass.java Added Files: Behavior.java Log Message: add behavior to mock library. --- NEW FILE: Behavior.java --- /** * Copyright (C) 2006 Carrier Access, Corp. */ package biz.xsoftware.mock; /** * An implementation of this class must have the */ public interface Behavior { public Object[] clone(Object[] params); /** * This method will be called in place of the interface method you are expecting to be called. * This is where you can add behavior to the mock object. * * @param params * @return */ public Object runMethod(Object[] params); } Index: MockSuperclass.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockSuperclass.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MockSuperclass.java 19 Feb 2006 19:20:52 -0000 1.6 --- MockSuperclass.java 10 Jun 2006 12:41:03 -0000 1.7 *************** *** 62,71 **** */ private List<CalledMethod> methodsCalled = new LinkedList<CalledMethod>(); /** ! * A map of queues containing exceptions to throw on certain methods. ! */ ! private Map<String, List<Throwable>> methodToException = new HashMap<String, List<Throwable>>(); ! /** ! * A map of queues, containing objects to return when methods are called */ private Map<String, List<Object>> methodToReturnVal = new HashMap<String, List<Object>>(); --- 62,71 ---- */ private List<CalledMethod> methodsCalled = new LinkedList<CalledMethod>(); + /** ! * A map of queues, containing either ! * 1. objects to return when methods are called ! * 2. Behaviors to run which return objects to return ! * 3. Exceptions to throw */ private Map<String, List<Object>> methodToReturnVal = new HashMap<String, List<Object>>(); *************** *** 172,210 **** //corrupted meaning you can't write a test to test the contract //without cloning the object so it can't be changed. ! parameters = clone(parameters); ! methodsCalled.add(new CalledMethod(method, parameters, new Throwable().fillInStackTrace())); this.notifyAll(); ! //throw exception last so clients can still verify this method was called ! //so they have confidence the exception was actually thrown. ! throwExceptionIfNeeded(method); ! ! return getReturnValue(method); ! } ! ! private Object getReturnValue(String method) { ! List l = (List)methodToReturnVal.get(method); ! if(l != null) { ! Object retVal = l.remove(0); ! if(l.size()<= 0) ! methodToReturnVal.remove(method); ! return retVal; ! } ! //next line returns null if setDefaultReturnValue not called by test case... ! return methodToDefaultRetVal.get(method); } ! private void throwExceptionIfNeeded(String method) throws Throwable { ! List l = (List)methodToException.get(method); ! if(l == null) ! return; ! Throwable t = (Throwable)l.remove(0); ! if(l.size() <= 0) ! methodToException.remove(method); ! ! t.fillInStackTrace(); ! log.fine("throw exception on method="+method+" exc="+t); ! throw (Throwable)t; } --- 172,200 ---- //corrupted meaning you can't write a test to test the contract //without cloning the object so it can't be changed. ! Object[] newParams = clone(method, parameters); ! methodsCalled.add(new CalledMethod(method, newParams, new Throwable().fillInStackTrace())); this.notifyAll(); ! return findNextAction(method, parameters); } ! private Object findNextAction(String method, Object[] params) throws Throwable { ! List l = (List)methodToReturnVal.get(method); ! if(l == null) ! return null; ! ! Object retVal = l.remove(0); ! if(l.size()<=0) ! methodToReturnVal.remove(method); ! ! if(retVal instanceof Behavior) { ! return ((Behavior)retVal).runMethod(params); ! } else if(retVal instanceof Throwable) { ! Throwable t = (Throwable)retVal; ! t.fillInStackTrace(); ! throw t; ! } else ! return retVal; } *************** *** 535,542 **** else if(e == null) throw new IllegalArgumentException("e parameter to this method cannot be null"); ! List<Throwable> l = methodToException.get(method); if(l == null) { ! l = new ArrayList<Throwable>(); ! methodToException.put(method, l); } l.add(e); --- 525,532 ---- else if(e == null) throw new IllegalArgumentException("e parameter to this method cannot be null"); ! List<Object> l = methodToReturnVal.get(method); if(l == null) { ! l = new ArrayList<Object>(); ! methodToReturnVal.put(method, l); } l.add(e); *************** *** 569,575 **** * @return */ ! private Object[] clone(Object[] params) { if(params == null) return null; if(cloner == null) return params; --- 559,577 ---- * @return */ ! private Object[] clone(String method, Object[] params) { if(params == null) return null; + + //check if the next object is a Behavior object + List<Object> actions = methodToReturnVal.get(method); + if(actions != null) { + Object action = actions.get(0); + if(action instanceof Behavior) { + Behavior behavior = (Behavior)action; + return behavior.clone(params); + } + } + + if(cloner == null) return params; *************** *** 585,587 **** --- 587,600 ---- cloner = c; } + + public void addBehavior(String method, Behavior behavior) { + if(method == null) + throw new IllegalArgumentException("method parameter cannot be null"); + List<Object> l = methodToReturnVal.get(method); + if(l == null) { + l = new ArrayList<Object>(); + methodToReturnVal.put(method, l); + } + l.add(behavior); + } } Index: MockObject.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObject.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MockObject.java 27 Jun 2005 03:40:32 -0000 1.3 --- MockObject.java 10 Jun 2006 12:41:03 -0000 1.4 *************** *** 7,10 **** --- 7,11 ---- package biz.xsoftware.mock; + /** * The interface all mock objects implement. This is the interface used *************** *** 113,116 **** --- 114,119 ---- public int getExpectTimeout(); + + public void addBehavior(String string, Behavior behavior); } |
From: Christopher B. W. <da...@us...> - 2006-05-05 15:29:37
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/advanced In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9115/input/javasrc/biz/xsoftware/examples/mock2/advanced Modified Files: TestExample.java Log Message: Missing returns on expect or ignore are reported to the user. Incorrect return types fail and are reported. Fixed some bugs with MockObject.verify(). Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/advanced/TestExample.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestExample.java 28 Mar 2006 15:50:06 -0000 1.1 --- TestExample.java 5 May 2006 15:29:23 -0000 1.2 *************** *** 68,78 **** 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); --- 68,78 ---- MockObject mockUser = MockObjectFactory.createMock(User.class); CalledMethod getUser=mockRecord.expect("getUser"); ! CalledMethod addTaskDone=mockUser.expect("", "addTaskDone"); ! mockRecord.setDefaultReturnValue( (User)mockUser,"getUser"); //have mockTaskSvc fire an event that should cause sysUnderTest //to interact with mockMessaging ! l.eventStarted(""); |
From: Christopher B. W. <da...@us...> - 2006-05-05 15:29:36
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9115/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java TestIgnoredMethods.java Added Files: TestVerify.java Log Message: Missing returns on expect or ignore are reported to the user. Incorrect return types fail and are reported. Fixed some bugs with MockObject.verify(). --- NEW FILE: TestVerify.java --- /** * Copyright (C) 2006 Carrier Access, Corp. */ package biz.xsoftware.test.mock2; import junit.framework.TestCase; import biz.xsoftware.mock2.MockObject; import biz.xsoftware.mock2.MockObjectFactory; /** */ public class TestVerify extends TestCase { private MockObject mock; private FakeSystem fake; private byte zeroByte = 30; /** * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { mock = MockObjectFactory.createMock(ListenerOne.class); fake = new FakeSystem((ListenerOne)mock, zeroByte); } /** * @see junit.framework.TestCase#tearDown() */ @Override protected void tearDown() throws Exception { super.tearDown(); } public void testVerifyWithAllMethodsIgnored() { //we are expecting this array to be modified so clone it here... byte[] expected = new byte[] { 4, 5, 6, 7 }; mock.addIgnoredMethod(100, "write"); mock.addIgnoredMethod("callMeLast"); mock.addIgnoredMethod("callMeFirst"); int answer = fake.runSystem(expected); mock.verify(); assertEquals(100, answer); } public void testIncorrectReturnTypeExpected() { //we are expecting this array to be modified so clone it here... byte[] expected = new byte[] { 4, 5, 6, 7 }; mock.addIgnoredMethod(new Object(), "write"); mock.addIgnoredMethod("callMeLast"); mock.addIgnoredMethod("callMeFirst"); try { fake.runSystem(expected); fail("We specified an incorrect return type, so this should have thrown a RuntimeException"); } catch(RuntimeException e) {} } public void testBoxableReturnType() { //we are expecting this array to be modified so clone it here... byte[] expected = new byte[] { 4, 5, 6, 7 }; mock.addIgnoredMethod(new Integer(100), "write"); mock.addIgnoredMethod("callMeLast"); mock.addIgnoredMethod("callMeFirst"); int answer = fake.runSystem(expected); mock.verify(); assertEquals(100, answer); } } Index: TestIgnoredMethods.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestIgnoredMethods.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestIgnoredMethods.java 2 May 2006 23:26:34 -0000 1.1 --- TestIgnoredMethods.java 5 May 2006 15:29:23 -0000 1.2 *************** *** 38,42 **** } - public void testIgnoredMethods() { --- 38,41 ---- Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** TestMockCreator.java 2 May 2006 23:26:34 -0000 1.19 --- TestMockCreator.java 5 May 2006 15:29:23 -0000 1.20 *************** *** 192,195 **** --- 192,196 ---- t.start(); + Thread.sleep(4000); m.verify(); *************** *** 330,334 **** l.callMeFirst(param1); m.addIgnoredMethod(methodName1); - m.setDefaultReturnValue("retval",methodName1); l.callMeLast(param2); l.callMeFirst(param1); --- 331,334 ---- *************** *** 342,351 **** } - - - - - - } --- 342,345 ---- |
From: Christopher B. W. <da...@us...> - 2006-05-05 15:29:29
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9115/input/javasrc/biz/xsoftware/mock2 Modified Files: Messages.java MockObject.java Log Message: Missing returns on expect or ignore are reported to the user. Incorrect return types fail and are reported. Fixed some bugs with MockObject.verify(). Index: MockObject.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/MockObject.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MockObject.java 2 May 2006 23:26:34 -0000 1.6 --- MockObject.java 5 May 2006 15:29:23 -0000 1.7 *************** *** 19,22 **** --- 19,23 ---- */ public CalledMethod expect(String methodName, Class... vargs); + public CalledMethod expect(String methodName); /** *************** *** 33,38 **** * is called */ ! public CalledMethod expect(Object returnValue, String methodName, ! Class... vargs); /** --- 34,38 ---- * is called */ ! public CalledMethod expect(Object returnValue, String methodName, Class... vargs); /** *************** *** 49,54 **** * is called */ ! public CalledMethod expect(String methodName, Throwable throwable, ! Class... vargs); /** --- 49,53 ---- * is called */ ! public CalledMethod expect(String methodName, Throwable throwable, Class... vargs); /** *************** *** 66,71 **** * @throws NoSuchMethodException */ ! public CalledMethod expect(String methodName, Behavior behavior, ! Class... params); /*************************************************************************** --- 65,69 ---- * @throws NoSuchMethodException */ ! public CalledMethod expect(String methodName, Behavior behavior, Class... params); /*************************************************************************** *************** *** 101,106 **** * is called */ ! public CalledMethod expect(Object returnValue, String methodName, ! long timeout, Class... vargs); /** --- 99,103 ---- * is called */ ! public CalledMethod expect(Object returnValue, String methodName, long timeout, Class... vargs); /** *************** *** 119,124 **** * is called */ ! public CalledMethod expect(String methodName, Throwable throwable, ! long timeout, Class... vargs); /** --- 116,120 ---- * is called */ ! public CalledMethod expect(String methodName, Throwable throwable, long timeout, Class... vargs); /** *************** *** 138,143 **** * @throws NoSuchMethodException */ ! public CalledMethod expect(String methodName, Behavior behavior, ! long timeout, Class... params) ; /** --- 134,138 ---- * @throws NoSuchMethodException */ ! public CalledMethod expect(String methodName, Behavior behavior, long timeout, Class... params) ; /** *************** *** 157,160 **** --- 152,156 ---- */ public void addIgnoredMethod(String methodName, Class... vargs); + public void addIgnoredMethod(String methodName); /** *************** *** 191,196 **** * the optional parameter types of the method calls */ ! public void setDefaultReturnValue(Object returnValue, String methodName, ! Class... vargs); /** --- 187,191 ---- * the optional parameter types of the method calls */ ! public void setDefaultReturnValue(Object returnValue, String methodName, Class... vargs); /** Index: Messages.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/Messages.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Messages.java 2 May 2006 23:26:34 -0000 1.6 --- Messages.java 5 May 2006 15:29:23 -0000 1.7 *************** *** 7,14 **** 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"; public static final String TOO_MANY_METHODS_CALLED="Unexpected method called"; public static final String ORDER_EXCEPTION="methods called or methods expected is in wrong order"; } --- 7,15 ---- 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 any 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"; public static final String TOO_MANY_METHODS_CALLED="Unexpected method called"; public static final String ORDER_EXCEPTION="methods called or methods expected is in wrong order"; + public static final String EXPECTED_METHOD_NOT_CALLED = "One or more methods you expected were not called"; } |
From: Christopher B. W. <da...@us...> - 2006-05-05 15:29:28
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9115/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectImpl.java CalledMethodImpl.java MockObjectSuperImpl.java Log Message: Missing returns on expect or ignore are reported to the user. Incorrect return types fail and are reported. Fixed some bugs with MockObject.verify(). Index: CalledMethodImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/CalledMethodImpl.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CalledMethodImpl.java 2 May 2006 23:26:34 -0000 1.4 --- CalledMethodImpl.java 5 May 2006 15:29:23 -0000 1.5 *************** *** 2,5 **** --- 2,6 ---- import biz.xsoftware.mock2.CalledMethod; + import biz.xsoftware.mock2.Messages; public class CalledMethodImpl implements CalledMethod{ *************** *** 37,41 **** if(parameters==null) { ! throw new IllegalStateException("MockObject.verify() must be called before accessing and of the methods on CalledMethod object"); } return parameters; --- 38,42 ---- if(parameters==null) { ! throw new IllegalStateException(Messages.VERIFY_NOT_CALLED); } return parameters; Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectImpl.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MockObjectImpl.java 2 May 2006 23:26:34 -0000 1.7 --- MockObjectImpl.java 5 May 2006 15:29:23 -0000 1.8 *************** *** 1,4 **** --- 1,7 ---- + + package biz.xsoftware.mock2.impl; + import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; *************** *** 9,87 **** import biz.xsoftware.mock2.MockObject; /** ! * this class implements the interface InvocationHandler,defind a ! * certain MockObject and return a calledMethod instance to the ! * test cases * @author Jay - * */ ! public class MockObjectImpl extends MockObjectSuperImpl implements ! InvocationHandler { ! private static Set<Method> isMethodInSuper=new HashSet<Method>(); ! private Class[] classes; private Class c; private Object realObject; - - static { - Class c=MockObject.class; - Method[] m=c.getMethods(); - for(int i=0;i<m.length;i++){ - isMethodInSuper.add(m[i]); - } - c=Object.class; - m=c.getMethods(); - for(int i=0;i<m.length;i++){ - isMethodInSuper.add(m[i]); - } - } - 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; ! } - 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; - - } ! private Object callSuperMethod(Object proxy, Method method, Object[] args) throws Throwable{ ! try { ! if("equals".equals(method.getName())) ! return new Boolean(proxy == args[0]); ! else if("toString".equals(method.getName())) ! return ""+this; ! ! return method.invoke(this, args); ! } catch(InvocationTargetException e) { ! if(e.getCause() != null) ! throw e.getCause(); ! else ! throw e; ! } ! } ! ! public Class getC(){ ! return this.c; ! } ! ! public Class[] getClasses(){ return this.classes; } ! ! public Object getRealObject(){ return this.realObject; } } - --- 12,110 ---- import biz.xsoftware.mock2.MockObject; + /** ! * this class implements the interface InvocationHandler,defind a certain MockObject and return a calledMethod instance ! * to the test cases ! * * @author Jay */ ! public class MockObjectImpl extends MockObjectSuperImpl implements InvocationHandler ! { ! private static Set<Method> isMethodInSuper = new HashSet<Method>(); ! ! private Class[] classes; ! private Class c; + private Object realObject; ! static ! { ! addMethodsToSet(MockObject.class); ! addMethodsToSet(Object.class); ! } ! ! private static void addMethodsToSet(Class c) ! { ! Method[] m = c.getMethods(); ! for(int i = 0; i < m.length; i++) ! { ! isMethodInSuper.add(m[i]); ! } ! } ! 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; ! } ! ! ! public Object invoke(Object proxy, Method method, Object[] args) throws Throwable ! { ! if(isMethodInSuper.contains(method)) ! { ! return callSuperMethod(proxy, method, args); ! } ! return methodCalledImpl(method.getName(), args, method.getReturnType()); ! ! } ! ! ! private Object callSuperMethod(Object proxy, Method method, Object[] args) throws Throwable ! { ! try ! { ! if("equals".equals(method.getName())) ! return new Boolean(proxy == args[0]); ! else if("toString".equals(method.getName())) ! return "" + this; ! ! return method.invoke(this, args); ! } ! catch(InvocationTargetException e) ! { ! if(e.getCause() != null) ! throw e.getCause(); ! else ! throw e; ! } ! } ! ! ! public Class getC() ! { ! return this.c; ! } ! ! ! public Class[] getClasses() ! { return this.classes; } ! ! ! public Object getRealObject() ! { return this.realObject; } } Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MockObjectSuperImpl.java 2 May 2006 23:26:34 -0000 1.14 --- MockObjectSuperImpl.java 5 May 2006 15:29:23 -0000 1.15 *************** *** 23,30 **** 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; --- 23,30 ---- 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,62 **** --- 59,63 ---- */ private Map<String,Behavior> behaviorMap = new HashMap<String,Behavior>(); + /** * A Map of methods which are ignored by tester *************** *** 73,76 **** --- 74,81 ---- } + public CalledMethod expect(String methodName) { + return expect(methodName, DEFAULT_TIME_OUT, new Class[] {}); + } + public CalledMethod expect(Object returnValue, String methodName, Class... vargs) { return expect(returnValue, methodName, DEFAULT_TIME_OUT, vargs); *************** *** 104,111 **** delayTime = timeout; CalledMethod calledMethod = new CalledMethodImpl(methodName); ! // if(!methodsIgnored.containsKey(methodName)){ methodsExpected.add(calledMethod); retVal.put(methodName, returnValue); ! // } if(log.isLoggable(Level.FINE)){ log.log(Level.FINE,"ID="+id+" "+methodName+" is expected with return value="+returnValue); --- 109,116 ---- delayTime = timeout; CalledMethod calledMethod = new CalledMethodImpl(methodName); ! if(!methodsIgnored.containsKey(methodName)){ methodsExpected.add(calledMethod); retVal.put(methodName, returnValue); ! } if(log.isLoggable(Level.FINE)){ log.log(Level.FINE,"ID="+id+" "+methodName+" is expected with return value="+returnValue); *************** *** 178,182 **** public void verify() { ! timeoutOnEmptyExpect(); // copy this stuff for reporting errors later --- 183,187 ---- public void verify() { ! // timeoutOnEmptyExpect(); // copy this stuff for reporting errors later *************** *** 239,244 **** --- 244,259 ---- expectedMethod.setStackTrace(calledMethod.getStackTrace()); } + + if(methodsExpected.size() > 0) + { + verifyErredOut(Messages.EXPECTED_METHOD_NOT_CALLED, copyMethodsCalled, copyMethodsExpected, copyMethodsIgnored); + } } + // TODO REMOVE: + // dadrox isn't sure what this code was supposed to do. all it _seemed_ to do was make some tests + // take a long time to run. dadrox removed the code and fixed all of the tests that seemed to + // depend on the delay. + // if this is deemed The Right Thing To Do, then this method may be removed. private void timeoutOnEmptyExpect() { *************** *** 288,294 **** } ! protected Object methodCalledImpl(String methodName, Object[] parameters) throws Throwable{ checkPreconditions(methodName); methodName = methodName.intern(); String params = ""; --- 303,312 ---- } ! protected Object methodCalledImpl(String methodName, Object[] parameters, Class<?> returnType) throws Throwable{ checkPreconditions(methodName); + // REMOVE + log.info("return type=" + returnType); + methodName = methodName.intern(); String params = ""; *************** *** 296,300 **** params = "no params"; } else { ! Object[] array = (Object[]) parameters; for (int i = 0; i < array.length - 1; i++) { params += array[i] + ", "; --- 314,318 ---- params = "no params"; } else { ! Object[] array = parameters; for (int i = 0; i < array.length - 1; i++) { params += array[i] + ", "; *************** *** 305,312 **** 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); --- 323,330 ---- 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); *************** *** 316,320 **** Throwable t=methodWithException.get(calledMethod.getMethodName()); throw t; ! } for(int i=0;i<methodList.size();i++){ --- 334,338 ---- Throwable t=methodWithException.get(calledMethod.getMethodName()); throw t; ! } for(int i=0;i<methodList.size();i++){ *************** *** 326,330 **** } } ! return getReturnValue(methodName); } --- 344,410 ---- } } ! Object ret = getReturnValue(methodName); ! if(ret == null && void.class != returnType) ! { ! throw new RuntimeException("You must specify a return value for " + ! "ignored or expected method " + methodName + "()"); ! } ! else if(returnType != Void.TYPE && ret != null && (ret.getClass().isPrimitive() || returnType.isPrimitive())) ! { ! handlePrimitiveReturns(methodName, ret, returnType); ! } ! else if(ret != null && ret instanceof MockObject) {} ! else if(ret != null && ret.getClass() != returnType)// && !returnType.isPrimitive()) ! { ! throwTypeException(methodName, ret, ret.getClass().getName(), returnType.getName()); ! } ! return ret; ! } ! ! private void handlePrimitiveReturns(String methodName, Object ret, Class<?> expectedReturnType) ! { ! Class<?>[] primitiveTypes = {Integer.TYPE, Double.TYPE, Float.TYPE, Boolean.TYPE, ! Character.TYPE, Byte.TYPE, Short.TYPE, Long.TYPE}; ! Object[] primitiveClasses = {Integer.class, Double.class, Float.class, Boolean.class, ! Character.class, Byte.class, Short.class, Long.class}; ! if(ret.getClass().isPrimitive() && expectedReturnType.isPrimitive()) ! { ! for(Class<?> currentType : primitiveTypes) ! { ! if(ret.getClass() == currentType && expectedReturnType != currentType) ! { ! throwTypeException(methodName, ret, ret.getClass().getName(), expectedReturnType.getName()); ! } ! } ! } ! else if(ret.getClass().isPrimitive()) ! { ! for(int ii = 0; ii < primitiveTypes.length; ii++) ! { ! if(ret.getClass() == primitiveTypes[ii] && expectedReturnType != primitiveClasses[ii]) ! { ! throwTypeException(methodName, ret, ret.getClass().getName(), expectedReturnType.getName()); ! } ! } ! } ! else ! { ! for(int ii = 0; ii < primitiveTypes.length; ii++) ! { ! if(expectedReturnType == primitiveTypes[ii] && ret.getClass() != primitiveClasses[ii]) ! { ! throwTypeException(methodName, ret, ret.getClass().getName(), expectedReturnType.getName()); ! } ! } ! } ! } ! ! private void throwTypeException(String methodName, Object returnValue, ! String returnType, String expectedReturnType) ! { ! throw new RuntimeException("You specified an incorrect return type for " + ! "ignored or expected method " + methodName + "()" + ! "\nyou specified: " + returnValue + " of type " + ! returnType + " but should have been of type " + expectedReturnType); } *************** *** 345,348 **** --- 425,432 ---- } + public void addIgnoredMethod(String methodName) { + addIgnoredMethod(methodName, new Class[] {}); + } + /** * @see biz.xsoftware.mock2.MockObject#addIgnoredMethod(java.lang.Object, java.lang.String, java.lang.Class...) |
From: Christopher B. W. <da...@us...> - 2006-05-02 23:26:39
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23471/input/javasrc/biz/xsoftware/test/mock2 Modified Files: FakeSystem.java TestMockCreator.java Added Files: TestIgnoredMethods.java Log Message: Fixed some bugs with method not being ignored correctly. general cleanup --- NEW FILE: TestIgnoredMethods.java --- /** * Copyright (C) 2006 Carrier Access, Corp. */ package biz.xsoftware.test.mock2; import biz.xsoftware.mock2.CalledMethod; import biz.xsoftware.mock2.MockObject; import biz.xsoftware.mock2.MockObjectFactory; import junit.framework.TestCase; /** */ public class TestIgnoredMethods extends TestCase { private MockObject mock; private FakeSystem fake; private byte zeroByte = 30; /** * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { mock = MockObjectFactory.createMock(ListenerOne.class); fake = new FakeSystem((ListenerOne)mock, zeroByte); } /** * @see junit.framework.TestCase#tearDown() */ @Override protected void tearDown() throws Exception { super.tearDown(); } public void testIgnoredMethods() { //we are expecting this array to be modified so clone it here... byte[] expected = new byte[] { 4, 5, 6, 7 }; int expectedAnswer = 20; String methodName = "write"; MyBehavior mb = new MyBehavior(expectedAnswer, zeroByte); byte[] clone = mb.cloneWrite(expected); CalledMethod method = mock.expect(methodName, mb, byte[].class); // ??behavior ??valledMethod // mock.addIgnoredMethod("callMeLast"); // mock.expect("callMeFirst"); mock.expect("callMeLast"); mock.addIgnoredMethod("callMeFirst"); int answer = fake.runSystem(clone); mock.verify(); byte[] actual = (byte[])method.getParameters()[0]; assertEquals(zeroByte, actual[0]); assertEquals(expected[1], actual[1]); assertEquals(expected[2], actual[2]); assertEquals(expected[3], actual[3]); assertEquals(100, answer); } public void testIgnoredLastMethod() { //we are expecting this array to be modified so clone it here... byte[] expected = new byte[] { 4, 5, 6, 7 }; int expectedAnswer = 20; String methodName = "write"; MyBehavior mb = new MyBehavior(expectedAnswer, zeroByte); byte[] clone = mb.cloneWrite(expected); CalledMethod method = mock.expect(methodName, mb, byte[].class); // ??behavior ??valledMethod mock.addIgnoredMethod("callMeLast"); mock.expect("callMeFirst"); int answer = fake.runSystem(clone); mock.verify(); byte[] actual = (byte[])method.getParameters()[0]; assertEquals(zeroByte, actual[0]); assertEquals(expected[1], actual[1]); assertEquals(expected[2], actual[2]); assertEquals(expected[3], actual[3]); assertEquals(100, answer); } } Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** TestMockCreator.java 6 Apr 2006 15:25:06 -0000 1.18 --- TestMockCreator.java 2 May 2006 23:26:34 -0000 1.19 *************** *** 289,295 **** 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 ???? --- 289,297 ---- String methodName = "write"; ! MyBehavior mb = new MyBehavior(expectedAnswer, zeroByte); ! byte[] clone = mb.cloneWrite(expected); CalledMethod method = m.expect(methodName,mb,byte[].class); // ??behavior ??valledMethod + m.addIgnoredMethod("callMeFirst"); + m.addIgnoredMethod("callMeLast"); FakeSystem systemUnderTest = new FakeSystem(l, zeroByte); // ??call ???? *************** *** 322,331 **** 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); ! m.addIgnoreMethod(methodName1); m.setDefaultReturnValue("retval",methodName1); l.callMeLast(param2); --- 324,333 ---- CalledMethod callMeLast=m.expect(methodName2); CalledMethod callAgain=m.expect(methodName1); ! m.removeIgnoredMethod(methodName1); CalledMethod callLastAgain=m.expect(methodName2); CalledMethod callThirdTime=m.expect(methodName1); l.callMeFirst(param1); ! m.addIgnoredMethod(methodName1); m.setDefaultReturnValue("retval",methodName1); l.callMeLast(param2); Index: FakeSystem.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/FakeSystem.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** FakeSystem.java 28 Mar 2006 02:52:49 -0000 1.7 --- FakeSystem.java 2 May 2006 23:26:34 -0000 1.8 *************** *** 16,22 **** public int runSystem(byte[] data) { int retVal = list.write(data); ! //now modify data....if mocklib did not clone, the //test will fail --- 16,26 ---- public int runSystem(byte[] data) { + int retVal = list.write(data); ! list.callMeFirst(retVal); ! // list.callMeSecond("foo"); ! list.callMeLast("bar"); ! //now modify data....if mocklib did not clone, the //test will fail |
From: Christopher B. W. <da...@us...> - 2006-05-02 23:26:37
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23471/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectImpl.java CalledMethodImpl.java MockObjectSuperImpl.java Log Message: Fixed some bugs with method not being ignored correctly. general cleanup Index: CalledMethodImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/CalledMethodImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CalledMethodImpl.java 25 Mar 2006 08:17:24 -0000 1.3 --- CalledMethodImpl.java 2 May 2006 23:26:34 -0000 1.4 *************** *** 58,64 **** this.stackTrace = stackTrace; } - - - } --- 58,82 ---- this.stackTrace = stackTrace; } + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + String str = methodName + "("; + if(parameters != null) + { + for(int ii = 0; ii < parameters.length; ii++) + { + str += parameters[ii]; + if(ii != parameters.length - 1) + { + str += ", "; + } + } + } + str += ")"; + return str; + } } Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MockObjectImpl.java 5 Apr 2006 15:27:08 -0000 1.6 --- MockObjectImpl.java 2 May 2006 23:26:34 -0000 1.7 *************** *** 84,91 **** return this.realObject; } - - - - } --- 84,87 ---- Index: MockObjectSuperImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** MockObjectSuperImpl.java 6 Apr 2006 15:25:03 -0000 1.13 --- MockObjectSuperImpl.java 2 May 2006 23:26:34 -0000 1.14 *************** *** 6,17 **** import java.util.List; import java.util.Map; ! import java.util.logging.Logger; import java.util.logging.Level; 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; /** --- 6,18 ---- import java.util.List; import java.util.Map; ! import java.util.Set; import java.util.logging.Level; + import java.util.logging.Logger; import biz.xsoftware.mock2.Behavior; import biz.xsoftware.mock2.CalledMethod; import biz.xsoftware.mock2.ExpectFailedException; import biz.xsoftware.mock2.Messages; + import biz.xsoftware.mock2.MockObject; /** *************** *** 52,65 **** * 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>(); --- 53,66 ---- * 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>(); *************** *** 72,88 **** } ! public CalledMethod expect(Object returnValue, String methodName, ! Class... vargs) { return expect(returnValue, methodName, DEFAULT_TIME_OUT, vargs); } ! public CalledMethod expect(String methodName, Throwable throwable, ! Class... vargs) { return expect(methodName, throwable, DEFAULT_TIME_OUT, vargs); } ! public CalledMethod expect(String methodName, Behavior behavior, ! Class... params){ return expect(methodName, behavior, DEFAULT_TIME_OUT, params); --- 73,86 ---- } ! public CalledMethod expect(Object returnValue, String methodName, Class... vargs) { return expect(returnValue, methodName, DEFAULT_TIME_OUT, vargs); } ! public CalledMethod expect(String methodName, Throwable throwable, Class... vargs) { return expect(methodName, throwable, DEFAULT_TIME_OUT, vargs); } ! public CalledMethod expect(String methodName, Behavior behavior, Class... params){ return expect(methodName, behavior, DEFAULT_TIME_OUT, params); *************** *** 90,96 **** public CalledMethod expect(String methodName, long timeout, Class... vargs) { ! if (methodName == null) ! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); ! delayTime=timeout; CalledMethod calledMethod = new CalledMethodImpl(methodName); if(!methodsIgnored.containsKey(methodName)) --- 88,93 ---- public CalledMethod expect(String methodName, long timeout, Class... vargs) { ! checkPreconditions(methodName); ! delayTime = timeout; CalledMethod calledMethod = new CalledMethodImpl(methodName); if(!methodsIgnored.containsKey(methodName)) *************** *** 103,118 **** } ! public CalledMethod expect(Object returnValue, String methodName, ! long timeout, Class... vargs) { ! 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); 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; --- 100,113 ---- } ! public CalledMethod expect(Object returnValue, String methodName, long timeout, Class... vargs) { ! checkPreconditions(methodName); ! delayTime = timeout; CalledMethod calledMethod = new CalledMethodImpl(methodName); ! // if(!methodsIgnored.containsKey(methodName)){ methodsExpected.add(calledMethod); retVal.put(methodName, returnValue); ! // } if(log.isLoggable(Level.FINE)){ ! log.log(Level.FINE,"ID="+id+" "+methodName+" is expected with return value="+returnValue); } return calledMethod; *************** *** 121,126 **** public CalledMethod expect(String methodName, Throwable throwable, long timeout, Class... vargs) { ! if (methodName == null) ! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); delayTime=timeout; CalledMethod calledMethod = new CalledMethodImpl(methodName); --- 116,120 ---- public CalledMethod expect(String methodName, Throwable throwable, long timeout, Class... vargs) { ! checkPreconditions(methodName); delayTime=timeout; CalledMethod calledMethod = new CalledMethodImpl(methodName); *************** *** 131,135 **** if(log.isLoggable(Level.FINE)){ ! log.log(Level.FINE,"ID="+id+" "+methodName+" is expected and expect this method to throw exception="+throwable.toString()); } --- 125,129 ---- if(log.isLoggable(Level.FINE)){ ! log.log(Level.FINE,"ID="+id+" "+methodName+" is expected and expect this method to throw exception="+throwable); } *************** *** 139,145 **** public CalledMethod expect(String methodName, Behavior behavior, long timeout, Class... params){ ! if(methodName==null) ! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); ! delayTime=timeout; CalledMethod calledMethod=new CalledMethodImpl(methodName); if(!methodsIgnored.containsKey(methodName)){ --- 133,138 ---- public CalledMethod expect(String methodName, Behavior behavior, long timeout, Class... params){ ! checkPreconditions(methodName); ! delayTime = timeout; CalledMethod calledMethod=new CalledMethodImpl(methodName); if(!methodsIgnored.containsKey(methodName)){ *************** *** 147,152 **** behaviorMap.put(methodName,behavior); try { ! Class c=behavior.getClass(); Method method = c.getMethod(methodName,params); methodList.add(method); --- 140,146 ---- behaviorMap.put(methodName,behavior); + Class c = null; try { ! c = behavior.getClass(); Method method = c.getMethod(methodName,params); methodList.add(method); *************** *** 154,163 **** throw new IllegalArgumentException(Messages.METHOD_CAN_NOT_ACCESS); } catch (NoSuchMethodException e) { ! throw new IllegalArgumentException(methodName+"is not defined in your Behvior Implemetation"); } } if(log.isLoggable(Level.FINE)){ ! log.log(Level.FINE,"ID="+id+" "+methodName+" is expected with behavior="+behavior.toString()); } --- 148,172 ---- throw new IllegalArgumentException(Messages.METHOD_CAN_NOT_ACCESS); } catch (NoSuchMethodException e) { ! Method[] methods = c.getMethods(); ! String message = methodName + "("; ! for(Class param : params) ! { ! message += param + ", "; ! } ! message += ") is not defined in your Behavior Implementation\n" + ! "The following methods with the desired name exist:"; ! for(Method method : methods) ! { ! if(method.getName().equals(methodName)) ! { ! message += "\n" + method; ! } ! } ! throw new IllegalArgumentException(message); } } if(log.isLoggable(Level.FINE)){ ! log.log(Level.FINE,"ID="+id+" "+methodName+" is expected with behavior="+behavior); } *************** *** 167,219 **** ! public void verify(){ ! ! 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(); } - } } ! ! 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()); ! m.setStackTrace(calledMethod.getStackTrace()); ! } ! } ! protected Object methodCalledImpl(String methodName, ! Object[] parameters) throws Throwable{ methodName = methodName.intern(); --- 176,293 ---- ! public void verify() ! { ! timeoutOnEmptyExpect(); ! ! // copy this stuff for reporting errors later ! List<CalledMethod> copyMethodsCalled = new LinkedList<CalledMethod>(methodsCalled); ! List<CalledMethod> copyMethodsExpected = new LinkedList<CalledMethod>(methodsExpected); ! Map<String, CalledMethod> copyMethodsIgnored = new HashMap<String, CalledMethod> (methodsIgnored); + while(methodsCalled.size() > 0) + { + log.info("\nmethodsCalled="+ methodsCalled + + "\nmethodsExpected=" + methodsExpected); + + CalledMethod calledMethod = methodsCalled.get(0); + CalledMethodImpl expectedMethod = null; + + if(methodsExpected.size() > 0) + { + expectedMethod = (CalledMethodImpl)methodsExpected.get(0); + + if(calledMethod.getMethodName().equals(expectedMethod.getMethodName())) + { + log.info("called[" + calledMethod + "] == expected[" + expectedMethod + "]... continuing"); + + methodsCalled.remove(0); + methodsExpected.remove(0); + } + else + { + // remove ignored called methods + while(!calledMethod.getMethodName().equals(expectedMethod.getMethodName())) + { + if(methodsIgnored.containsKey(calledMethod.getMethodName())) + // TODO: it seems like we need to verify that the _correct_ method was called here + // since we now differentiate between methods of the same name, but different parameters + // && methodsIgnored.get(calledMethod.getMethodName()).equals(calledMethod)) + { + CalledMethod ignoredMethod = methodsCalled.remove(0); + calledMethod = methodsCalled.get(0); + log.info("ignored method=" + ignoredMethod); + } + else + { + verifyErredOut(Messages.ORDER_EXCEPTION, copyMethodsCalled, copyMethodsExpected, copyMethodsIgnored); + } + } + } + } + else if(methodsIgnored.containsKey(calledMethod.getMethodName())) + { + CalledMethod ignoredMethod = methodsCalled.remove(0); + log.info("ignored method=" + ignoredMethod); + continue; + } + else + { + verifyErredOut(Messages.TOO_MANY_METHODS_CALLED + ": " + calledMethod, + copyMethodsCalled, copyMethodsExpected, copyMethodsIgnored); + } + expectedMethod.setParameters(calledMethod.getParameters()); + expectedMethod.setStackTrace(calledMethod.getStackTrace()); + } + } + + private void timeoutOnEmptyExpect() + { + if(methodsCalled.size() == 0) + { + if(log.isLoggable(Level.FINE)) + { + log.log(Level.FINE, "called methods may be delayed, waiting methods to call..."); + } + synchronized(this) + { + try + { this.wait(delayTime); ! } ! catch(InterruptedException e) ! { e.getMessage(); } } } ! } ! ! private void verifyErredOut(String errorMessage, ! List<CalledMethod> methodsCalled, ! List<CalledMethod> methodsExpected, ! Map<String, CalledMethod> methodsIgnored) ! { ! String message = errorMessage + "\nMethods you expected:"; ! for(CalledMethod method : methodsExpected) ! { ! message += "\n" + method; } ! message += "\n\nMethods you ignored:"; ! Set<String> keys = methodsIgnored.keySet(); ! for(String key : keys) ! { ! message += "\n" + methodsIgnored.get(key); ! } ! message += "\n\nMethods actually called:"; ! for(CalledMethod method : methodsCalled) ! { ! message += "\n" + method; ! } ! message += "\n"; ! throw new ExpectFailedException(message); } ! protected Object methodCalledImpl(String methodName, Object[] parameters) throws Throwable{ ! checkPreconditions(methodName); methodName = methodName.intern(); *************** *** 252,289 **** } } - return getReturnValue(methodName); } private Object getReturnValue(String methodName) { ! if (retVal.containsKey(methodName)) { ! return retVal.get(methodName); } return null; } ! 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); } ! 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); ! ! } --- 326,370 ---- } } return getReturnValue(methodName); } private Object getReturnValue(String methodName) { ! String trimmedMethodName = methodName.trim(); ! checkPreconditions(trimmedMethodName); ! if (retVal.containsKey(trimmedMethodName)) { ! return retVal.get(trimmedMethodName); } return null; } ! public void addIgnoredMethod(String methodName, Class... vargs) { ! String trimmedMethodName = methodName.trim(); ! checkPreconditions(trimmedMethodName); ! CalledMethod calledMethod = new CalledMethodImpl(trimmedMethodName); ! methodsIgnored.put(trimmedMethodName, calledMethod); } ! /** ! * @see biz.xsoftware.mock2.MockObject#addIgnoredMethod(java.lang.Object, java.lang.String, java.lang.Class...) ! */ ! public void addIgnoredMethod(Object returnValue, String methodName, Class... vargs) ! { ! String trimmedMethodName = methodName.trim(); ! checkPreconditions(trimmedMethodName); ! CalledMethod calledMethod = new CalledMethodImpl(trimmedMethodName); ! methodsIgnored.put(trimmedMethodName, calledMethod); ! setDefaultReturnValue(returnValue, trimmedMethodName, vargs); ! } + public void removeIgnoredMethod(String methodName, Class... vargs) { + String trimmedMethodName = methodName.trim(); + checkPreconditions(trimmedMethodName); + methodsIgnored.remove(trimmedMethodName); } ! public void setDefaultReturnValue(Object returnValue, String methodName, Class... vargs) { ! String trimmedMethodName = methodName.trim(); ! checkPreconditions(trimmedMethodName); ! retVal.put(trimmedMethodName, returnValue); } *************** *** 292,294 **** --- 373,382 ---- } + private void checkPreconditions(String methodName) + { + if(methodName == null || "".equals(methodName)) + { + throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL); + } + } } |
From: Christopher B. W. <da...@us...> - 2006-05-02 23:26:37
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23471/input/javasrc/biz/xsoftware/mock2 Modified Files: Messages.java MockObject.java Log Message: Fixed some bugs with method not being ignored correctly. general cleanup Index: MockObject.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/MockObject.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MockObject.java 20 Mar 2006 15:01:20 -0000 1.5 --- MockObject.java 2 May 2006 23:26:34 -0000 1.6 *************** *** 156,160 **** * the optional parameter types of the method call */ ! public void addIgnoreMethod(String methodName, Class... vargs); /** --- 156,172 ---- * the optional parameter types of the method call */ ! public void addIgnoredMethod(String methodName, Class... vargs); ! ! /** ! * Add a method to the ignore list. ! * ! * @param returnValue ! * the default value to return from the method call ! * @param methodName ! * the name of the method to ignore ! * @param vargs ! * the optional parameter types of the method call ! */ ! public void addIgnoredMethod(Object returnValue, String methodName, Class... vargs); /** *************** *** 166,170 **** * the optinal parameter types of the method call */ ! public void removeIgnoreMethod(String methodName, Class... vargs); /** --- 178,182 ---- * the optinal parameter types of the method call */ ! public void removeIgnoredMethod(String methodName, Class... vargs); /** Index: Messages.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/Messages.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Messages.java 6 Apr 2006 15:25:09 -0000 1.5 --- Messages.java 2 May 2006 23:26:34 -0000 1.6 *************** *** 9,15 **** "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"; ! 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"; - } --- 9,14 ---- "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"; ! public static final String TOO_MANY_METHODS_CALLED="Unexpected method called"; public static final String ORDER_EXCEPTION="methods called or methods expected is in wrong order"; } |