mocklib-checkins Mailing List for mocklib (Page 15)
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: Nobody <fas...@us...> - 2006-09-10 18:01:18
|
Update of /cvsroot/mocklib/mocklib/input/javasrc/biz/xsoftware/manifest In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv16469/input/javasrc/biz/xsoftware/manifest Added Files: ManifestUtilImpl.java ManifestInfo.java TestManifestInfo.java Log Message: clean up mocklib 1. It is not 1.4 compatible and is pretty much the final mocklib1 --- NEW FILE: ManifestUtilImpl.java --- /* * Created on Sep 19, 2004 * * FIXME To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package biz.xsoftware.manifest; import java.io.File; import java.net.URL; import java.util.jar.Attributes; import java.util.jar.Manifest; import java.util.logging.Logger; /** * @author Dean Hiller * * FIXME To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class ManifestUtilImpl implements ManifestInfo.ManifestUtil { private static final Logger log = Logger.getLogger(ManifestUtilImpl.class.getName()); public File getFile(URL url) { log.finest("url="+url); String filePart = url.getFile(); log.finest("filePart from url="+filePart); String nameWithClass = filePart.substring(5, filePart.length()); log.finest("nameWithClass="+nameWithClass); int index = nameWithClass.indexOf("!"); log.finest("index="+index); String fileName = nameWithClass.substring(0, index); log.finest("fileName of buildtemplate="+fileName); File f = new File(fileName); if(!f.exists()) { log.warning("Bug, Exiting System. Could not find file="+fileName); System.exit(1); } log.finer("returning file="+f.getAbsolutePath()); return f; } /* (non-Javadoc) * @see biz.xsoftware.manifest.ManifestInfo.SystemInterface#exit(int) */ public void exit(int code) { System.exit(code); } public String getMainClass(Manifest manifest) { Attributes attr = manifest.getMainAttributes(); String s = attr.getValue("SubMain-Class"); return s.trim(); } //dummy main for testing purposes!!! public static void main(String[] args) { log.fine("just throwing an exception for testing purposes"); throw new RuntimeException("Just for testing only"); } } --- NEW FILE: TestManifestInfo.java --- /* * Created on Sep 11, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package biz.xsoftware.manifest; import java.io.File; import java.net.URL; import java.util.jar.Manifest; import junit.framework.TestCase; /** * This is purely so emma always always reports code coverage * numbers on everything */ public class TestManifestInfo extends TestCase { private static final String DUMMY = "dummy"; private File jarFile; /** * @param arg0 */ public TestManifestInfo(String arg0) { super(arg0); } public void setUp() { String jarLoc = System.getProperty("jar.name"); if(jarLoc != null) //for tests run from ant jarFile = new File(jarLoc); else //for tests run from eclipse jarFile = new File("output/jardist/projectname.jar"); } public void testManifestInfo() throws Throwable { FakeJarLocator mock = new FakeJarLocator(jarFile, "should.not.matter.class"); ManifestInfo.setJarLocator(mock); ManifestInfo.main(new String[] {"-version"}); ManifestInfo.main(new String[] {"-manifest"}); String version = new ManifestInfo().getVersion(); assertEquals("version from build.xml should equal version in jar", System.getProperty("version"), version); } public void testRunMainClass() throws Throwable { FakeJarLocator mock = new FakeJarLocator(jarFile, TestManifestInfo.class.getName()); ManifestInfo.setJarLocator(mock); ManifestInfo.main(new String[] {DUMMY}); assertTrue("should have one argument", argsLen == 1); assertEquals("variable should have been passed through", DUMMY, dummyArg); } public void testExceptionFromMainClass() throws Throwable { FakeJarLocator mock = new FakeJarLocator(jarFile, ManifestUtilImpl.class.getName()); ManifestInfo.setJarLocator(mock); ManifestInfo.main(new String[0]); } public void testClassNotFound() throws Throwable { FakeJarLocator mock = new FakeJarLocator(jarFile, "this.class.is.not.found"); ManifestInfo.setJarLocator(mock); ManifestInfo.main(new String[0]); } public void testTOOLSJAVAMain() throws Throwable { FakeJarLocator mock = new FakeJarLocator(jarFile, " TOOLS.JAVA.Main "); ManifestInfo.setJarLocator(mock); ManifestInfo.main(new String[0]); } public void testNullClassName() throws Throwable { FakeJarLocator mock = new FakeJarLocator(jarFile, null); ManifestInfo.setJarLocator(mock); ManifestInfo.main(new String[0]); } public void testGetMainClass() { Manifest mf = new Manifest(); mf.getMainAttributes().putValue("SubMain-Class", " xx "); ManifestUtilImpl util = new ManifestUtilImpl(); String s = util.getMainClass(mf); assertEquals("should have trimmed the value", "xx", s); } public void testGetFile() throws Exception { File f = jarFile; assertTrue("file should exist before we test this", f.exists()); URL url = f.toURL(); URL urlToClassFile = new URL("file", null, -1, url+"!/biz/xsoftware/buildtemplate/Util.class"); File tmp = new ManifestUtilImpl().getFile(urlToClassFile); assertNotNull("Should return a real file", tmp); assertTrue("file should still exist", tmp.exists()); } private class FakeJarLocator implements ManifestInfo.ManifestUtil { private File file; private String mainClass; public FakeJarLocator(File f, String mainClass) { this.file = f; this.mainClass = mainClass; } public File getFile(URL url) { return file; } public void exit(int code) { //do nothing!!! } public String getMainClass(Manifest manifest) { return mainClass; } } //dummy main method for testing!!! public static void main(String[] args) { argsLen = args.length; dummyArg = args[0]; } private static int argsLen; private static String dummyArg; } --- NEW FILE: ManifestInfo.java --- /* * Created on Jul 9, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package biz.xsoftware.manifest; import java.io.File; import java.io.IOException; import java.lang.reflect.Method; import java.net.URL; import java.util.Iterator; import java.util.Set; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; import java.util.logging.Level; import java.util.logging.Logger; /** * Miscellaneous class that just prints the version of the mock object jar * getting it from the manifest file. * * @author Dean Hiller */ public class ManifestInfo { private static final Logger log = Logger.getLogger(ManifestInfo.class.getName()); private static ManifestUtil util = new ManifestUtilImpl(); //private Package thePackage; private Manifest manifest; /** * The main program for Version that prints the version info from * the manifest file. * * java -jar xxx.jar * 1. runs SubMain-Class in manifest file * 2. If SubMain-Class is default value or "", prints usage info * for -manifest and -version * * java -jar xxx.jar -version * 1. prints version info * * java -jar xxx.jar -manifest * 1. prints all manifest contents. * * @param args Ignores all arguments. */ public static void main(String[] args) throws Throwable { try { run(args); } catch(Throwable e) { log.log(Level.WARNING, "Exception occurred", e); throw e; } } public static void run(String[] args) throws IOException { ManifestInfo manifestInfo = new ManifestInfo(); if(args.length > 0) { if("-manifest".equals(args[0])) { System.out.println(""+manifestInfo); return; } else if("-version".equals(args[0])) { System.out.println(manifestInfo.getFullVersionInfo()); return; } } String className = util.getMainClass(manifestInfo.getManifest()); if(className == null) className = ""; if("TOOLS.JAVA.Main".equals(className.trim()) || "".equals(className)) { System.err.println("Usage:"); System.err.println("1. java -jar <jarfile> -version"); System.err.println("2. java -jar <jarfile> -manifest"); } else { runProgram(className, args); } util.exit(1); } static void runProgram(String className, String[] args) { String msg = ""; ClassLoader cl = ManifestInfo.class.getClassLoader(); try { Class c = cl.loadClass(className); log.finest("class="+c); Method m = c.getMethod("main", new Class[] {String[].class}); m.invoke(null, new Object[] { args }); } catch(ClassNotFoundException e) { msg = "Class in manifest not found in classpath\n" +"Fix the ant.properties file to refer to the\n" +"main class or refer to nothing\n" +"class="+className; System.out.println(msg); } catch(NoSuchMethodException e) { msg = "You have specified a class that doesn't" +"have a main method in ant.properties file." +"class="+className; System.out.println(msg); } catch(Exception e) { msg = "\n\n2. Unknown failure. Contact buildtemplate owner"; log.log(Level.WARNING, "Exception occurred", e); System.out.println(msg); } util.exit(1); } public static void setJarLocator(ManifestUtil l) { util = l; } /** * Constructor that takes a class to get the version information * from out of the manifest. Uses the class's package to retrieve * the manifest version info. */ public ManifestInfo() throws IOException { URL url = ManifestInfo.class.getResource("ManifestInfo.class"); //set manifest from jar file File f = util.getFile(url); JarFile jarFile = new JarFile(f); manifest = jarFile.getManifest(); //set the package of this guy(not really needed as we could get all this info //directly from manifest) //String name = ManifestInfo.class.getName(); //int index = name.lastIndexOf("."); //String packageName = name.substring(0, index); //thePackage = Package.getPackage(packageName); } private Manifest getManifest() { return manifest; } public String getVersion() { Attributes attr = manifest.getMainAttributes(); String version = attr.getValue("Implementation-Version"); version = version.trim(); int index = version.indexOf(" "); version = version.substring(0, index); return version; } public String getFullVersionInfo() { Attributes attr = manifest.getMainAttributes(); String retVal = attr.getValue("Implementation-Title")+" information..."; retVal += "\nwebsite= "+attr.getValue("Implementation-Vendor"); retVal += "\nbuilt by= "+attr.getValue("Built-By"); retVal += "\nclasspath= "+attr.getValue("Class-Path"); retVal += "\nversion= "+attr.getValue("Implementation-Version")+"\n"; return retVal; } /** * Prints the version info the Version represents. * * @see java.lang.Object#toString() */ public String toString() { String manifestInfo = "\nManifest information...\n"; Attributes attr = manifest.getMainAttributes(); Set s = attr.keySet(); Iterator iter = s.iterator(); while(iter.hasNext()) { Object o = iter.next(); manifestInfo += o+"="+attr.get(o)+"\n"; } return manifestInfo; } public interface ManifestUtil { public File getFile(URL url); public String getMainClass(Manifest manifest); public void exit(int code); } } |
From: Nobody <fas...@us...> - 2006-09-10 18:01:15
|
Update of /cvsroot/mocklib/mocklib/input/javasrc/biz/xsoftware/manifest In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv16439/input/javasrc/biz/xsoftware/manifest Log Message: Directory /cvsroot/mocklib/mocklib/input/javasrc/biz/xsoftware/manifest added to the repository |
From: Nobody <fas...@us...> - 2006-09-10 18:01:10
|
Update of /cvsroot/mocklib/mocklib/.settings In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv16439/.settings Log Message: Directory /cvsroot/mocklib/mocklib/.settings added to the repository |
From: Nobody <fas...@us...> - 2006-09-10 17:41:34
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv8021/input/javasrc/biz/xsoftware/test/mock Modified Files: TestMockCreator.java Removed Files: NewBehavior.java Log Message: back out changes for new behavior. Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TestMockCreator.java 10 Sep 2006 17:18:39 -0000 1.10 --- TestMockCreator.java 10 Sep 2006 17:41:29 -0000 1.11 *************** *** 275,308 **** assertEquals(newBytes[i], newBytes[i+4]); } ! } ! ! public void testNewBehavior() { ! // MockObject mock = MockObjectFactory.createMock(Identical.class); ! // ! // mock.addBehavior("doThat", new NewBehavior()); ! // ! // Identical ident = (Identical)mock; ! // ! // byte[] original = new byte[] { 1, 2, 3, 4, 0, 0, 0, 0}; ! // byte[] bytes = new byte[] { 1, 2, 3, 4, 0 ,0,0,0}; ! // ! // byte[] newBytes = ident.doThat(bytes); ! // ! // CalledMethod m = mock.expect("doThat"); ! // byte[] passedIn = (byte[])m.getAllParams()[0]; ! // ! // assertEquals(original.length, passedIn.length); ! // for(int i = 0; i < original.length; i++) { ! // assertEquals(original[i], passedIn[i]); ! // } ! // ! // //make sure this is the same byte array we passed in ! // assertSame(bytes, newBytes); ! // ! // for(int i = 0; i < 4; i++) { ! // assertEquals(newBytes[i], newBytes[i+4]); ! // } ! } ! public void testAddRemoveIgnore() --- 275,279 ---- assertEquals(newBytes[i], newBytes[i+4]); } ! } public void testAddRemoveIgnore() --- NewBehavior.java DELETED --- |
From: Nobody <fas...@us...> - 2006-09-10 17:41:34
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv8021/input/javasrc/biz/xsoftware/mock Modified Files: Behavior.java MockObject.java MockSuperclass.java Removed Files: MethodBehavior.java Log Message: back out changes for new behavior. Index: Behavior.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/Behavior.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Behavior.java 10 Sep 2006 17:18:39 -0000 1.3 --- Behavior.java 10 Sep 2006 17:41:29 -0000 1.4 *************** *** 6,17 **** /** * Use MethodBehavior interface instead of Behavior interface - * @deprecated */ ! public interface Behavior extends MethodBehavior { /** ! * Use MethodBehavior interface instead of Behavior interface ! * ! * @deprecated * @param params * @return --- 6,14 ---- /** * Use MethodBehavior interface instead of Behavior interface */ ! public interface Behavior { /** ! * @param params * @return *************** *** 20,26 **** /** - * Use MethodBehavior interface instead of Behavior interface - * - * @deprecated * @param params */ --- 17,20 ---- Index: MockSuperclass.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockSuperclass.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MockSuperclass.java 10 Sep 2006 17:18:39 -0000 1.14 --- MockSuperclass.java 10 Sep 2006 17:41:29 -0000 1.15 *************** *** 244,249 **** if(retVal instanceof Behavior) { return ((Behavior)retVal).runMethod(params); - } else if(retVal instanceof MethodBehavior) { - throw new UnsupportedOperationException("Not supported yet, use Behavior instead of MethodBehavior"); } else if(retVal instanceof Throwable) { Throwable t = (Throwable)retVal; --- 244,247 ---- *************** *** 677,681 **** } ! public void addBehavior(String method, MethodBehavior behavior) { if(method == null) throw new IllegalArgumentException("method parameter cannot be null"); --- 675,679 ---- } ! public void addBehavior(String method, Behavior behavior) { if(method == null) throw new IllegalArgumentException("method parameter cannot be null"); Index: MockObject.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObject.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MockObject.java 10 Sep 2006 17:18:39 -0000 1.7 --- MockObject.java 10 Sep 2006 17:41:29 -0000 1.8 *************** *** 172,176 **** public int getExpectTimeout(); ! public void addBehavior(String string, MethodBehavior behavior); } --- 172,176 ---- public int getExpectTimeout(); ! public void addBehavior(String string, Behavior behavior); } --- MethodBehavior.java DELETED --- |
From: Nobody <fas...@us...> - 2006-09-10 17:18:47
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv30736/input/javasrc/biz/xsoftware/test/mock Modified Files: TestMockCreator.java Added Files: OldBehavior.java NewBehavior.java Log Message: starting addition of newbehavior. --- NEW FILE: OldBehavior.java --- /** * */ package biz.xsoftware.test.mock; import biz.xsoftware.mock.Behavior; class OldBehavior implements Behavior { /** * @see biz.xsoftware.mock.Behavior#clone(java.lang.Object[]) */ public Object[] clone(Object[] params) { Object[] retVal = new Object[params.length]; for(int i = 0; i < retVal.length; i++) { Object val = params[i]; if(val instanceof byte[]) { retVal[i] = cloneBytes((byte[])val); } } return retVal; } private Object cloneBytes(byte[] bytes) { byte[] newBytes = new byte[bytes.length]; for(int i = 0; i < newBytes.length; i++) { newBytes[i] = bytes[i]; } return newBytes; } /** * @see biz.xsoftware.mock.Behavior#runMethod(java.lang.Object[]) */ public Object runMethod(Object[] params) { //we know the test does an 4 byte array, so do that byte[] bytes = (byte[])params[0]; for(int i = 0; i < 4; i++) { bytes[i+4] = bytes[i]; } //make sure to return the same byte buffer so we are really testing this... return bytes; } } Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TestMockCreator.java 1 Sep 2006 17:07:23 -0000 1.9 --- TestMockCreator.java 10 Sep 2006 17:18:39 -0000 1.10 *************** *** 12,16 **** import junit.framework.TestSuite; import junit.textui.TestRunner; - import biz.xsoftware.mock.Behavior; import biz.xsoftware.mock.CalledMethod; import biz.xsoftware.mock.ExpectFailedException; --- 12,15 ---- *************** *** 253,257 **** MockObject mock = MockObjectFactory.createMock(Identical.class); ! mock.addBehavior("doThat", new MyBehavior()); Identical ident = (Identical)mock; --- 252,256 ---- MockObject mock = MockObjectFactory.createMock(Identical.class); ! mock.addBehavior("doThat", new OldBehavior()); Identical ident = (Identical)mock; *************** *** 278,281 **** --- 277,309 ---- } + public void testNewBehavior() { + // MockObject mock = MockObjectFactory.createMock(Identical.class); + // + // mock.addBehavior("doThat", new NewBehavior()); + // + // Identical ident = (Identical)mock; + // + // byte[] original = new byte[] { 1, 2, 3, 4, 0, 0, 0, 0}; + // byte[] bytes = new byte[] { 1, 2, 3, 4, 0 ,0,0,0}; + // + // byte[] newBytes = ident.doThat(bytes); + // + // CalledMethod m = mock.expect("doThat"); + // byte[] passedIn = (byte[])m.getAllParams()[0]; + // + // assertEquals(original.length, passedIn.length); + // for(int i = 0; i < original.length; i++) { + // assertEquals(original[i], passedIn[i]); + // } + // + // //make sure this is the same byte array we passed in + // assertSame(bytes, newBytes); + // + // for(int i = 0; i < 4; i++) { + // assertEquals(newBytes[i], newBytes[i+4]); + // } + } + + public void testAddRemoveIgnore() { *************** *** 295,342 **** } ! private static class MyBehavior implements Behavior { ! ! /** ! * @see biz.xsoftware.mock.Behavior#clone(java.lang.Object[]) ! */ ! public Object[] clone(Object[] params) ! { ! Object[] retVal = new Object[params.length]; ! for(int i = 0; i < retVal.length; i++) { ! Object val = params[i]; ! if(val instanceof byte[]) { ! retVal[i] = cloneBytes((byte[])val); ! } ! } ! return retVal; ! } ! ! private Object cloneBytes(byte[] bytes) ! { ! byte[] newBytes = new byte[bytes.length]; ! for(int i = 0; i < newBytes.length; i++) { ! newBytes[i] = bytes[i]; ! } ! return newBytes; ! } ! ! /** ! * @see biz.xsoftware.mock.Behavior#runMethod(java.lang.Object[]) ! */ ! public Object runMethod(Object[] params) ! { ! //we know the test does an 4 byte array, so do that ! byte[] bytes = (byte[])params[0]; ! for(int i = 0; i < 4; i++) { ! bytes[i+4] = bytes[i]; ! } ! ! //make sure to return the same byte buffer so we are really testing this... ! return bytes; ! } ! ! } ! ! public static void main(String[] args) { TestSuite suite = new TestSuite(); suite.addTest(new TestMockCreator("testWrongMethod")); --- 323,327 ---- } ! public static void main(String[] args) { TestSuite suite = new TestSuite(); suite.addTest(new TestMockCreator("testWrongMethod")); --- NEW FILE: NewBehavior.java --- /** * */ package biz.xsoftware.test.mock; import biz.xsoftware.mock.MethodBehavior; class NewBehavior implements MethodBehavior { /** * @see biz.xsoftware.mock.Behavior#clone(java.lang.Object[]) */ public Object[] doThatClone(Object[] params) { Object[] retVal = new Object[params.length]; for(int i = 0; i < retVal.length; i++) { Object val = params[i]; if(val instanceof byte[]) { retVal[i] = cloneBytes((byte[])val); } } return retVal; } private Object cloneBytes(byte[] bytes) { byte[] newBytes = new byte[bytes.length]; for(int i = 0; i < newBytes.length; i++) { newBytes[i] = bytes[i]; } return newBytes; } /** * @see biz.xsoftware.mock.Behavior#runMethod(java.lang.Object[]) */ public byte[] doThat(byte[] bytes) { for(int i = 0; i < 4; i++) { bytes[i+4] = bytes[i]; } //make sure to return the same byte buffer so we are really testing this... return bytes; } } |
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv30736/input/javasrc/biz/xsoftware/mock Modified Files: Behavior.java MockObject.java MockSuperclass.java MockObjectImpl.java Added Files: MethodBehavior.java Log Message: starting addition of newbehavior. Index: Behavior.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/Behavior.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Behavior.java 7 Aug 2006 15:52:45 -0000 1.2 --- Behavior.java 10 Sep 2006 17:18:39 -0000 1.3 *************** *** 5,18 **** /** ! * 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 */ --- 5,26 ---- /** ! * Use MethodBehavior interface instead of Behavior interface ! * @deprecated */ ! public interface Behavior extends MethodBehavior { + /** + * Use MethodBehavior interface instead of Behavior interface + * + * @deprecated + * @param params + * @return + */ public Object[] clone(Object[] params); /** ! * Use MethodBehavior interface instead of Behavior interface * + * @deprecated * @param params */ Index: MockSuperclass.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockSuperclass.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** MockSuperclass.java 25 Aug 2006 22:31:55 -0000 1.13 --- MockSuperclass.java 10 Sep 2006 17:18:39 -0000 1.14 *************** *** 244,247 **** --- 244,249 ---- if(retVal instanceof Behavior) { return ((Behavior)retVal).runMethod(params); + } else if(retVal instanceof MethodBehavior) { + throw new UnsupportedOperationException("Not supported yet, use Behavior instead of MethodBehavior"); } else if(retVal instanceof Throwable) { Throwable t = (Throwable)retVal; *************** *** 675,679 **** } ! public void addBehavior(String method, Behavior behavior) { if(method == null) throw new IllegalArgumentException("method parameter cannot be null"); --- 677,681 ---- } ! public void addBehavior(String method, MethodBehavior behavior) { if(method == null) throw new IllegalArgumentException("method parameter cannot be null"); Index: MockObject.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObject.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MockObject.java 25 Aug 2006 19:42:09 -0000 1.6 --- MockObject.java 10 Sep 2006 17:18:39 -0000 1.7 *************** *** 172,176 **** public int getExpectTimeout(); ! public void addBehavior(String string, Behavior behavior); } --- 172,176 ---- public int getExpectTimeout(); ! public void addBehavior(String string, MethodBehavior behavior); } Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObjectImpl.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** MockObjectImpl.java 1 Sep 2006 17:07:24 -0000 1.11 --- MockObjectImpl.java 10 Sep 2006 17:18:39 -0000 1.12 *************** *** 26,31 **** private Class[] classes; - Class<?>[] primitiveTypes = {Integer.TYPE, Double.TYPE, Float.TYPE, Boolean.TYPE, - Character.TYPE, Byte.TYPE, Short.TYPE, Long.TYPE}; static { //reflect and find all the methods of the superclass. --- 26,29 ---- *************** *** 87,91 **** if(!primitiveClass.isInstance(o)) throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n" ! +"You specified a return type of="+o.getClass()+" which needs to be or extend type="+returnType); } else if(!returnType.isInstance(o)) //if not a primitive, make sure is assignable.... throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n" --- 85,90 ---- if(!primitiveClass.isInstance(o)) throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n" ! +"You specified a return type of="+o.getClass() ! +" which needs to be or extend type="+returnType); } else if(!returnType.isInstance(o)) //if not a primitive, make sure is assignable.... throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n" --- NEW FILE: MethodBehavior.java --- package biz.xsoftware.mock; public interface MethodBehavior { } |
From: Nobody <fas...@us...> - 2006-09-01 17:07:33
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6967/input/javasrc/biz/xsoftware/test/mock2 Removed Files: TestVerify.java TestProxyClass.java FakeSystem.java MyProxyImpl.java MyBehavior.java ListenerOne.java TestMockCreator.java TestIgnoredMethods.java Log Message: fix mocklib and delete mocklib2 --- TestIgnoredMethods.java DELETED --- --- TestMockCreator.java DELETED --- --- MyBehavior.java DELETED --- --- TestProxyClass.java DELETED --- --- ListenerOne.java DELETED --- --- MyProxyImpl.java DELETED --- --- TestVerify.java DELETED --- --- FakeSystem.java DELETED --- |
From: Nobody <fas...@us...> - 2006-09-01 17:07:30
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6967/input/javasrc/biz/xsoftware/mock Modified Files: MockObjectImpl.java Log Message: fix mocklib and delete mocklib2 Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObjectImpl.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** MockObjectImpl.java 1 Sep 2006 16:31:43 -0000 1.10 --- MockObjectImpl.java 1 Sep 2006 17:07:24 -0000 1.11 *************** *** 10,14 **** --- 10,17 ---- import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; + import java.lang.reflect.Type; + import java.util.HashMap; import java.util.HashSet; + import java.util.Map; import java.util.Set; *************** *** 20,25 **** --- 23,31 ---- private static Set<Method> isMethodInSuper = new HashSet<Method>(); + private static Map<Type, Class> primitiveToClass = new HashMap<Type, Class>(); private Class[] classes; + Class<?>[] primitiveTypes = {Integer.TYPE, Double.TYPE, Float.TYPE, Boolean.TYPE, + Character.TYPE, Byte.TYPE, Short.TYPE, Long.TYPE}; static { //reflect and find all the methods of the superclass. *************** *** 34,37 **** --- 40,52 ---- isMethodInSuper.add(m[i]); } + + primitiveToClass.put(Integer.TYPE, Integer.class); + primitiveToClass.put(Double.TYPE, Double.class); + primitiveToClass.put(Float.TYPE, Float.class); + primitiveToClass.put(Boolean.TYPE, Boolean.class); + primitiveToClass.put(Character.TYPE, Character.class); + primitiveToClass.put(Byte.TYPE, Byte.class); + primitiveToClass.put(Short.TYPE, Short.class); + primitiveToClass.put(Long.TYPE, Long.class); } *************** *** 58,62 **** //The return type is void if(o != null) ! throw new IllegalArgumentException("You are trying to return something on a method that returns void. Method="+methodString+" value you tried to return="+o); } else { //Return type is not void...(could be primitive or Object) --- 73,78 ---- //The return type is void if(o != null) ! throw new IllegalArgumentException("You are trying to return something on a method that returns void.\n" + ! "Method="+methodString+" value you tried to return="+o); } else { //Return type is not void...(could be primitive or Object) *************** *** 66,70 **** throw new IllegalArgumentException("Must call addReturnValue and " + "specify a non-null value as method="+methodString+" returns a primitive value"); ! } else if(!returnType.isInstance(o)) throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n" +"You specified a return type of="+o.getClass()+" which needs to be or extend type="+returnType); --- 82,92 ---- throw new IllegalArgumentException("Must call addReturnValue and " + "specify a non-null value as method="+methodString+" returns a primitive value"); ! } else if(returnType.isPrimitive()) { ! //TODO: this is not working correctly no matter what I do here..... ! Class primitiveClass = primitiveToClass.get(returnType); ! if(!primitiveClass.isInstance(o)) ! throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n" ! +"You specified a return type of="+o.getClass()+" which needs to be or extend type="+returnType); ! } else if(!returnType.isInstance(o)) //if not a primitive, make sure is assignable.... throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n" +"You specified a return type of="+o.getClass()+" which needs to be or extend type="+returnType); *************** *** 73,76 **** --- 95,99 ---- return o; } + /** * @param method |
From: Nobody <fas...@us...> - 2006-09-01 17:07:27
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6967/input/javasrc/biz/xsoftware/test/mock Modified Files: TestMockCreator.java Log Message: fix mocklib and delete mocklib2 Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TestMockCreator.java 1 Sep 2006 16:31:43 -0000 1.8 --- TestMockCreator.java 1 Sep 2006 17:07:23 -0000 1.9 *************** *** 239,242 **** --- 239,252 ---- } } + + public void testPrimitive() { + MockObject mock = MockObjectFactory.createMock(Car.class); + + Car car = (Car)mock; + mock.addReturnValue("getWheelCount", new Integer(5)); + car.getWheelCount(); + + mock.expect("getWheelCount"); + } public void testBehavior() { |
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/advanced In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6967/input/javasrc/biz/xsoftware/examples/mock2/advanced Removed Files: User.java TaskRecordService.java TestExample.java SysUnderTest.java Location.java TaskSystem.java Log Message: fix mocklib and delete mocklib2 --- TaskSystem.java DELETED --- --- TestExample.java DELETED --- --- SysUnderTest.java DELETED --- --- TaskRecordService.java DELETED --- --- User.java DELETED --- --- Location.java DELETED --- |
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2 In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6967/input/javasrc/biz/xsoftware/mock2 Removed Files: ExpectFailedException.java MockObjectFactory.java MockObject.java Messages.java CalledMethod.java Behavior.java Log Message: fix mocklib and delete mocklib2 --- MockObjectFactory.java DELETED --- --- Messages.java DELETED --- --- ExpectFailedException.java DELETED --- --- Behavior.java DELETED --- --- CalledMethod.java DELETED --- --- MockObject.java DELETED --- |
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/basic In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6967/input/javasrc/biz/xsoftware/examples/mock2/basic Removed Files: TestExample.java CreditAuthorizationSvc.java PurchaseException.java SysUnderTest.java GiftCardAccountSvc.java Log Message: fix mocklib and delete mocklib2 --- PurchaseException.java DELETED --- --- GiftCardAccountSvc.java DELETED --- --- TestExample.java DELETED --- --- CreditAuthorizationSvc.java DELETED --- --- SysUnderTest.java DELETED --- |
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6967/input/javasrc/biz/xsoftware/mock2/impl Removed Files: MockObjectSuperImpl.java MockObjectImpl.java CalledMethodImpl.java MockObjectFactoryImpl.java Log Message: fix mocklib and delete mocklib2 --- CalledMethodImpl.java DELETED --- --- MockObjectImpl.java DELETED --- --- MockObjectFactoryImpl.java DELETED --- --- MockObjectSuperImpl.java DELETED --- |
From: Nobody <fas...@us...> - 2006-09-01 16:31:49
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv24439/input/javasrc/biz/xsoftware/mock Modified Files: MockObjectImpl.java Log Message: fix mocklib bug. Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObjectImpl.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** MockObjectImpl.java 25 Aug 2006 22:31:55 -0000 1.9 --- MockObjectImpl.java 1 Sep 2006 16:31:43 -0000 1.10 *************** *** 51,135 **** 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 + ! " 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); ! } /** --- 51,142 ---- Class returnType = method.getReturnType(); ! if(returnType == null) ! throw new RuntimeException("This is a bug or something"); ! ! String methodString = getCleanMethodString(method); ! if(returnType.equals(void.class)) { ! //The return type is void ! if(o != null) ! throw new IllegalArgumentException("You are trying to return something on a method that returns void. Method="+methodString+" value you tried to return="+o); ! } else { ! //Return type is not void...(could be primitive or Object) ! ! if(o == null) { ! if(returnType.isPrimitive()) ! throw new IllegalArgumentException("Must call addReturnValue and " + ! "specify a non-null value as method="+methodString+" returns a primitive value"); ! } else if(!returnType.isInstance(o)) ! throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n" ! +"You specified a return type of="+o.getClass()+" which needs to be or extend type="+returnType); } + return o; } ! /** ! * @param method ! * @return ! */ ! private String getCleanMethodString(Method method) { ! String retType = method.getReturnType().getName(); ! String methodArgs = retType+" "+method.getName()+"("; ! 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 += ", "; } + return methodArgs+")"; } + ! // 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); ! // } /** |
From: Nobody <fas...@us...> - 2006-09-01 16:31:49
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv24439/input/javasrc/biz/xsoftware/test/mock Modified Files: Car.java TestMockCreator.java Added Files: CarImpl.java Log Message: fix mocklib bug. Index: Car.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/Car.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Car.java 1 Jan 2006 00:35:56 -0000 1.1 --- Car.java 1 Sep 2006 16:31:43 -0000 1.2 *************** *** 18,20 **** --- 18,21 ---- public void closeDoor(); + public int getWheelCount(); } Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TestMockCreator.java 25 Aug 2006 22:31:55 -0000 1.7 --- TestMockCreator.java 1 Sep 2006 16:31:43 -0000 1.8 *************** *** 8,11 **** --- 8,12 ---- import java.io.IOException; + import junit.framework.TestCase; import junit.framework.TestSuite; *************** *** 14,19 **** import biz.xsoftware.mock.CalledMethod; import biz.xsoftware.mock.ExpectFailedException; - import biz.xsoftware.mock.MockObjectFactory; import biz.xsoftware.mock.MockObject; /** --- 15,20 ---- import biz.xsoftware.mock.CalledMethod; import biz.xsoftware.mock.ExpectFailedException; import biz.xsoftware.mock.MockObject; + import biz.xsoftware.mock.MockObjectFactory; /** *************** *** 164,168 **** } ! public void testDefaultReturnWithOtherReturns() { MockObject mock = MockObjectFactory.createMock(Identical.class); --- 165,169 ---- } ! public void testDefaultReturnWithOtherReturns() { MockObject mock = MockObjectFactory.createMock(Identical.class); *************** *** 191,194 **** --- 192,243 ---- } + + public void testReturnInterface() { + MockObject mock = MockObjectFactory.createMock(FactoryInterface.class); + + FactoryInterface factory = (FactoryInterface)mock; + + mock.addReturnValue("createCar", new CarImpl()); + Car car = factory.createCar("id"); + + assertEquals(car.getClass(), CarImpl.class); + + mock.expect("createCar"); + } + + + public void testReturnNull() { + MockObject mock = MockObjectFactory.createMock(FactoryInterface.class); + + FactoryInterface factory = (FactoryInterface)mock; + + factory.createCar("aaa"); + + mock.expect("createCar"); + } + + public void testBadPrimitive() { + MockObject mock = MockObjectFactory.createMock(Car.class); + + Car car = (Car)mock; + try { + mock.addReturnValue("getWheelCount", new Long(56)); + car.getWheelCount(); + fail("should have thrown exception"); + } catch(IllegalArgumentException e) { + } + } + + public void testNullPrimitive() { + MockObject mock = MockObjectFactory.createMock(Car.class); + + Car car = (Car)mock; + try { + car.getWheelCount(); + fail("should have thrown exception"); + } catch(IllegalArgumentException e) { + } + } + public void testBehavior() { MockObject mock = MockObjectFactory.createMock(Identical.class); --- NEW FILE: CarImpl.java --- /** * Copyright (C) 2006 Carrier Access, Corp. */ package biz.xsoftware.test.mock; /** */ public class CarImpl implements Car { /** * @see biz.xsoftware.test.mock.Car#openDoor() */ public void openDoor() { } /** * @see biz.xsoftware.test.mock.Car#closeDoor() */ public void closeDoor() { } /** * @see biz.xsoftware.test.mock.Car#getWheelCount() */ public int getWheelCount() { return 0; } } |
From: dadrox <da...@us...> - 2006-08-25 22:31:59
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv10562/input/javasrc/biz/xsoftware/mock Modified Files: MockObjectImpl.java MockSuperclass.java Log Message: add/removeIgnore works now Index: MockSuperclass.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockSuperclass.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** MockSuperclass.java 25 Aug 2006 19:42:09 -0000 1.12 --- MockSuperclass.java 25 Aug 2006 22:31:55 -0000 1.13 *************** *** 24,31 **** * This class will also return the parameters that were passed into the MockObject * so they can be introspected in testing to make sure they were correct. ! * * The MockObject extending this class can also be told to throw exceptions on certain * methods so we can test error leg behavior. ! * * Example of how to use * MockActionListener implements ActionListener and extends this class --- 24,31 ---- * This class will also return the parameters that were passed into the MockObject * so they can be introspected in testing to make sure they were correct. ! * * The MockObject extending this class can also be told to throw exceptions on certain * methods so we can test error leg behavior. ! * * Example of how to use * MockActionListener implements ActionListener and extends this class *************** *** 38,42 **** * } * </PRE> ! * * In the test, when you expect an ActionEvent, you can call * <PRE> --- 38,42 ---- * } * </PRE> ! * * In the test, when you expect an ActionEvent, you can call * <PRE> *************** *** 45,55 **** * assertNonNull(evt.getSource()); * </PRE> ! * * Another useful behavior is throwing any type of exception using * setExceptionOnMethod(String method, Throwable e). This can test * robustness in a system to make sure listeners or services that ! * throw exceptions don't affect your system, or at least affect * your system in the proper way. ! * * @author Dean Hiller (de...@xs...) */ --- 45,55 ---- * assertNonNull(evt.getSource()); * </PRE> ! * * Another useful behavior is throwing any type of exception using * setExceptionOnMethod(String method, Throwable e). This can test * robustness in a system to make sure listeners or services that ! * throw exceptions don't affect your system, or at least affect * your system in the proper way. ! * * @author Dean Hiller (de...@xs...) */ *************** *** 62,66 **** */ private List<CalledMethod> methodsCalled = new LinkedList<CalledMethod>(); ! /** * A map of queues, containing either --- 62,66 ---- */ private List<CalledMethod> methodsCalled = new LinkedList<CalledMethod>(); ! /** * A map of queues, containing either *************** *** 75,83 **** */ private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>(); ! private List<String> ignoredMethods = new ArrayList<String>(); ! private Cloner cloner; ! /** * Default wait time to wait for a method to be called once expectCall is --- 75,83 ---- */ private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>(); ! private List<String> ignoredMethods = new ArrayList<String>(); ! private Cloner cloner; ! /** * Default wait time to wait for a method to be called once expectCall is *************** *** 90,94 **** /** ! * Default constructor of superclass of all mockObjects with a delay of * 10 seconds. This delay is the amount of time the mock object waits for * a method to be called when a client calls expectCall. --- 90,94 ---- /** ! * Default constructor of superclass of all mockObjects with a delay of * 10 seconds. This delay is the amount of time the mock object waits for * a method to be called when a client calls expectCall. *************** *** 100,104 **** * such that the mock object will give methods a longer time to be called * before timing out to fail the test. ! * * @param delay The amount of time in milliseconds to wait for a method to be * called. --- 100,104 ---- * such that the mock object will give methods a longer time to be called * before timing out to fail the test. ! * * @param delay The amount of time in milliseconds to wait for a method to be * called. *************** *** 107,115 **** waitTime = delay; } ! public MockSuperclass(String id) { this.id = id; } ! public void setExpectTimeout(int delay) { this.waitTime = delay; --- 107,115 ---- waitTime = delay; } ! public MockSuperclass(String id) { this.id = id; } ! public void setExpectTimeout(int delay) { this.waitTime = delay; *************** *** 118,142 **** return waitTime; } ! public void addIgnore(String method) { ignoreImpl(method); } ! public void addIgnore(String ... methods) { ignoreImpl(methods); } ! public void removeIgnore(String method) { removeIgnoreImpl(method); } ! public void removeIgnore(String ... methods) { removeIgnoreImpl(methods); } ! private void removeIgnoreImpl(String ... methods) { --- 118,142 ---- return waitTime; } ! public void addIgnore(String method) { ignoreImpl(method); } ! public void addIgnore(String ... methods) { ignoreImpl(methods); } ! public void removeIgnore(String method) { removeIgnoreImpl(method); } ! public void removeIgnore(String ... methods) { removeIgnoreImpl(methods); } ! private void removeIgnoreImpl(String ... methods) { *************** *** 146,160 **** } } ! private void ignoreImpl(String ... methods) { addIgnoredMethods(methods); } ! public void addIgnoredMethods(String[] methods) { if(methods == null) return; verifyMethodsExist(methods); ! for(String method : methods) { --- 146,160 ---- } } ! private void ignoreImpl(String ... methods) { addIgnoredMethods(methods); } ! public void addIgnoredMethods(String[] methods) { if(methods == null) return; verifyMethodsExist(methods); ! for(String method : methods) { *************** *** 162,172 **** } } ! public void setIgnoredMethods(String[] methods) { if(methods == null) ! ignoredMethods = new ArrayList<String>(); verifyMethodsExist(methods); ! for(String method : methods) { --- 162,173 ---- } } ! public void setIgnoredMethods(String[] methods) { if(methods == null) ! return; ! ignoredMethods = new ArrayList<String>(); verifyMethodsExist(methods); ! for(String method : methods) { *************** *** 174,183 **** } } ! /** * Subclasses should call this method when a method on their interface * is called. This method is for users to create subclasses and call so * they don't have to wrap it in a try-catch block. ! * * @param method * @param parameters --- 175,184 ---- } } ! /** * Subclasses should call this method when a method on their interface * is called. This method is for users to create subclasses and call so * they don't have to wrap it in a try-catch block. ! * * @param method * @param parameters *************** *** 197,201 **** } } ! protected synchronized Object methodCalledImpl(String method, Object[] parameters) throws Throwable { method = method.intern(); --- 198,202 ---- } } ! protected synchronized Object methodCalledImpl(String method, Object[] parameters) throws Throwable { method = method.intern(); *************** *** 213,220 **** if (log.isLoggable(Level.FINE)) log.log(Level.FINE, id+"method called="+method+"("+params+") on obj="+this); ! ! //sometimes, the contract is for the "code" to give a parameter ! //to a library and then modify the parameter after the library ! //is done with it. This means the object the "code" gave to //the MockObject will change out from under the MockObject and be //corrupted meaning you can't write a test to test the contract --- 214,221 ---- if (log.isLoggable(Level.FINE)) log.log(Level.FINE, id+"method called="+method+"("+params+") on obj="+this); ! ! //sometimes, the contract is for the "code" to give a parameter ! //to a library and then modify the parameter after the library ! //is done with it. This means the object the "code" gave to //the MockObject will change out from under the MockObject and be //corrupted meaning you can't write a test to test the contract *************** *** 222,228 **** Object[] newParams = clone(method, parameters); methodsCalled.add(new CalledMethod(method, newParams, new Throwable().fillInStackTrace())); ! this.notifyAll(); ! return findNextAction(method, parameters); } --- 223,229 ---- Object[] newParams = clone(method, parameters); methodsCalled.add(new CalledMethod(method, newParams, new Throwable().fillInStackTrace())); ! this.notifyAll(); ! return findNextAction(method, parameters); } *************** *** 234,238 **** return methodToDefaultRetVal.get(method); } ! Object retVal = l.remove(0); if(l.size()<=0) --- 235,239 ---- return methodToDefaultRetVal.get(method); } ! Object retVal = l.remove(0); if(l.size()<=0) *************** *** 240,244 **** else if(retVal == null) methodToDefaultRetVal.get(method); ! if(retVal instanceof Behavior) { return ((Behavior)retVal).runMethod(params); --- 241,245 ---- else if(retVal == null) methodToDefaultRetVal.get(method); ! if(retVal instanceof Behavior) { return ((Behavior)retVal).runMethod(params); *************** *** 250,254 **** return retVal; } ! /** * @see biz.xsoftware.mock.MockObject#expectUnorderedCalls(java.lang.String[]) --- 251,255 ---- return retVal; } ! /** * @see biz.xsoftware.mock.MockObject#expectUnorderedCalls(java.lang.String[]) *************** *** 258,262 **** throw new IllegalArgumentException("methods cannot be null"); else if(methods.length <= 0) ! throw new IllegalArgumentException("methods.length must be >= 1"); for(int i = 0; i < methods.length; i++) { if(methods[i] == null) --- 259,263 ---- throw new IllegalArgumentException("methods cannot be null"); else if(methods.length <= 0) ! throw new IllegalArgumentException("methods.length must be >= 1"); for(int i = 0; i < methods.length; i++) { if(methods[i] == null) *************** *** 264,276 **** "can be null, yet methods["+i+"] was null"); } ! Map<String, Integer> expectedMethods = new HashMap<String, Integer>(); for(int i = 0; i < methods.length; i++) { expectedMethods.put(methods[i], new Integer(i)); } ! Set<String> ignorables = createIgnorableMap(ignoredMethods); CalledMethod[] retVal = new CalledMethod[methods.length]; ! List<CalledMethod> methodsCalledList = new ArrayList<CalledMethod>(); for(int i = 0; i < methods.length; i++) { --- 265,277 ---- "can be null, yet methods["+i+"] was null"); } ! Map<String, Integer> expectedMethods = new HashMap<String, Integer>(); for(int i = 0; i < methods.length; i++) { expectedMethods.put(methods[i], new Integer(i)); } ! Set<String> ignorables = createIgnorableMap(ignoredMethods); CalledMethod[] retVal = new CalledMethod[methods.length]; ! List<CalledMethod> methodsCalledList = new ArrayList<CalledMethod>(); for(int i = 0; i < methods.length; i++) { *************** *** 278,285 **** throw new IllegalArgumentException("The parameter 'methods' in " + "expectUnorderedCalls cannot contain MockSuperclass.ANY(use expectOrderedCalls instead)"); ! CalledMethod o = expectUnignoredCall(ANY, ignorables, methodsCalledList); if(o == null) { ! String reason = putTogetherReason(methods, ignorables, methodsCalledList, "timed out on next expected method\n"); throw new ExpectFailedException("Timed out waiting for a method call\n" --- 279,286 ---- throw new IllegalArgumentException("The parameter 'methods' in " + "expectUnorderedCalls cannot contain MockSuperclass.ANY(use expectOrderedCalls instead)"); ! CalledMethod o = expectUnignoredCall(ANY, ignorables, methodsCalledList); if(o == null) { ! String reason = putTogetherReason(methods, ignorables, methodsCalledList, "timed out on next expected method\n"); throw new ExpectFailedException("Timed out waiting for a method call\n" *************** *** 291,298 **** throw new ExpectFailedException(reason, retVal, ExpectFailedException.UNEXPECTED_CALL_BEFORE); } ! retVal[index.intValue()] = o; } ! LeftOverMethods leftOver = getLeftOverMethods(ignorables); if(leftOver != null) { --- 292,299 ---- throw new ExpectFailedException(reason, retVal, ExpectFailedException.UNEXPECTED_CALL_BEFORE); } ! retVal[index.intValue()] = o; } ! LeftOverMethods leftOver = getLeftOverMethods(ignorables); if(leftOver != null) { *************** *** 301,309 **** , ExpectFailedException.UNEXPECTED_CALL_AFTER); } ! return retVal; } ! ! private String getHowMethodWasCalled(CalledMethod method) { Throwable t = method.getHowItWasCalled(); String retVal = "\nThe last method was="+method.getMethodName(); --- 302,310 ---- , ExpectFailedException.UNEXPECTED_CALL_AFTER); } ! return retVal; } ! ! private String getHowMethodWasCalled(CalledMethod method) { Throwable t = method.getHowItWasCalled(); String retVal = "\nThe last method was="+method.getMethodName(); *************** *** 326,330 **** return retVal; } ! /** * @see biz.xsoftware.mock.MockObject#expectCall(java.lang.String) --- 327,331 ---- return retVal; } ! /** * @see biz.xsoftware.mock.MockObject#expectCall(java.lang.String) *************** *** 333,344 **** return expectImpl(new String[] {method})[0]; } ! /** * @see biz.xsoftware.mock.MockObject#expect(java.lang.String) */ public CalledMethod expect(String method) { ! return expectImpl(new String[] {method})[0]; } ! /** * @see biz.xsoftware.mock.MockObject#expect(java.lang.String[]) --- 334,345 ---- return expectImpl(new String[] {method})[0]; } ! /** * @see biz.xsoftware.mock.MockObject#expect(java.lang.String) */ public CalledMethod expect(String method) { ! return expectImpl(method)[0]; } ! /** * @see biz.xsoftware.mock.MockObject#expect(java.lang.String[]) *************** *** 348,357 **** return expectImpl(methods); } ! ! private synchronized CalledMethod[] expectImpl(String[] methods) { return expectOrderedCalls(methods); } ! /** * @see biz.xsoftware.mock.MockObject#expectOrderedCalls(java.lang.String[]) --- 349,358 ---- return expectImpl(methods); } ! ! private synchronized CalledMethod[] expectImpl(String ... methods) { return expectOrderedCalls(methods); } ! /** * @see biz.xsoftware.mock.MockObject#expectOrderedCalls(java.lang.String[]) *************** *** 368,372 **** verifyMethodsExist(methods); ! Set<String> ignorables = createIgnorableMap(ignoredMethods); --- 369,373 ---- verifyMethodsExist(methods); ! Set<String> ignorables = createIgnorableMap(ignoredMethods); *************** *** 400,404 **** } } ! LeftOverMethods leftOver = getLeftOverMethods(ignorables); if(leftOver != null) { --- 401,405 ---- } } ! LeftOverMethods leftOver = getLeftOverMethods(ignorables); if(leftOver != null) { *************** *** 407,415 **** CalledMethod[] calledOnes = new CalledMethod[retVal.length+1]; System.arraycopy(retVal, 0, calledOnes, 0, retVal.length); ! calledOnes[retVal.length] = leftOver.getMethods()[0]; throw new ExpectFailedException("There was a method called after your expected methods.\n"+reason, calledOnes , ExpectFailedException.UNEXPECTED_CALL_AFTER); } ! return retVal; } --- 408,416 ---- CalledMethod[] calledOnes = new CalledMethod[retVal.length+1]; System.arraycopy(retVal, 0, calledOnes, 0, retVal.length); ! calledOnes[retVal.length] = leftOver.getMethods()[0]; throw new ExpectFailedException("There was a method called after your expected methods.\n"+reason, calledOnes , ExpectFailedException.UNEXPECTED_CALL_AFTER); } ! return retVal; } *************** *** 426,446 **** if(classes == null) return; ! String classNames = ""; for(int i = 0; i < classes.length; i++) { if(log.isLoggable(Level.FINEST)) ! log.finest("class="+classes[i].getName()); if(methodExistInThisClass(method, classes[i])) return; classNames += "\n"+classes[i]; } ! throw new IllegalArgumentException("method='"+method+"' is not a method on any of the" + "\nfollowing Classes/Interfaces"+classNames); } ! private boolean methodExistInThisClass(String method, Class c) { Method[] methods = c.getMethods(); ! for(int i = 0; i < methods.length; i++) { if(log.isLoggable(Level.FINEST)) log.finest("method in class='"+methods[i].getName()+"' expected='"+method+"'"); --- 427,447 ---- if(classes == null) return; ! String classNames = ""; for(int i = 0; i < classes.length; i++) { if(log.isLoggable(Level.FINEST)) ! log.finest("class="+classes[i].getName()); if(methodExistInThisClass(method, classes[i])) return; classNames += "\n"+classes[i]; } ! throw new IllegalArgumentException("method='"+method+"' is not a method on any of the" + "\nfollowing Classes/Interfaces"+classNames); } ! private boolean methodExistInThisClass(String method, Class c) { Method[] methods = c.getMethods(); ! for(int i = 0; i < methods.length; i++) { if(log.isLoggable(Level.FINEST)) log.finest("method in class='"+methods[i].getName()+"' expected='"+method+"'"); *************** *** 450,454 **** return false; } ! private String putTogetherReason(String[] methods, Set<String> ignorables, List methodsCalled, String lastLine) { String reason = "\nMethods you expected...\n"; --- 451,455 ---- return false; } ! private String putTogetherReason(String[] methods, Set<String> ignorables, List methodsCalled, String lastLine) { String reason = "\nMethods you expected...\n"; *************** *** 475,495 **** else reason += lastLine+"\n"; ! ! return reason; } ! protected synchronized CalledMethod expectUnignoredCall(String method, Set<String> ignorables, List<CalledMethod> calledMethods) { if(method == null) method = NONE; ! ! //kind of dangerous if used with multiple threads because we might miss //a bad event coming in, but if you keep using the same listener for every test ! //the problem should still manifest itself in a //different test case which sucks but works. if(method.equals(NONE)) { if (log.isLoggable(Level.FINE)) ! log.log(Level.FINE, "method expected="+NONE+" on obj="+this); LeftOverMethods leftOver = getLeftOverMethods(ignorables); if(leftOver != null) { --- 476,510 ---- else reason += lastLine+"\n"; ! ! return reason; } ! protected synchronized CalledMethod expectUnignoredCall(String method, Set<String> ignorables, List<CalledMethod> calledMethods) { if(method == null) method = NONE; ! ! //kind of dangerous if used with multiple threads because we might miss //a bad event coming in, but if you keep using the same listener for every test ! //the problem should still manifest itself in a //different test case which sucks but works. if(method.equals(NONE)) { if (log.isLoggable(Level.FINE)) ! log.log(Level.FINE, "method expected="+NONE+" on obj="+this); ! ! // we have to strip out all of the ignored methods from methodsCalled ! CalledMethod[] methods = methodsCalled.toArray(new CalledMethod[0]); ! for(CalledMethod calledMethod : methods) ! { ! if(ignorables.contains(calledMethod.getMethodName())) ! { ! while(methodsCalled.contains(calledMethod)) ! { ! methodsCalled.remove(calledMethod); ! } ! } ! } ! LeftOverMethods leftOver = getLeftOverMethods(ignorables); if(leftOver != null) { *************** *** 501,515 **** return new CalledMethod(NONE, null, null); } ! try { return waitForUnignoredCall(method, ignorables, calledMethods); } catch (InterruptedException e) { throw new RuntimeException(e); ! } } private CalledMethod waitForUnignoredCall( String logM, Set<String> ignorables, List<CalledMethod> calledMethods) throws InterruptedException { ! long waitTime2 = waitTime+50; long currentTime; --- 516,530 ---- return new CalledMethod(NONE, null, null); } ! try { return waitForUnignoredCall(method, ignorables, calledMethods); } catch (InterruptedException e) { throw new RuntimeException(e); ! } } private CalledMethod waitForUnignoredCall( String logM, Set<String> ignorables, List<CalledMethod> calledMethods) throws InterruptedException { ! long waitTime2 = waitTime+50; long currentTime; *************** *** 525,529 **** waitTime2 -= waitedOnWait; } ! //check for new methods to be called now...if no non-ignorable methods, then //continue while loop. --- 540,544 ---- waitTime2 -= waitedOnWait; } ! //check for new methods to be called now...if no non-ignorable methods, then //continue while loop. *************** *** 533,546 **** if(!ignorables.contains(calledMethod.getMethodName())) { if(log.isLoggable(Level.FINE)) ! log.fine("method expected and was called="+logM+" on obj="+this); return calledMethod; } } ! } //return null means timeout.... return null; } ! private Set<String> createIgnorableMap(List<String> ignorableMethods) { Set<String> ignorables = new HashSet<String>(); --- 548,561 ---- if(!ignorables.contains(calledMethod.getMethodName())) { if(log.isLoggable(Level.FINE)) ! log.fine("method expected and was called="+logM+" on obj="+this); return calledMethod; } } ! } //return null means timeout.... return null; } ! private Set<String> createIgnorableMap(List<String> ignorableMethods) { Set<String> ignorables = new HashSet<String>(); *************** *** 563,572 **** if(leftOver.size() <= 0) return null; ! CalledMethod[] m = new CalledMethod[0]; m = leftOver.toArray(m); return new LeftOverMethods(m); } ! private class LeftOverMethods { --- 578,587 ---- if(leftOver.size() <= 0) return null; ! CalledMethod[] m = new CalledMethod[0]; m = leftOver.toArray(m); return new LeftOverMethods(m); } ! private class LeftOverMethods { *************** *** 591,595 **** /** * @see biz.xsoftware.mock.MockObject#addThrowException(java.lang.String, java.lang.Throwable) ! */ public synchronized void addThrowException(String method, Throwable e) { if(method == null) --- 606,610 ---- /** * @see biz.xsoftware.mock.MockObject#addThrowException(java.lang.String, java.lang.Throwable) ! */ public synchronized void addThrowException(String method, Throwable e) { if(method == null) *************** *** 604,608 **** l.add(e); } ! /** * @see biz.xsoftware.mock.MockObject#addReturnValue(java.lang.String, java.lang.Object) --- 619,623 ---- l.add(e); } ! /** * @see biz.xsoftware.mock.MockObject#addReturnValue(java.lang.String, java.lang.Object) *************** *** 618,631 **** l.add(o); } ! public void setDefaultReturnValue(String method, Object o) { methodToDefaultRetVal.put(method, o); } ! /** * This is the method that calls the cloner to clone * objects like ByteBuffer that can change after * they are called. ! * * @param o * @return --- 633,646 ---- l.add(o); } ! public void setDefaultReturnValue(String method, Object o) { methodToDefaultRetVal.put(method, o); } ! /** * This is the method that calls the cloner to clone * objects like ByteBuffer that can change after * they are called. ! * * @param o * @return *************** *** 634,638 **** if(params == null) return null; ! //check if the next object is a Behavior object List<Object> actions = methodToReturnVal.get(method); --- 649,653 ---- if(params == null) return null; ! //check if the next object is a Behavior object List<Object> actions = methodToReturnVal.get(method); *************** *** 644,663 **** } } ! ! if(cloner == null) return params; ! return cloner.clone(params); ! } ! public Class[] getClasses() { return new Class[] {this.getClass()}; } ! public void setCloner(Cloner c) { cloner = c; } ! public void addBehavior(String method, Behavior behavior) { if(method == null) --- 659,678 ---- } } ! ! if(cloner == null) return params; ! return cloner.clone(params); ! } ! public Class[] getClasses() { return new Class[] {this.getClass()}; } ! public void setCloner(Cloner c) { cloner = c; } ! public void addBehavior(String method, Behavior behavior) { if(method == null) Index: MockObjectImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObjectImpl.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** MockObjectImpl.java 7 Aug 2006 15:52:45 -0000 1.8 --- MockObjectImpl.java 25 Aug 2006 22:31:55 -0000 1.9 *************** *** 64,68 **** } throw new RuntimeException("\nYou must specify a return value of type " + ! returnType.getCanonicalName() + " for ignored or expected method:\n" + " " + method.getName() + "(" + methodArgs + ")"); --- 64,68 ---- } throw new RuntimeException("\nYou must specify a return value of type " + ! returnType + " for ignored or expected method:\n" + " " + method.getName() + "(" + methodArgs + ")"); |
From: dadrox <da...@us...> - 2006-08-25 22:31:59
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv10562/input/javasrc/biz/xsoftware/test/mock Modified Files: TestMockCreator.java Log Message: add/removeIgnore works now Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TestMockCreator.java 25 Aug 2006 19:42:08 -0000 1.6 --- TestMockCreator.java 25 Aug 2006 22:31:55 -0000 1.7 *************** *** 219,222 **** --- 219,239 ---- } + public void testAddRemoveIgnore() + { + MockObject mock = MockObjectFactory.createMock(Car.class); + mock.addIgnore("openDoor", "closeDoor"); + + Car car = (Car)mock; + car.openDoor(); + car.closeDoor(); + + mock.expect(MockObject.NONE); + + mock.removeIgnore("closeDoor"); + car.closeDoor(); + + mock.expect("closeDoor"); + } + private static class MyBehavior implements Behavior { |
From: dadrox <da...@us...> - 2006-08-25 19:42:24
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2 In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv26781/input/javasrc/biz/xsoftware/test/mock2 Modified Files: TestMockCreator.java Log Message: added add/removeIgnore and did some minor cleanup Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** TestMockCreator.java 5 May 2006 15:29:23 -0000 1.20 --- TestMockCreator.java 25 Aug 2006 19:42:09 -0000 1.21 *************** *** 179,183 **** final String param = "some params"; Thread t = new Thread() { ! public void run() { try { Thread.sleep(3000); --- 179,184 ---- final String param = "some params"; Thread t = new Thread() { ! @Override ! public void run() { try { Thread.sleep(3000); |
From: dadrox <da...@us...> - 2006-08-25 19:42:16
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv26781/input/javasrc/biz/xsoftware/mock Modified Files: MockSuperclass.java MockObject.java Log Message: added add/removeIgnore and did some minor cleanup Index: MockSuperclass.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockSuperclass.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** MockSuperclass.java 25 Aug 2006 17:26:29 -0000 1.11 --- MockSuperclass.java 25 Aug 2006 19:42:09 -0000 1.12 *************** *** 76,80 **** private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>(); ! private String[] ignoredMethods = new String[0]; private Cloner cloner; --- 76,80 ---- private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>(); ! private List<String> ignoredMethods = new ArrayList<String>(); private Cloner cloner; *************** *** 118,144 **** return waitTime; } ! ! public void ignore(String method) { ! ignoreImpl(new String[] {method}); } ! public void ignore(String ... methods) { ignoreImpl(methods); } ! private void ignoreImpl(String[] methods) { ! setIgnoredMethods(methods); } ! public void setIgnoredMethods(String[] methods) { if(methods == null) ! ignoredMethods = new String[0]; verifyMethodsExist(methods); ! ignoredMethods = methods; } /** --- 118,177 ---- return waitTime; } ! ! public void addIgnore(String method) { ! ignoreImpl(method); } ! public void addIgnore(String ... methods) { ignoreImpl(methods); } ! public void removeIgnore(String method) { ! removeIgnoreImpl(method); } ! public void removeIgnore(String ... methods) ! { ! removeIgnoreImpl(methods); ! } ! ! private void removeIgnoreImpl(String ... methods) ! { ! for(String method : methods) ! { ! ignoredMethods.remove(method); ! } ! } ! ! private void ignoreImpl(String ... methods) ! { ! addIgnoredMethods(methods); ! } ! ! public void addIgnoredMethods(String[] methods) { if(methods == null) ! return; verifyMethodsExist(methods); ! for(String method : methods) ! { ! ignoredMethods.add(method); ! } } + + public void setIgnoredMethods(String[] methods) + { + if(methods == null) + ignoredMethods = new ArrayList<String>(); + verifyMethodsExist(methods); + + for(String method : methods) + { + ignoredMethods.add(method); + } + } /** *************** *** 171,175 **** params = "no params"; } else { ! Object[] array = (Object[])parameters; for(int i = 0; i < array.length-1; i++) { params += array[i]+", "; --- 204,208 ---- params = "no params"; } else { ! Object[] array = parameters; for(int i = 0; i < array.length-1; i++) { params += array[i]+", "; *************** *** 196,200 **** private Object findNextAction(String method, Object[] params) throws Throwable { ! List l = (List)methodToReturnVal.get(method); if(l == null) { --- 229,233 ---- private Object findNextAction(String method, Object[] params) throws Throwable { ! List l = methodToReturnVal.get(method); if(l == null) { *************** *** 253,257 **** +reason, retVal, ExpectFailedException.TIMED_OUT); } ! Integer index = (Integer)expectedMethods.remove(o.getMethodName()); if(index == null) { String reason = putTogetherReason(methods, ignorables, methodsCalledList, null); --- 286,290 ---- +reason, retVal, ExpectFailedException.TIMED_OUT); } ! Integer index = expectedMethods.remove(o.getMethodName()); if(index == null) { String reason = putTogetherReason(methods, ignorables, methodsCalledList, null); *************** *** 496,500 **** //continue while loop. for(int i = 0; i < methodsCalled.size(); i++) { ! CalledMethod calledMethod = (CalledMethod)methodsCalled.remove(0); calledMethods.add(calledMethod); if(!ignorables.contains(calledMethod.getMethodName())) { --- 529,533 ---- //continue while loop. for(int i = 0; i < methodsCalled.size(); i++) { ! CalledMethod calledMethod = methodsCalled.remove(0); calledMethods.add(calledMethod); if(!ignorables.contains(calledMethod.getMethodName())) { *************** *** 510,520 **** } ! private Set<String> createIgnorableMap(String[] ignorableMethods) { Set<String> ignorables = new HashSet<String>(); if(ignorableMethods != null) { ! for(int i = 0; i < ignorableMethods.length; i++) { ! if(ignorableMethods[i] != null) ! ignorables.add(ignorableMethods[i]); ! } } return ignorables; --- 543,553 ---- } ! private Set<String> createIgnorableMap(List<String> ignorableMethods) { Set<String> ignorables = new HashSet<String>(); if(ignorableMethods != null) { ! for(String method : ignorableMethods) ! { ! ignorables.add(method); ! } } return ignorables; *************** *** 523,527 **** List<CalledMethod> leftOver = new ArrayList<CalledMethod>(); for(int i = 0; i < methodsCalled.size(); i++) { ! CalledMethod o = (CalledMethod)methodsCalled.get(i); if(!ignorables.contains(o.getMethodName()) && o != null) { leftOver.add(o); --- 556,560 ---- List<CalledMethod> leftOver = new ArrayList<CalledMethod>(); for(int i = 0; i < methodsCalled.size(); i++) { ! CalledMethod o = methodsCalled.get(i); if(!ignorables.contains(o.getMethodName()) && o != null) { leftOver.add(o); *************** *** 532,536 **** CalledMethod[] m = new CalledMethod[0]; ! m = (CalledMethod[])leftOver.toArray(m); return new LeftOverMethods(m); } --- 565,569 ---- CalledMethod[] m = new CalledMethod[0]; ! m = leftOver.toArray(m); return new LeftOverMethods(m); } *************** *** 543,552 **** } /** - * @return */ public CalledMethod[] getMethods() { return leftOver; } ! public String toString() { String retVal = ""; for(int i = 0; i < leftOver.length; i++) { --- 576,585 ---- } /** */ public CalledMethod[] getMethods() { return leftOver; } ! @Override ! public String toString() { String retVal = ""; for(int i = 0; i < leftOver.length; i++) { Index: MockObject.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObject.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MockObject.java 4 Aug 2006 16:20:52 -0000 1.5 --- MockObject.java 25 Aug 2006 19:42:09 -0000 1.6 *************** *** 11,15 **** * The interface all mock objects implement. This is the interface used * by the unit tests once the mock object is created. ! * * @author Dean Hiller */ --- 11,15 ---- * The interface all mock objects implement. This is the interface used * by the unit tests once the mock object is created. ! * * @author Dean Hiller */ *************** *** 25,32 **** */ public static String ANY = "'Any 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. --- 25,32 ---- */ public static String ANY = "'Any 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. *************** *** 34,45 **** * @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. --- 34,45 ---- * @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. *************** *** 47,51 **** * @param method The expected method. * @return An array of params that were passed to the methods called ! */ public CalledMethod expect(String method); --- 47,51 ---- * @param method The expected method. * @return An array of params that were passed to the methods called ! */ public CalledMethod expect(String method); *************** *** 56,66 **** * 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 --- 56,66 ---- * 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 *************** *** 69,89 **** * 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 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); ! /** * Expect many methods to be called irrelevant of the order in which they are * called. ! * * @param methods The methods to be called in no particular order * @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. */ --- 69,89 ---- * 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 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); ! /** * Expect many methods to be called irrelevant of the order in which they are * called. ! * * @param methods The methods to be called in no particular order * @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. */ *************** *** 106,110 **** * <li> RuntimeException for Subclasses of MockSuperclass</li> * </ol> ! * * @param method The method to throw the exception on when it is called. * @param e The exception to throw on method. --- 106,110 ---- * <li> RuntimeException for Subclasses of MockSuperclass</li> * </ol> ! * * @param method The method to throw the exception on when it is called. * @param e The exception to throw on method. *************** *** 114,118 **** * Add a return value to return when 'method' is called. * <br></br> ! * This can be called multiple times and each call will add * to a queue. When 'method' is called, it will return * the first value on the queue. If the queue is null, --- 114,118 ---- * Add a return value to return when 'method' is called. * <br></br> ! * This can be called multiple times and each call will add * to a queue. When 'method' is called, it will return * the first value on the queue. If the queue is null, *************** *** 121,145 **** * <br></br> * Use Integer to return int, Long for long, etc. ! * * @param method The method that when called returns first value on queue * @param o The object to return that is added to the queue */ public void addReturnValue(String method, Object o); ! /** * When calling expectCall, 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. ! * * @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 --- 121,146 ---- * <br></br> * Use Integer to return int, Long for long, etc. ! * * @param method The method that when called returns first value on queue * @param o The object to return that is added to the queue */ public void addReturnValue(String method, Object o); ! /** * When calling expectCall, 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. ! * * @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 addIgnore(String method); ! /** * When calling expect, the MockObject will ignore the methods *************** *** 147,164 **** * called, it will not result in an exception. */ ! public void ignore(String ... methods); ! public void setCloner(Cloner c); /** * Set the DefaultReturnValue for a 'method' ! * @param method The method */ public void setDefaultReturnValue(String method, Object o); ! public void setExpectTimeout(int timeout); ! public int getExpectTimeout(); public void addBehavior(String string, Behavior behavior); ! } --- 148,176 ---- * called, it will not result in an exception. */ ! public void addIgnore(String ... methods); ! ! ! /** ! * Removes the method from the ignored methods set. ! */ ! public void removeIgnore(String method); ! ! /** ! * Removes the methods from the ignored methods set. ! */ ! public void removeIgnore(String ... methods); ! public void setCloner(Cloner c); /** * Set the DefaultReturnValue for a 'method' ! * @param method The method */ public void setDefaultReturnValue(String method, Object o); ! public void setExpectTimeout(int timeout); ! public int getExpectTimeout(); public void addBehavior(String string, Behavior behavior); ! } |
From: dadrox <da...@us...> - 2006-08-25 19:42:16
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv26781/input/javasrc/biz/xsoftware/test/mock Modified Files: TestMockCreator.java MockOne.java Log Message: added add/removeIgnore and did some minor cleanup Index: MockOne.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/MockOne.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MockOne.java 1 Jan 2006 00:35:56 -0000 1.1 --- MockOne.java 25 Aug 2006 19:42:08 -0000 1.2 *************** *** 52,56 **** * @see biz.xsoftware.mock.MockSuperclass#getClasses() */ ! public Class[] getClasses() { return new Class[] { MockOne.class }; } --- 52,57 ---- * @see biz.xsoftware.mock.MockSuperclass#getClasses() */ ! @Override ! public Class[] getClasses() { return new Class[] { MockOne.class }; } Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TestMockCreator.java 25 Aug 2006 17:26:28 -0000 1.5 --- TestMockCreator.java 25 Aug 2006 19:42:08 -0000 1.6 *************** *** 95,99 **** MockObject car = MockObjectFactory.createMock(Car.class); ! factory.addReturnValue("createCar", (Car)car); //now we would normally tweak code on the subsystem which --- 95,99 ---- MockObject car = MockObjectFactory.createMock(Car.class); ! factory.addReturnValue("createCar", car); //now we would normally tweak code on the subsystem which *************** *** 169,187 **** mock.addReturnValue("doThat", new byte[] {3}); mock.setDefaultReturnValue("doThat", new byte[] {4}); Identical ident = (Identical)mock; ! byte[] retVal1 = ident.doThat(null); ! mock.expect("doThat"); ! assertEquals(1, retVal1.length); ! assertEquals(3, retVal1[0]); ! byte[] retVal2 = ident.doThat(null); mock.expect("doThat"); ! assertEquals(1, retVal2.length); ! assertEquals(4, retVal2[0]); } --- 169,192 ---- mock.addReturnValue("doThat", new byte[] {3}); mock.setDefaultReturnValue("doThat", new byte[] {4}); + mock.addReturnValue("doThat", new byte[] {5}); Identical ident = (Identical)mock; ! byte[] retVal = ident.doThat(null); mock.expect("doThat"); ! assertEquals(1, retVal.length); ! assertEquals(3, retVal[0]); ! retVal = ident.doThat(null); ! mock.expect("doThat"); + assertEquals(1, retVal.length); + assertEquals(5, retVal[0]); + + retVal = ident.doThat(null); mock.expect("doThat"); ! assertEquals(1, retVal.length); ! assertEquals(4, retVal[0]); } |
From: dadrox <da...@us...> - 2006-08-25 19:42:15
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/advanced In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv26781/input/javasrc/biz/xsoftware/examples/mock2/advanced Modified Files: TestExample.java Log Message: added add/removeIgnore and did some minor cleanup Index: TestExample.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/examples/mock2/advanced/TestExample.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TestExample.java 7 Aug 2006 15:52:45 -0000 1.3 --- TestExample.java 25 Aug 2006 19:42:08 -0000 1.4 *************** *** 70,74 **** CalledMethod getUser=mockRecord.expect("getUser"); CalledMethod addTaskDone=mockUser.expect("", "addTaskDone"); ! mockRecord.setDefaultReturnValue( (User)mockUser,"getUser"); --- 70,74 ---- CalledMethod getUser=mockRecord.expect("getUser"); CalledMethod addTaskDone=mockUser.expect("", "addTaskDone"); ! mockRecord.setDefaultReturnValue( mockUser,"getUser"); |
From: dadrox <da...@us...> - 2006-08-25 19:42:13
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv26781/input/javasrc/biz/xsoftware/mock2/impl Modified Files: MockObjectFactoryImpl.java Log Message: added add/removeIgnore and did some minor cleanup Index: MockObjectFactoryImpl.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectFactoryImpl.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MockObjectFactoryImpl.java 5 Apr 2006 15:27:08 -0000 1.5 --- MockObjectFactoryImpl.java 25 Aug 2006 19:42:09 -0000 1.6 *************** *** 8,12 **** public class MockObjectFactoryImpl extends MockObjectFactory { ! public MockObject createMockImpl( String id,Class[] interfacesToMock) { Class[] interfacesPlusMock = new Class[interfacesToMock.length + 1]; interfacesPlusMock[0] = MockObject.class; --- 8,13 ---- public class MockObjectFactoryImpl extends MockObjectFactory { ! @Override ! public MockObject createMockImpl( String id,Class[] interfacesToMock) { Class[] interfacesPlusMock = new Class[interfacesToMock.length + 1]; interfacesPlusMock[0] = MockObject.class; *************** *** 22,26 **** } ! public MockObject createMockImpl(String id,Class interfaceToMock, Object realObject) { Class[] interfacePlusMock = new Class[1]; --- 23,28 ---- } ! @Override ! public MockObject createMockImpl(String id,Class interfaceToMock, Object realObject) { Class[] interfacePlusMock = new Class[1]; |
From: dadrox <da...@us...> - 2006-08-25 17:27:28
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv28184/input/javasrc/biz/xsoftware/test/mock Modified Files: TestMockCreator.java Log Message: fixed default returns bug Index: TestMockCreator.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock/TestMockCreator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TestMockCreator.java 7 Aug 2006 15:52:45 -0000 1.4 --- TestMockCreator.java 25 Aug 2006 17:26:28 -0000 1.5 *************** *** 164,167 **** --- 164,189 ---- } + public void testDefaultReturnWithOtherReturns() + { + MockObject mock = MockObjectFactory.createMock(Identical.class); + mock.addReturnValue("doThat", new byte[] {3}); + mock.setDefaultReturnValue("doThat", new byte[] {4}); + + Identical ident = (Identical)mock; + byte[] retVal1 = ident.doThat(null); + + mock.expect("doThat"); + + assertEquals(1, retVal1.length); + assertEquals(3, retVal1[0]); + + byte[] retVal2 = ident.doThat(null); + + mock.expect("doThat"); + + assertEquals(1, retVal2.length); + assertEquals(4, retVal2[0]); + } + public void testBehavior() { MockObject mock = MockObjectFactory.createMock(Identical.class); |
From: dadrox <da...@us...> - 2006-08-25 17:26:34
|
Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv28184/input/javasrc/biz/xsoftware/mock Modified Files: MockSuperclass.java Log Message: fixed default returns bug Index: MockSuperclass.java =================================================================== RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockSuperclass.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** MockSuperclass.java 7 Aug 2006 15:52:45 -0000 1.10 --- MockSuperclass.java 25 Aug 2006 17:26:29 -0000 1.11 *************** *** 191,198 **** this.notifyAll(); - - Object defaultVal = methodToDefaultRetVal.get(method); - if(defaultVal != null) - return defaultVal; return findNextAction(method, parameters); --- 191,194 ---- *************** *** 202,210 **** 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) { --- 198,210 ---- List l = (List)methodToReturnVal.get(method); if(l == null) ! { ! return methodToDefaultRetVal.get(method); ! } Object retVal = l.remove(0); if(l.size()<=0) methodToReturnVal.remove(method); + else if(retVal == null) + methodToDefaultRetVal.get(method); if(retVal instanceof Behavior) { |