contestj-developer Mailing List for contestJ
Status: Inactive
Brought to you by:
thomasra
You can subscribe to this list here.
| 2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(23) |
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(6) |
Feb
(43) |
Mar
(20) |
Apr
(12) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(2) |
Dec
|
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(49) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Ståle P. <st...@us...> - 2007-06-20 15:10:20
|
Update of /cvsroot/contestj/contestj/contestj2 In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8182/contestj2 Log Message: Directory /cvsroot/contestj/contestj/contestj2 added to the repository |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:23
|
Update of /cvsroot/contestj/contestj/contestj2/src/main/java/org/contestj/duplicator In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/main/java/org/contestj/duplicator Added Files: MockInjector.java Duplicator.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: Duplicator.java --- package org.contestj.duplicator; import java.io.IOException; import javassist.CannotCompileException; import javassist.ClassPool; import javassist.CtClass; import javassist.CtField; import javassist.CtMethod; import javassist.CtNewMethod; import javassist.CtPrimitiveType; import javassist.Modifier; import javassist.NotFoundException; import org.apache.log4j.Logger; public class Duplicator { private static Logger log = Logger.getLogger(Duplicator.class.getName()); private static String DUPLICATE = "_duplicate"; /** * This method returns a duplicated object for use in runtime, using * javassist libraries for runtime bytecode manipulation. Send in an * instantiated class object or a class representing an interface and * get an instantiated object back, supporting the methods defined * in the class or interface for use in testing. * * @param classOrInterface * @return */ public static Object duplicate(String classOrInterface) { if(doesDuplicateClassExist(classOrInterface)) { System.out.println("Duplicate already found in Classloader, using it..."); return loadDuplicateObject(classOrInterface); } System.out.println("Duplicating " + classOrInterface + " (in-memory)"); try { Class classOrInterfaceClass = Class.forName(classOrInterface); CtClass resultClass = null; // Split the responsibilities into two classes if(classOrInterfaceClass.isInterface() || Modifier.isAbstract(classOrInterfaceClass.getModifiers()) || classOrInterfaceClass.getName().equals("java.lang.Class")) { resultClass = duplicateInterface(classOrInterfaceClass); } else { throw new RuntimeException("Can only duplicate interfaces"); } //MockInjector.injectMock(resultClass); resultClass.writeFile("/tmp"); return resultClass.toClass().newInstance(); } catch (ClassNotFoundException e) { throw new RuntimeException("Not found: " + e.getMessage()); } catch (InstantiationException e) { throw new RuntimeException("Could not instantiate: " + e.getMessage()); } catch (IllegalAccessException e) { throw new RuntimeException("Could not access: " + e.getMessage()); } catch (IOException e) { throw new RuntimeException("I/O error: " + e.getMessage()); } catch (CannotCompileException e) { throw new RuntimeException("Could not compile: " + e.getMessage()); } } private static boolean doesDuplicateClassExist(String classOrInterface) { try { Class clazz = Class.forName(classOrInterface + DUPLICATE); return (clazz != null); } catch(ClassNotFoundException ce) { return false; } catch(Exception e) { log.error("Class.forName().. exception: "+classOrInterface + DUPLICATE, e); return false; } } private static Object loadDuplicateObject(String classOrInterface) { try { Class dupe = Class.forName(classOrInterface + DUPLICATE); return dupe.newInstance(); } catch(ClassNotFoundException ce) { throw new RuntimeException("Didnt find class: " + ce.getMessage()); } catch(IllegalAccessException ie ) { throw new RuntimeException("Illegal access: " + ie.getMessage()); } catch(InstantiationException ine ) { throw new RuntimeException("Instantiation error: " + ine.getMessage()); } catch(ExceptionInInitializerError ee ) { throw new RuntimeException("Initialize error: " + ee.getMessage()); } catch(SecurityException se ) { throw new RuntimeException("Security error: " + se.getMessage()); } } private static CtClass duplicateInterface(Class interfaceObject ) { ClassPool cPool = ClassPool.getDefault(); try { String interfaceCopyName = interfaceObject.getName() + DUPLICATE; CtClass ctClass = cPool.makeClass(interfaceCopyName); CtClass ctInterface = cPool.get(interfaceObject.getName()); if(ctInterface.isInterface()) { ctClass.addInterface(ctInterface); } else { ctClass.setSuperclass(ctInterface); } overrideReturningMethods(ctClass, ctInterface); return ctClass; } catch (NotFoundException e) { throw new RuntimeException("Not found: " + e.getMessage()); } catch (CannotCompileException e) { throw new RuntimeException("Cannot compile: " + e.getMessage()); } } private static void overrideReturningMethods(CtClass copy, CtClass original) { System.out.println("Overriding returning methods"); CtMethod[] methodsOnClass = null; CtMethod[] methodsOnSuperclass = null; // Should we look for methods on the original (interface) or the copy (class)? if(original == null) { methodsOnClass = copy.getDeclaredMethods(); methodsOnSuperclass = copy.getMethods(); } else { methodsOnClass = original.getDeclaredMethods(); methodsOnSuperclass = original.getMethods(); } // Loop through all of the methods to find non-void methods for (int i = 0; i < methodsOnSuperclass.length; i++) { CtMethod method = methodsOnSuperclass[i]; System.out.println("transforming method: "+method.toString()); // Find the non-void methods try { CtClass returnType = method.getReturnType(); CtClass[] parameterTypes = method.getParameterTypes(); CtClass[] exceptionTypes = method.getExceptionTypes(); String methodName = method.getName(); if(!method.getDeclaringClass().getName().equals("java.lang.Object")) { if(!method.getReturnType().equals(CtPrimitiveType.voidType)) { System.out.println("Modifying main method body: " + method.getName()); if(original == null) { if(methodExistsOnCopy(method.getName(), method, methodsOnClass)) { System.out.println("Changing method: " + methodName); //method.setBody(createAccessorBody(returnType, methodName)); method.setBody(createReturnBody(returnType)); } else { System.out.println("Adding new method (override from super): " + method.getName()); CtMethod accessor = CtNewMethod.make( returnType, method.getName(), parameterTypes, exceptionTypes, // createAccessorBody(returnType, methodName), createReturnBody(returnType), copy); copy.addMethod(accessor); } } else { System.out.println("Adding new method: " + method.getName()); try { CtMethod accessor = CtNewMethod.make( returnType, method.getName(), parameterTypes, exceptionTypes, //createAccessorBody(returnType, methodName), createReturnBody(returnType), copy); copy.addMethod(accessor); } catch(Exception e) { System.out.println("Got exception when adding method "+method.getName()+" to class"); e.printStackTrace(); } } } else { if(original == null) { if(methodExistsOnCopy(method.getName(), method, methodsOnClass)) { System.out.println("Changing void method: " + method.getName()); method.setBody("{ System.out.println(\"calling method: "+method.getName()+"\");}"); } else { System.out.println("Adding void method (override from super): " + method.getName()); CtMethod voidMethod = CtNewMethod.make(returnType, method.getName(), parameterTypes, exceptionTypes, "{ System.out.println(\"calling method: "+method.getName()+"\");}", copy); copy.addMethod(voidMethod); } } else { System.out.println("Adding void method: " + method.getName()); CtMethod voidMethod = CtNewMethod.make(returnType, method.getName(), parameterTypes, exceptionTypes, "{ System.out.println(\"calling method: "+method.getName()+"\");}", copy); copy.addMethod(voidMethod); } } } } catch (NotFoundException e) { throw new RuntimeException("Not found: " + e); } catch (CannotCompileException e) { throw new RuntimeException("Cannot compile: " + e); } } } private static boolean methodExistsOnCopy(String methodName, CtMethod method, CtMethod[] methodsOnClass) { for (int i = 0; i < methodsOnClass.length; i++) { CtMethod m = methodsOnClass[i]; try { if(m.getName().equals(methodName)) { if(m.getParameterTypes().length == method.getParameterTypes().length) { CtClass[] mParams = m.getParameterTypes(); CtClass[] methodParams = method.getParameterTypes(); for(int j = 0;j < mParams.length;j++) { if(!(mParams[j].getName().equals(methodParams[j].getName()))) { continue; } } if(m.getReturnType().getName().equals(method.getReturnType().getName())) { return true; } } } } catch(NotFoundException e) { return false; } } return false; } private static String createReturnBody(CtClass returnType) { StringBuffer buffer = new StringBuffer("return "); if(returnType.isPrimitive()) { if(returnType.equals(CtClass.booleanType)) buffer.append("false;"); else buffer.append("0;"); } else { if(returnType.getConstructors() != null && returnType.getConstructors().length > 0) buffer.append(" new ").append(returnType.getName()).append("();"); else buffer.append(" null;"); } return buffer.toString(); } } --- NEW FILE: MockInjector.java --- package org.contestj.duplicator; import org.contestj.introduction.Mock; import org.contestj.introduction.MockImpl; import javassist.CannotCompileException; import javassist.ClassPool; import javassist.CtClass; import javassist.CtField; import javassist.CtMethod; import javassist.NotFoundException; /** * MockInjector. * * @author <a href="st...@gm...">Stale W. Pedersen</a> * @version $Revision: 1.1 $ */ public class MockInjector { public static CtClass injectMock(CtClass clazz) { CtClass mockInterface = getCtClass(Mock.class.getName()); CtClass mockClass = getCtClass(MockImpl.class.getName()); //clazz.addInterface(mockInterface); CtField[] mockFields = mockClass.getFields(); try { for(CtField field : mockFields) clazz.addField(field); } catch (CannotCompileException e) { // TODO Auto-generated catch block e.printStackTrace(); } CtMethod[] mockMethods = mockClass.getMethods(); try { for(CtMethod method : mockMethods) { System.out.println("adding method: "+method.getName()); clazz.addMethod(method); } } catch (CannotCompileException e) { // TODO Auto-generated catch block e.printStackTrace(); } return clazz; } private static CtClass getCtClass(String name) { ClassPool cPool = ClassPool.getDefault(); CtClass ctMock = null; try { ctMock = cPool.get(name); } catch (NotFoundException e) { throw new RuntimeException("Not found: " + e.getMessage()); } return ctMock; } } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:22
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/conf/method In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/conf/method Added Files: method-aop.xml Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: method-aop.xml --- <?xml version="1.0" encoding="UTF-8"?> <aop> <bind pointcut="execution(public * org.contestj.test.mock.clazz.Bar->getData())"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> <bind pointcut="execution(public * org.contestj.test.mock.clazz.Bar->getData2(int))"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> <bind pointcut="execution(static * org.contestj.test.mock.clazz.Bar->getData3())"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> <bind pointcut="execution(public * org.contestj.test.mock.clazz.Bar->doStuff())"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> <bind pointcut="execution(public * org.contestj.test.mock.clazz.Bar->returnStuff(..))"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> </aop> |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:22
|
Update of /cvsroot/contestj/contestj/contestj2/src/main/java/org/contestj/mockservice In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/main/java/org/contestj/mockservice Added Files: MockInvocationHandler.java MockService.java ContestJSetup.java MockMethod.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: MockMethod.java --- package org.contestj.mockservice; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Iterator; import org.apache.log4j.Logger; /** * This class wraps a java.lang.reflect.Method object, and implements the * ability to set the desired return value etc. * * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * * */ public class MockMethod { private Method method = null; private Class originatingClass = null; private ArrayList returnValues = null; private ArrayList arguments = null; private RuntimeException exception = null; private long waitTime = 0L; private boolean timedOnly = false; private long timeToWait = 0L; private MockInvocationHandler invocationHandler; private Logger logger = Logger.getLogger(MockMethod.class); /** * This constructor is calls the other constructor for void methods (using * new Class[0] as the arguments). * * @param originatingClass * @param method */ public MockMethod(String originatingClass, String method) { this(originatingClass, method, new Class[0]); } /** * This constructor looks up the method on the class and initializes the local * variables. * * @param originatingClass * @param method */ public MockMethod(String originatingClass, String method, Class[] methodArguments) { try { this.originatingClass = Class.forName(originatingClass); this.method = this.originatingClass.getDeclaredMethod(method, methodArguments); returnValues = new ArrayList(); arguments = new ArrayList(); } catch (Exception e) { throw new RuntimeException("Could not define mock because of reflection errors: " + e); } } public MockMethod(String originatingClass, String method, Class[] methodArguments, MockInvocationHandler invocation) { this(originatingClass, method, methodArguments); this.invocationHandler = invocation; } /** * This constructor takes Class and Method reflection objects * as arguments in order to be a lot more rigid and avoid errors * because of classes not found etc. * * @param originatingClass * @param method */ public MockMethod(String originatingClass, String method, long milliSeconds) { this(originatingClass, method); //set up the waiting time this.waitTime = milliSeconds; } /** * Set up the return value for the invocation of the method. Note that * for this to be foolproof it needs to get in an object of the same type * as the original method, else you will get classcast exceptions. * * @param returnValue */ public void setupInvoke(Object returnValue) { returnValues.add(returnValue); } /** * Set up an exception to be thrown when the invoke method is called. If this * exception is not set (defaults to null) or set to null, it will not be used, * if it is anything other than null, it will always be thrown on invoke. * * @param exception */ public void setupInvokeException(RuntimeException exception) { this.exception = exception; } public Method getMethod() { return method; } public Class getOriginatingClass() { return originatingClass; } public MockInvocationHandler getInvocationHandler() { return invocationHandler; } public void setInvocationHandler(MockInvocationHandler invHandler) { invocationHandler = invHandler; logger.debug("Setting invocation handler to: "+invHandler.toString()); } /** * Returns the first set up value or throws an exception (if the exception is not null) * * Note that this method returns FIFO according to the setupInvoke methods that were added * at the back of the array. * * @return */ public Object invoke(Object[] argument) { if(waitTime > 0) { System.out.println("Waiting for: ."+waitTime); new WaitThread(waitTime).run(); } arguments.add(argument); if(exception == null) { if(invocationHandler != null) { Object result = invocationHandler.invoke(argument); return result; } else { Iterator iter = returnValues.iterator(); Object result = null; if (iter.hasNext()) { result = iter.next(); } if(result == null && returnValues.size() == 0) { throw new RuntimeException("setupInvoke was not configured with enough return values!"); } returnValues.remove(0); System.out.println("Returning object: "+result.getClass().getName()); return result; } } throw exception; } /** * This method returns the arguments that were passed to the mock method in the * order they were called. * * @return */ public Object getArgument() { if(arguments.size() == 0) { throw new RuntimeException("getArgument was invoked without more arguments!"); } Iterator iter = arguments.iterator(); Object argument = null; while(iter.hasNext()) { argument = iter.next(); } arguments.remove(argument); return argument; } private class WaitThread extends Thread { private long waitTime; /* (non-Javadoc) * @see java.lang.Runnable#run() */ public void run() { super.run(); try { sleep(waitTime); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public WaitThread(long milliSeconds) { this.waitTime = milliSeconds; } } public boolean isTimedOnly() { return timedOnly; } public long getTimeToWait() { return timeToWait; } public void setTimedOnly(boolean timedOnly, long timeToWait) { this.timedOnly = timedOnly; this.timeToWait = timeToWait; } } --- NEW FILE: MockService.java --- /* * Created on Aug 3, 2004 * * Copyright (C) 2004 Thomas Roka-Aardal */ package org.contestj.mockservice; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.apache.log4j.Logger; /** * This class is a singleton that holds references to mocked classes and their * settings for use in a test environment. For more information, refer to * various articles on using AspectJ and MockObjects for unit testing. * * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * * */ public class MockService { private Logger logger = Logger.getLogger(MockService.class); private static MockService instance = new MockService(); private Map mockObjectReferences = null; private Map mockMethodReferences = null; protected MockService() { logger.debug("ContestJMockService initialized"); mockObjectReferences = new Hashtable(); mockMethodReferences = new Hashtable(); } public static MockService getInstance() { return instance; } /** * Adds a mock method to the internal map, intended to be * used to mock both static and non-static methods. * * It uses fully.qualified.classname::methodname as the key in * the private map. * * @param mockMethod */ public void addMockMethod(MockMethod mockMethod) { String classAndMethod = generateMethodKey(mockMethod.getOriginatingClass().getName(), mockMethod.getMethod().getName()); logger.debug("ContestJMockService::addMockMethod adding mock for key: " + classAndMethod); mockMethodReferences.put(classAndMethod, mockMethod); } /** * * @param mock */ public void addMock(Object mock) { String className = mock.getClass().getSuperclass().getName(); logger.debug("ContestJMockService::addMock adding mock for class: " + className); mockObjectReferences.put(className, mock); } /** * @return Mock objects in service */ public Map getMocks() { return mockObjectReferences; } /** * @return Mock methods in service */ public Map getMockMethods() { return mockMethodReferences; } /** * Prints mock object keys to System.out for debug purposes. */ public void printMockObjectKeysToSystemOut() { String mocklist = ""; Iterator iterKeys = mockObjectReferences.keySet().iterator(); int counter = 0; while (iterKeys.hasNext()) { Object key = iterKeys.next(); mocklist += "\"" + key + "\" "; counter++; } if (mocklist.equals("")) { System.out.println("[ContestJMockService] There are no keys for mock objects in ContestJMockService right now."); } else { System.out.println("[ContestJMockService] Keys (count=" + counter + ") for mock objects in ContestJMockService right now: " + mocklist); } } /** * Prints mock method keys to System.out for debug purposes. */ public void printMockMethodKeysToSystemOut() { String mocklist = ""; Iterator iterKeys = mockMethodReferences.keySet().iterator(); int counter = 0; while (iterKeys.hasNext()) { Object key = iterKeys.next(); mocklist += "\"" + key + "\" "; counter++; } if (mocklist.equals("")) { System.out.println("[ContestJMockService] There are no keys for mock methods in ContestJMockService right now."); } else { System.out.println("[ContestJMockService] Keys (count=" + counter + ") for mock methods in ContestJMockService right now: " + mocklist); } } /** * * @param interfaceToMock * @return */ public Object getMockForInterface(Class interfaceToMock) { logger.debug("ContestJMockService::getMockForInterface requesting mock for interface: " + interfaceToMock); Set keys = mockObjectReferences.keySet(); for (Iterator iter = keys.iterator(); iter.hasNext();) { String element = (String) iter.next(); logger.debug("ContestJMockService::getMockForInterface checking against registered mock: " + element); if(element.equals(interfaceToMock.getName())) { logger.debug("ContestJMockService::getMockForInterface found mock for interface: " + interfaceToMock); return mockObjectReferences.get(element); } } logger.debug("ContestJMockService::getMockForInterface didn't find mock for interface: " + interfaceToMock); return null; } /** * This method checks the private method map to see if a certain method * is registered on the service. If it is, it is returned. * * @param method * @return */ public MockMethod getMockForMethod(String className, String methodName) { String keyToFind = generateMethodKey(className, methodName); System.out.println("ContestJMockService::getMockForMethod requesting mock for method: " + keyToFind); Set keys = mockMethodReferences.keySet(); for (Iterator iter = keys.iterator(); iter.hasNext();) { String key = (String) iter.next(); if(key.equals(keyToFind)) { logger.debug("ContestJMockService::getMockForMethod found mock for method: " + keyToFind); return (MockMethod) mockMethodReferences.get(key); } } logger.debug("ContestJMockService::getMockForMethod didn't find mock for method: " + keyToFind); return null; } /** * @param mockMethod * @return */ private String generateMethodKey(String className, String methodName) { String classAndMethod = new StringBuffer().append(className) .append("::") .append(methodName) .toString(); return classAndMethod; } /** * Resets the mocks in the singleton * */ public void reset() { logger.debug("ContestJMockService resetting values"); mockMethodReferences.clear(); mockObjectReferences.clear(); } } --- NEW FILE: MockInvocationHandler.java --- package org.contestj.mockservice; /** * MockInvocationHandler. * * @author <a href="st...@gm...">Stale W. Pedersen</a> * @version $Revision: 1.1 $ */ public interface MockInvocationHandler { public Object invoke(Object[] o); } --- NEW FILE: ContestJSetup.java --- package org.contestj.mockservice; import org.contestj.introduction.Mock; /** * A simple replacement of the original ContestJSetup. * * @author <a href="st...@gm...">Stale W. Pedersen</a> * @version $Revision: 1.1 $ */ public class ContestJSetup { /** * This method primes the mock method with a return value so that it returns expected * results. This will only work on classes thats already been duplicated by * Duplicator. * * Note that for use with varargs in Java5 you need to tell this method that the arguments * are an array (because that is how the bytecode works). So if you have a method: * doStuff(String ... args) * ...you need to tell this method that the arguments are an array of strings (String[].class). * * Multiple invocations on this method stacks return values. * * @param instance * @param method * @param arguments * @param returnValue */ public static void setup(Object instance, String method, Class[] arguments, Object returnValue) { if(arguments != null && arguments.length > 0) { ((Mock) instance).setupMock(method, arguments, returnValue); } else { ((Mock) instance).setupMock(method, returnValue); } } /** * This method primes the mock method with an exception value so that it returns expected * results. * * Note that for use with varargs in Java5 you need to tell this method that the arguments * are an array (because that is how the bytecode works). So if you have a method: * doStuff(String ... args) * ...you need to tell this method that the arguments are an array of strings (String[].class). * * * @param method * @param arguments * @param exception */ public static void setupException(Object instance, String method, Class[] arguments, Object exception) { if(arguments != null && arguments.length > 0) { ((Mock) instance).setupExceptionMock(method, arguments, new Exception(exception.toString())); } else { ((Mock) instance).setupExceptionMock(method, new Exception(exception.toString())); } } } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:20
|
Update of /cvsroot/contestj/contestj/contestj2/src/main/java/org/contestj/annotation In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/main/java/org/contestj/annotation Added Files: MockClass.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: MockClass.java --- package org.contestj.annotation; /** * * @author <a href="st...@gm...">Stale W. Pedersen</a> * @version $Revision: 1.1 $ */ public @interface MockClass { } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:20
|
Update of /cvsroot/contestj/contestj/contestj2/src/main/java/org/contestj/util In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/main/java/org/contestj/util Added Files: Generator.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: Generator.java --- package org.contestj.util; public class Generator { public static String generateMethodName(String method, Object[] params) { StringBuffer setupMethodName = new StringBuffer(); setupMethodName.append(method); for (int i = 0; i < params.length; i++) { Class argument = params[i].getClass(); setupMethodName.append("_"); String simpleName = argument.getSimpleName(); if(argument.isArray()) { simpleName = simpleName.replaceAll("\\[\\]", "Array"); } setupMethodName.append(simpleName); } return setupMethodName.toString(); } } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:19
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/conf In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/conf Added Files: mock-test-aop.xml Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: mock-test-aop.xml --- <?xml version="1.0" encoding="UTF-8"?> <aop> <!-- All classes thats fully mocked must be described like this. The only thing that need to be changed from class to class is class="path.to.class.and.classname" --> <introduction class="org.contestj.mock.simpleclass.Bar"> <mixin> <interfaces> org.contestj.introduction.Mock </interfaces> <class> org.contestj.introduction.MockImpl </class> <construction> new org.contestj.introduction.MockImpl(this) </construction> </mixin> </introduction> <!-- add this for each class thats fully mocked, change the name for each class --> <pointcut name="bar" expr="execution(public * org.contestj.mock.simpleclass.Bar->*(..))"/> <!-- do not touch --> <pointcut name="mockMethods" expr="execution(public * *->getReturnObject(..))"/> <pointcut name="mockMethods2" expr="execution(public * *->setup(..))"/> <!-- for each fully mocked class you must add the pointcut to the end here. leave mockMethods and mockMethods2 be --> <bind pointcut="!mockMethods AND !mockMethods2 AND bar"> <interceptor class="org.contestj.interceptor.MockInterceptor"/> </bind> <!-- for each method thats mocked, add a line similar to this --> <bind pointcut="execution(public * org.contestj.mock.simpleclass.Foo->getBar())"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> <bind pointcut="execution(public * org.contestj.mock.simpleclass.Bar->getData())"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> </aop> |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:18
|
Update of /cvsroot/contestj/contestj/contestj2 In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2 Added Files: pom.xml README Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: README --- Contestj2 is an attempt to rewrite ContestJ to make it more flexible, easier to maintain and more features. The test can only be run manually (or within an ide).. more to come.. --- NEW FILE: pom.xml --- <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.contestj</groupId> <artifactId>contestj2</artifactId> <name>Contestj2</name> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <build> <sourceDirectory>src/main/java</sourceDirectory> <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory> <testSourceDirectory>src/test/java</testSourceDirectory> <outputDirectory>target/classes</outputDirectory> <testOutputDirectory>target/test-classes</testOutputDirectory> <defaultGoal>install</defaultGoal> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> <testResources> <testResource> <directory>src/test/resources</directory> </testResource> </testResources> <directory>target</directory> <finalName>${artifactId}-${version}</finalName> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ejb-plugin</artifactId> <version>2.1-SNAPSHOT</version> <configuration> <ejbVersion>3.0</ejbVersion> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ear-plugin</artifactId> <version>2.2</version> <configuration> <ejbVersion>3.0</ejbVersion> </configuration> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <excludes> <exclude>**/*DeepTest.java</exclude> <exclude>**/Abstract*Test.java</exclude> <exclude>**/Abstract*TestCase.java</exclude> <exclude>**/*$*</exclude> </excludes> </configuration> </plugin> <plugin> <artifactId>maven-idea-plugin</artifactId> <configuration> <jdkLevel>${jdkVersion}</jdkLevel> <jdkName>${jdkVersion}</jdkName> </configuration> </plugin> <plugin> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <source>${jdkVersion}</source> </configuration> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${jdkVersion}</source> <target>${jdkVersion}</target> </configuration> </plugin> </plugins> </pluginManagement> </build> <repositories> <repository> <id>apache_repo</id> <name>Aspiro repository</name> <url>http://people.apache.org/repo/m2-snapshot-repository</url> </repository> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Maven Repository Switchboard</name> <url>http://repo1.maven.org/maven2</url> </repository> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>jboss_repo</id> <name>JBoss Maven Repository</name> <url>http://repository.jboss.com/maven2</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <releases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Maven Plugin Repository</name> <url>http://repo1.maven.org/maven2</url> </pluginRepository> <pluginRepository> <releases/> <snapshots> <enabled>true</enabled> </snapshots> <id>apache-plugins</id> <url>http://people.apache.org/maven-snapshot-repository/</url> </pluginRepository> </pluginRepositories> <!-- <url>http://stdb.inpoc.com/maven-sites/amp-root</url> --> <dependencies> <dependency> <groupId>jboss</groupId> <artifactId>jboss-system</artifactId> <version>4.0.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>jboss</groupId> <artifactId>jboss-jmx</artifactId> <version>4.0.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>jboss.jboss-aop</groupId> <artifactId>jboss-aop</artifactId> <version>1.5.0.GA</version> <!-- <version>1.5.0.GA</version> --> <scope>provided</scope> </dependency> <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.4.GA</version> <scope>provided</scope> </dependency> <dependency> <groupId>jboss</groupId> <artifactId>jboss-cache</artifactId> <version>1.4.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.8</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <properties> <jdkVersion>1.5</jdkVersion> </properties> </project> |
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/backport/test In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/java/org/contestj/test/backport/test Added Files: TestTestCase.java TestFactory.java Test2.java TestInterface.java Test.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: TestInterface.java --- package org.contestj.test.backport.test; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * * @mock * */ public interface TestInterface { public String doStuff(); } --- NEW FILE: TestTestCase.java --- package org.contestj.test.backport.test; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import org.contestj.introduction.Mock; //import org.contestj.duplicator.Duplicator; import org.contestj.test.backport.example.BaseClass; import org.contestj.test.backport.example.Java5BaseClass; import org.contestj.mockservice.ContestJSetup; import org.contestj.mockservice.MockMethod; import org.contestj.mockservice.MockService; import org.contestj.mockservice.MockInvocationHandler; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * */ public class TestTestCase extends TestCase { public void setUp() throws Exception { super.setUp(); } public void tearDown() throws Exception { MockService.getInstance().reset(); super.tearDown(); } /** * "Replace a method call on a class with a configured MockMethod if available". * * This test attempts to do the same as the previous test, but without using interfaces and * mock objects. This is how we would do it if there is a specific method on a specific class * we would like to return something we can control. Enter MockMethod, which exposes similar * functionality as MockObjects, but is per method and can be used directly on classes. In * this example we obtain the Class and Method we would like to "swap" with a controlled version * by using reflection, and then we set the expected result value using setupInvoke(). Look in * jboss-aop.xml to see that the pointcut that allows this is the one that explicitly mentions * Test->doStuff and calls the "getMethod" advice. This advice checks if there are any mock methods * on our ConductMockService that match the intercepted Class::Method, and returns the mock method * result instead of the original one. Nice. * * @throws Exception */ public void testDoStuffWithMockMethod() throws Exception { Test test = new Test(); MockMethod mockMethod = new MockMethod(Test.class.getName(), "doStuff"); String result = "Mocked string by method"; mockMethod.setupInvoke(result); MockService.getInstance().addMockMethod(mockMethod); assertEquals("Should have been mocked by method string: ", result, test.doStuff()); test = null; } /** * "Replace a method call on a class with a configured MockMethod if available". * * This test attempts to do the same as the previous test waits a period before invoking. * * @throws Exception */ public void testDoStuffWithMockMethodAndWait() throws Exception { long waitTime = 500L; long startTime = System.currentTimeMillis(); Test test = new Test(); MockMethod mockMethod = new MockMethod(Test.class.getName(), "doStuff", waitTime); String result = "Mocked string by method"; mockMethod.setupInvoke(result); MockService.getInstance().addMockMethod(mockMethod); assertEquals("Should have been mocked by method string: ", result, test.doStuff()); long executionTime = System.currentTimeMillis() - startTime; assertTrue("Should have taken at least " + waitTime + " msec. executiontime", executionTime > waitTime); test = null; } /** * "Replace method call on class with method call on mock". * * This test makes use of classes mocked with mockobjects (not interfaces), and they need to be created * (for now) "manually" in the build script (see the __gen-mocks target). Look at jboss-aop.xml to see * that the pointcut that triggers this behaviour is the one that explicitly mentions all methods on * Test2 (Test2->*()). The advice method replaces a call to the real object to a call on the mock * object found on ConductMockService matching the Class on which the method is located. So when Test2->doStuff * is called, it checks to see if there are any MockTest2 classes registered, and delegates to them. * Note that this is different from the "Replace a call that returns an interface with one that returns * a mock of the interface if available" which you would use for instance for factories (like above). * It doesn't return your mock, it just calls it instead. Very magical. * * @throws Exception */ public void testDoStuffWithMockedClass() throws Exception { BaseClass test = new BaseClass(); // //BaseClass_duplicate mockTest = new BaseClass_duplicate(); // mockTest.setup_getValue(42); // MockService.getInstance().addMock(mockTest); //assertEquals("Should have been mocked value", 42, test.getValue()); // mockTest = null; // test = null; ((Mock) test).setupMock("getValue", 42); MockService.getInstance().addMock(test); assertEquals("Should have been mocked value", 42, test.getValue()); test = null; } /** * Same as test above, only now also tests the sequence in which things are returned * * @throws Exception */ public void testDoStuffWithMockedClassRepeatedly() throws Exception { BaseClass test = new BaseClass(); //BaseClass_duplicate mockTest = new BaseClass_duplicate(); // mockTest.setup_getValue(42); // mockTest.setup_getValue(666); // mockTest.setup_getValue(21); ((Mock) test).setupMock("getValue", 42); ((Mock) test).setupMock("getValue", 666); ((Mock) test).setupMock("getValue", 21); MockService.getInstance().addMock(test); assertEquals("Should have been mocked value", 42, test.getValue()); assertEquals("Should have been mocked value", 666, test.getValue()); assertEquals("Should have been mocked value", 21, test.getValue()); try { test.getValue(); fail("Should have thrown Exception when no more values exist!"); } catch(Exception e) { // Correct } //mockTest = null; test = null; } /** * "Replace static method call on class with method call on a configured MockMethod if available". * * @throws Exception */ public void testDoStuffWithStaticMockedMethod() throws Exception { MockMethod mm = new MockMethod(Test.class.getName(), "doStaticStuff"); String result = "This is a MOCKED result"; mm.setupInvoke(result); MockService.getInstance().addMockMethod(mm); assertEquals("Should have been mocked by mock method string: ", result, Test.doStaticStuff()); } /** * This test tests for that repreated calls to the same method will return the * configured objects (trough setupInvoke) in the proper order. * The order should be FIFO. (queue) */ public void testDoStuffWithMockMethodProperReturnedObjectsOrder() throws Exception { Test test = new Test(); MockMethod mockMethod = new MockMethod(Test.class.getName(), "doStuff"); String obj1 = "A1"; String obj2 = "B2"; String obj3 = "C3"; String obj4 = "D4"; mockMethod.setupInvoke(obj1); mockMethod.setupInvoke(obj2); mockMethod.setupInvoke(obj3); mockMethod.setupInvoke(obj4); MockService.getInstance().addMockMethod(mockMethod); assertEquals("Should have been mocked by method string: ", obj1, test.doStuff()); assertEquals("Should have been mocked by method string: ", obj2, test.doStuff()); assertEquals("Should have been mocked by method string: ", obj3, test.doStuff()); assertEquals("Should have been mocked by method string: ", obj4, test.doStuff()); test = null; } /** * This test verifies that we can make a duplicate class method throw an exception which * is set up by the test. This allows testing of various rainy day scenarios (like getting * HTTPClient to throw a timeout exception). * * @throws Exception */ public void testThrowExceptionFromDuplicate() throws Exception { // BaseInterface_duplicate dupe = new BaseInterface_duplicate(); // dupe.setup_getName_exception(new RuntimeException("From test")); BaseClass dupe = new BaseClass(); ((Mock) dupe).setupExceptionMock("getValue", new RuntimeException("From test")); try { dupe.getValue(); fail("Should have thrown exception!"); } catch(Exception e) { // Correct } } /** * This method tests that we can actually delay any method, but still return * whatever the original method should return. The alternative to this, timed * execution with a mocked result, can be achieved using the three-argument setupInvoke * method. * * @throws Exception */ public void testDoStuffWithMockMethodTimedOnly() throws Exception { Test test = new Test(); long timeToWait = 500L; MockMethod mockMethod = new MockMethod(Test.class.getName(), "doStuff"); mockMethod.setTimedOnly(true, timeToWait); //mockMethod.setupInvoke("Original string"); MockService.getInstance().addMockMethod(mockMethod); long startTime = System.currentTimeMillis(); assertEquals("Should have returned original string value", "Original string", test.doStuff()); assertTrue("Should have taken more than " + timeToWait + " msecs", System.currentTimeMillis() - startTime > timeToWait); } /** * This test just assures us that we support the mocking of methods with the same name * but with different sets of arguments. The Test class has two "doStuff" methods, one * of which takes a String as input. This test verifies (through the use of setTimedOnly) * that the original class is called and that the correct method of the two is called. * * @throws Exception */ public void testMockMethodWithMultipleMethodsWithSameName() throws Exception { Test test = new Test(); long timeToWait = 0L; String input = "input"; MockMethod mockMethod = new MockMethod(Test.class.getName(), "doStuff", new Class[] {String.class}); mockMethod.setTimedOnly(true, timeToWait); MockService.getInstance().addMockMethod(mockMethod); assertEquals("Should have been original value", "Input was: " + input, test.doStuff(input)); } /** * This test makes use of in-memory duplication so no class files are actually written to * disk. When using in-memory duplication one cannot cast the duplicate to its own type, * therefore one needs to use the utility class ContestJSetup (which uses reflection) to * setup the methods for testing accordingly. * * @throws Exception */ public void testInMemoryDuplication() throws Exception { BaseClass base = new BaseClass(); int result = 42; //BaseClass dupe = (BaseClass) Duplicator.duplicate(BaseClass.class.getName()); ContestJSetup.setup(base, "getValue", new Class[0], result); MockService.getInstance().addMock(base); assertEquals("Should have returned mocked value", 42, base.getValue()); } /** * Similar to the above in-memory test, except tests for java5 generics. * * @throws Exception */ public void testInMemoryJava5Duplication() throws Exception { Java5BaseClass base = new Java5BaseClass(); List<String> result = new ArrayList<String>(); result.add(new String("123")); // Java5BaseClass dupe = (Java5BaseClass) Duplicator.duplicate(Java5BaseClass.class.getName()); ContestJSetup.setup(base, "getValue", new Class[0], result); MockService.getInstance().addMock(base); assertEquals("Should have returned mocked value", result, base.getValue()); } public void testMockMethodWithInvocationObject() throws Exception { Test test = new Test(); //long timeToWait = 0L; String input = "input"; MockInvocationHandler handler = new MockInvocationHandler() { public Object invoke(Object[] args) { //String s = (String) args; System.out.println("Inside invoke object, got: "+args[0].toString()); //return "blada"; return args[0]; } public String toString() { return "blada"; } }; MockMethod mockMethod = new MockMethod(Test.class.getName(), "doInvocationStuff", new Class[] {String.class} ); mockMethod.setInvocationHandler(handler); //mockMethod.setTimedOnly(true, timeToWait); MockService.getInstance().addMockMethod(mockMethod); System.out.println("testing...."); assertEquals("Should have been original value", input, test.doInvocationStuff(input)); //assertEquals("Should have been original value", input, test.doStuff(input)); } } --- NEW FILE: TestFactory.java --- package org.contestj.test.backport.test; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * */ public class TestFactory { public TestInterface getTestInterfaceImplementation() { return new Test2(); } } --- NEW FILE: Test2.java --- package org.contestj.test.backport.test; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * */ public class Test2 implements TestInterface { public String doStuff() { return "Original string"; } } --- NEW FILE: Test.java --- package org.contestj.test.backport.test; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * */ public class Test { private TestInterface test2 = null; public String doStuff() { TestFactory factory = new TestFactory(); test2 = factory.getTestInterfaceImplementation(); return test2.doStuff(); } public String doStuff(String value) { return "Input was: " + value; } public static String doStaticStuff() { return "This is a static Hello"; } public String doInvocationStuff(String value) { return "foo"; } } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:18
|
Update of /cvsroot/contestj/contestj/contestj2/src/main/java/org/contestj/interceptor In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/main/java/org/contestj/interceptor Added Files: MockInterceptor.java MockMethodInterceptor.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: MockInterceptor.java --- package org.contestj.interceptor; import org.contestj.introduction.Mock; import org.contestj.mockservice.MockMethod; import org.contestj.mockservice.MockService; import org.jboss.aop.advice.Interceptor; import org.jboss.aop.joinpoint.Invocation; import org.jboss.aop.joinpoint.MethodInvocation; /** * MockInterceptor. * * @author <a href="st...@gm...">Stale W. Pedersen</a> * @version $Revision: 1.1 $ */ public class MockInterceptor implements Interceptor { public String getName() { return "MockInterceptor"; } public Object invoke(Invocation invocation) throws Throwable { System.out.println("inside MockInterceptor"); if(invocation instanceof MethodInvocation) { MethodInvocation mi = (MethodInvocation) invocation; System.out.println("its a methodinvocation: "+mi.getMethod().getName()); MockMethod mock = null; if(mi.getTargetObject() != null) { System.out.println("Targetobject is not null: "+mi.getTargetObject().getClass().getName()); Object target = mi.getTargetObject(); Object[] params = mi.getArguments(); Object returnValue = ((Mock) target).getReturnObject(mi.getMethod().getName()); System.out.println("Returnvalue is: "+returnValue); return returnValue; //mock = MockService.getInstance().getMockForMethod(mi.getTargetObject().getClass().getName(), mi.getMethod().getName()); } else { System.out.println("targetobject is null, just invoking next in chain"); return invocation.invokeNext(); // String className = mi.getMethod().getDeclaringClass().getName(); // // mock = MockService.getInstance().getMockForMethod(className, mi.getMethod().getName()); } } System.out.println("not a methodinvocation, invoking next"); return invocation.invokeNext(); } } --- NEW FILE: MockMethodInterceptor.java --- package org.contestj.interceptor; import org.contestj.mockservice.MockMethod; import org.contestj.mockservice.MockService; import org.jboss.aop.advice.Interceptor; import org.jboss.aop.joinpoint.Invocation; import org.jboss.aop.joinpoint.MethodInvocation; /** * A MockMethodInterceptor. * * @author <a href="st...@gm...">Stale W. Pedersen</a> * @version $Revision: 1.1 $ */ public class MockMethodInterceptor implements Interceptor { public String getName() { return "MockMethodInterceptor"; } public Object invoke(Invocation invocation) throws Throwable { System.out.println("inside MockMethodInterceptor"); MockService.getInstance().printMockMethodKeysToSystemOut(); MethodInvocation mi = (MethodInvocation) invocation; MockMethod mock = null; if(mi.getTargetObject() == null) { String className = mi.getMethod().getDeclaringClass().getName(); mock = MockService.getInstance().getMockForMethod(className, mi.getMethod().getName()); if(mock != null) System.out.println("MockMethod is set to: "+mock.toString()); else { System.out.println("Mock is null, className: "+className+", method: "+mi.getMethod().getName()); } } else { System.out.println("Target object is NOT null.. method:"+mi.getMethod().getName()); mock = MockService.getInstance().getMockForMethod(mi.getTargetObject().getClass().getName(), mi.getMethod().getName()); } if(mock == null) return invocation.invokeNext(); else { if(mock.isTimedOnly()) { WaitThread waitThread = new WaitThread(mock.getTimeToWait()); waitThread.run(); return invocation.invokeNext(); } else { System.out.println("Contestj couldnt find any mockmethod, just invoking normally.."); return mock.invoke(mi.getArguments()); } } } private class WaitThread extends Thread { private long waitTime; /* (non-Javadoc) * @see java.lang.Runnable#run() */ public void run() { super.run(); try { sleep(waitTime); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public WaitThread(long milliSeconds) { this.waitTime = milliSeconds; } } } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:18
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/conf/backport/test In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/conf/backport/test Added Files: test-backport-aop.xml Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: test-backport-aop.xml --- <?xml version="1.0" encoding="UTF-8"?> <aop> <!-- All classes thats fully mocked must be described like this. The only thing that need to be changed from class to class is class="path.to.class.and.classname" --> <!-- <introduction class="org.contestj.test.mock.clazz.Bar"> <mixin> <interfaces> org.contestj.introduction.Mock </interfaces> <class> org.contestj.introduction.MockImpl </class> <construction> new org.contestj.introduction.MockImpl(this) </construction> </mixin> </introduction> --> <!-- add this for each class thats fully mocked, change the name for each class --> <!-- <pointcut name="bar" expr="execution(public * org.contestj.test.mock.clazz.Bar->*(..))"/> --> <!-- do not touch --> <!-- <pointcut name="mockMethods" expr="execution(public * *->getReturnObject(..))"/> <pointcut name="mockMethods2" expr="execution(public * *->setupMock(..))"/> <pointcut name="mockMethods3" expr="execution(public * *->setupVoidMock(..))"/> --> <!-- for each fully mocked class you must add the pointcut to the end here. leave (!mockMethods AND !mockMethods2 AND !mockMethods3) be as they are --> <!-- <bind pointcut="(!mockMethods AND !mockMethods2 AND !mockMethods3) AND bar"> <interceptor class="org.contestj.interceptor.MockInterceptor"/> </bind> --> <!-- for each method thats mocked, add a line similar to this --> <bind pointcut="execution(public * org.contestj.test.backport.test.TestFactory->getTestInterfaceImplementation())"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> <bind pointcut="execution(* org.contestj.test.backport.test.Test->doStuff())"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> <bind pointcut="execution(* org.contestj.test.backport.test.Test->doInvocationStuff(java.lang.String))"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> <bind pointcut="execution(static * org.contestj.test.backport.test.Test->doStaticStuff())"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> <!-- BaseClass Mocking --> <!-- All classes thats fully mocked must be described like this. The only thing that need to be changed from class to class is class="path.to.class.and.classname" --> <introduction class="org.contestj.test.backport.example.BaseClass"> <mixin> <interfaces> org.contestj.introduction.Mock </interfaces> <class> org.contestj.introduction.MockImpl </class> <construction> new org.contestj.introduction.MockImpl(this) </construction> </mixin> </introduction> <!-- add this for each class thats fully mocked, change the name for each class --> <pointcut name="baseclass" expr="execution(public * org.contestj.test.backport.example.BaseClass->getValue())"/> <!-- do not touch --> <pointcut name="mockMethods" expr="execution(public * *->getReturnObject(..))"/> <pointcut name="mockMethods2" expr="execution(public * *->setupMock(..))"/> <pointcut name="mockMethods3" expr="execution(public * *->setupVoidMock(..))"/> <!-- for each fully mocked class you must add the pointcut to the end here. leave (!mockMethods AND !mockMethods2 AND !mockMethods3) be as they are --> <bind pointcut="(!mockMethods AND !mockMethods2 AND !mockMethods3) AND baseclass"> <interceptor class="org.contestj.interceptor.MockInterceptor"/> </bind> <!-- Java5BaseClass Mocking --> <!-- All classes thats fully mocked must be described like this. The only thing that need to be changed from class to class is class="path.to.class.and.classname" --> <introduction class="org.contestj.test.backport.example.Java5BaseClass"> <mixin> <interfaces> org.contestj.introduction.Mock </interfaces> <class> org.contestj.introduction.MockImpl </class> <construction> new org.contestj.introduction.MockImpl(this) </construction> </mixin> </introduction> <!-- add this for each class thats fully mocked, change the name for each class --> <pointcut name="java5baseclass" expr="execution(public * org.contestj.test.backport.example.Java5BaseClass->getValue())"/> <!-- do not touch --> <pointcut name="mockMethods" expr="execution(public * *->getReturnObject(..))"/> <pointcut name="mockMethods2" expr="execution(public * *->setupMock(..))"/> <pointcut name="mockMethods3" expr="execution(public * *->setupVoidMock(..))"/> <!-- for each fully mocked class you must add the pointcut to the end here. leave (!mockMethods AND !mockMethods2 AND !mockMethods3) be as they are --> <bind pointcut="(!mockMethods AND !mockMethods2 AND !mockMethods3) AND java5baseclass"> <interceptor class="org.contestj.interceptor.MockInterceptor"/> </bind> </aop> |
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/duplicate In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/java/org/contestj/test/duplicate Added Files: DupeInterface.java DuplicateTest.java DupeAbstractClass.java SuperDupeInterface.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: DupeAbstractClass.java --- package org.contestj.test.duplicate; import java.util.ArrayList; import java.util.List; public abstract class DupeAbstractClass { public void initServices() { System.out.println("here we init some services that cant be called"); } public abstract void setAbstract(List<String> s); public abstract List<String> getAbstract(); } --- NEW FILE: DupeInterface.java --- package org.contestj.test.duplicate; public interface DupeInterface extends SuperDupeInterface { public void setInt(int i); public int getInt(); public String getString(); public void setString(String s); } --- NEW FILE: DuplicateTest.java --- package org.contestj.test.duplicate; import org.contestj.duplicator.Duplicator; import junit.framework.TestCase; public class DuplicateTest extends TestCase { public void testDupe1() { DupeInterface d = (DupeInterface) Duplicator.duplicate(DupeInterface.class.getName()); assertTrue(true); } public void testDupe2() { DupeAbstractClass d = (DupeAbstractClass) Duplicator.duplicate(DupeAbstractClass.class.getName()); assertTrue(true); } } --- NEW FILE: SuperDupeInterface.java --- package org.contestj.test.duplicate; public interface SuperDupeInterface { public void setSuper(Integer i); public String getSuper(); } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:18
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/conf/subclass In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/conf/subclass Added Files: subclass-aop.xml Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: subclass-aop.xml --- <?xml version="1.0" encoding="UTF-8"?> <aop> <!-- All classes thats fully mocked must be described like this. The only thing that need to be changed from class to class is class="path.to.class.and.classname" --> <introduction class="org.contestj.test.mock.subclass.SubPOJO"> <mixin> <interfaces> org.contestj.introduction.Mock </interfaces> <class> org.contestj.introduction.MockImpl </class> <construction> new org.contestj.introduction.MockImpl(this) </construction> </mixin> </introduction> <!-- add this for each class thats fully mocked, change the name for each class --> <pointcut name="subpojo" expr="execution(public * org.contestj.test.mock.subclass.SubPOJO->*(..))"/> <pointcut name="pojo" expr="execution(public * org.contestj.test.mock.subclass.POJO->*(..))"/> <!-- do not touch --> <pointcut name="mockMethods" expr="execution(public * *->getReturnObject(..))"/> <pointcut name="mockMethods2" expr="execution(public * *->setupMock(..))"/> <!-- for each fully mocked class you must add the pointcut to the end here. leave mockMethods and mockMethods2 be --> <bind pointcut="!mockMethods AND !mockMethods2 AND (subpojo OR pojo)"> <interceptor class="org.contestj.interceptor.MockInterceptor"/> </bind> <!-- for each method thats mocked, add a line similar to this --> <bind pointcut="execution(public * org.contestj.test.mock.subclass.Tester->getSubPOJO())"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> </aop> |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:18
|
Update of /cvsroot/contestj/contestj/contestj2/src/main/java/org/contestj/introduction In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/main/java/org/contestj/introduction Added Files: MockImpl.java Mock.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: Mock.java --- package org.contestj.introduction; /** * Every class thats duplicated/mocked can be casted to Mock. * Mock methods are used to setup method return values. * * @author <a href="st...@gm...">Stale W. Pedersen</a> * @version $Revision: 1.1 $ */ public interface Mock { public void setupMock(String methodName, Object returnObject); public void setupMock(String methodName, Object[] params, Object returnObject); public Object getReturnObject(String methodName); public Object getReturnObject(String methodName, Object[] params); public void setupVoidMock(String methodName); public void setupVoidMock(String methodName, Object[] params); public void setupExceptionMock(String methodName, Throwable t); public void setupExceptionMock(String methodName, Object[] params, Throwable t); } --- NEW FILE: MockImpl.java --- package org.contestj.introduction; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.contestj.util.Generator; /** * A MockImpl. * * TODO: need to check if method is static. if it is, add the invocation to MockService. * * @author <a href="st...@gm...">Stale W. Pedersen</a> * @version $Revision: 1.1 $ */ public class MockImpl implements Mock { private HashMap<String, List<Object>> invocationMap = new HashMap<String, List<Object>>(); private HashMap<String, List<Throwable>> exceptionMap = new HashMap<String, List<Throwable>>(); private List<String> voidInvocationList = new ArrayList<String>(); public MockImpl(Object o) { } public Object getReturnObject(String methodName) { System.out.println("getting object with key: "+methodName); System.out.println("size of invocationMap is: "+invocationMap.size()); // if its a void method we just return an empty object if(voidInvocationList.remove(methodName)) { return new Object(); } //getFromInvocationMap //Object o = invocationMap.remove(methodName); Object o = getFromInvocationMap(methodName); if(o != null) { return o; } Throwable t = getException(methodName); if(t != null) { throw new RuntimeException(t); } throw new RuntimeException("Method was not setup with enough return values."); //return invocationMap.remove(methodName); } public Object getReturnObject(String methodName, Object[] params) { return getReturnObject(Generator.generateMethodName(methodName, params)); //return invocationMap.remove(Generator.generateMethodName(methodName, params)); } public void setupMock(String methodName, Object returnObject) { addToInvocationMap(methodName, returnObject); System.out.println("size of invocationMap is: "+invocationMap.size()); } public void setupMock(String methodName, Object[] params, Object returnObject) { addToInvocationMap(Generator.generateMethodName(methodName, params), returnObject); } public void setupVoidMock(String methodName) { voidInvocationList.add(methodName); } public void setupVoidMock(String methodName, Object[] params) { voidInvocationList.add(Generator.generateMethodName(methodName, params)); } public void setupExceptionMock(String methodName, Throwable t) { addException(methodName, t); } public void setupExceptionMock(String methodName, Object[] params, Throwable t) { addException(Generator.generateMethodName(methodName, params), t); } private void addToInvocationMap(String methodName, Object returnObject) { List<Object> invocationList = invocationMap.remove(methodName); if(invocationList != null) { invocationList.add(returnObject); } else { invocationList = new ArrayList<Object>(); invocationList.add(returnObject); } invocationMap.put(methodName, invocationList); } private Object getFromInvocationMap(String methodName) { List<Object> invocationList = invocationMap.remove(methodName); if(invocationList != null && invocationList.size() > 0) { Object o = invocationList.remove(0); if(invocationList.size() > 0) invocationMap.put(methodName, invocationList); return o; } else return null; } private void addException(String methodName, Throwable t) { List<Throwable> exceptionList = exceptionMap.remove(methodName); if(exceptionList != null) { exceptionList.add(t); } else { exceptionList = new ArrayList<Throwable>(); exceptionList.add(t); } exceptionMap.put(methodName, exceptionList); } private Throwable getException(String methodName) { List<Throwable> exceptionList = exceptionMap.remove(methodName); if(exceptionList != null && exceptionList.size() > 0) { Throwable t = exceptionList.remove(0); if(exceptionList.size() > 0) exceptionMap.put(methodName, exceptionList); return t; } else return null; } } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:17
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/conf/clazz In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/conf/clazz Added Files: clazz-aop.xml Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: clazz-aop.xml --- <?xml version="1.0" encoding="UTF-8"?> <aop> <!-- All classes thats fully mocked must be described like this. The only thing that need to be changed from class to class is class="path.to.class.and.classname" --> <introduction class="org.contestj.test.mock.clazz.Bar"> <mixin> <interfaces> org.contestj.introduction.Mock </interfaces> <class> org.contestj.introduction.MockImpl </class> <construction> new org.contestj.introduction.MockImpl(this) </construction> </mixin> </introduction> <!-- add this for each class thats fully mocked, change the name for each class --> <pointcut name="bar" expr="execution(public * org.contestj.test.mock.clazz.Bar->*(..))"/> <!-- do not touch --> <pointcut name="mockMethods" expr="execution(public * *->getReturnObject(..))"/> <pointcut name="mockMethods2" expr="execution(public * *->setupMock(..))"/> <pointcut name="mockMethods3" expr="execution(public * *->setupVoidMock(..))"/> <!-- for each fully mocked class you must add the pointcut to the end here. leave (!mockMethods AND !mockMethods2 AND !mockMethods3) be as they are --> <bind pointcut="(!mockMethods AND !mockMethods2 AND !mockMethods3) AND bar"> <interceptor class="org.contestj.interceptor.MockInterceptor"/> </bind> <!-- for each method thats mocked, add a line similar to this --> <bind pointcut="execution(public * org.contestj.test.mock.clazz.Foo->getBar())"> <interceptor class="org.contestj.interceptor.MockMethodInterceptor"/> </bind> </aop> |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:17
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/backport/example In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/java/org/contestj/test/backport/example Added Files: BaseInterface.java BaseClass.java AbstractClass.java Java5BaseInterface.java OverloadedMethodsClass.java Java5BaseClass.java InnerClass.java SubclassOfAbstractClass.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: SubclassOfAbstractClass.java --- package org.contestj.test.backport.example; public class SubclassOfAbstractClass extends AbstractClass { @Override public int getValueAbstract() { // TODO Auto-generated method stub return 0; } public void setValueAbstract(int v) { } } --- NEW FILE: BaseClass.java --- package org.contestj.test.backport.example; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * */ public class BaseClass { private int value; private int[] valueArray; public void setValue(int value) { this.value = value; } public int getValue() { return value; } public void setValueArray(int[] v) { valueArray = v; } public int[] getValueArray() { return valueArray; } public void setValueToOne() throws Exception { throw new Exception("This should never occure"); } } --- NEW FILE: Java5BaseInterface.java --- package org.contestj.test.backport.example; import java.util.List; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * */ public interface Java5BaseInterface { public List<String> getValue(); public void setValue(List<String> value); public String getName(List<String> value) throws Exception; } --- NEW FILE: Java5BaseClass.java --- package org.contestj.test.backport.example; import java.util.ArrayList; import java.util.List; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * */ public class Java5BaseClass { private List<String> value = new ArrayList<String>(); public void setValue(List<String> value) { this.value = value; } public List<String> getValue() { return value; } public int getStuff(List<String> list) { return 42; } public List<String> getValue(List<String> list) { return value; } public List<String> getValue(String list) { return value; } public String getStuffByAnyNumberOfArguments(String ... args) { return "Jalla"; } } --- NEW FILE: OverloadedMethodsClass.java --- package org.contestj.test.backport.example; public class OverloadedMethodsClass { public String getStuff() { return "Stuff"; } public String getStuff(String otherStuff) { return otherStuff; } } --- NEW FILE: InnerClass.java --- package org.contestj.test.backport.example; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * */ public class InnerClass { public InnerClass() { } public String getGreeting() { return "Hello world"; } public class MyInnerClass { public MyInnerClass() { } private int value; public int getValue() { return value; } } } --- NEW FILE: AbstractClass.java --- package org.contestj.test.backport.example; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * */ public abstract class AbstractClass { private int value; public void setValue(int value) { this.value = value; } public int getValue() { return value; } public List<String> getValue(Date now, Date then) { ArrayList<String> x = new ArrayList<String>(); x.add("Hello from test"); return x; } public abstract int getValueAbstract(); public abstract void setValueAbstract(int v); } --- NEW FILE: BaseInterface.java --- package org.contestj.test.backport.example; /** * Part of the contestJ test framework. * * Distributed under the terms of the LGPL. * * Copyright (C) 2005 Thomas Roka-Aardal * * @author Thomas Roka-Aardal * */ public interface BaseInterface { public int getValue(); public void setValue(int value); public String getName() throws Exception; } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:17
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/mock/subclass In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/java/org/contestj/test/mock/subclass Added Files: SubClassMockTest.java SubPOJO.java Tester.java POJO.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: POJO.java --- package org.contestj.test.mock.subclass; public class POJO { public int getPojoData() { return 1; } } --- NEW FILE: SubClassMockTest.java --- package org.contestj.test.mock.subclass; import org.contestj.introduction.Mock; import org.contestj.mockservice.MockMethod; import org.contestj.mockservice.MockService; import org.contestj.test.mock.clazz.Bar; import org.contestj.test.mock.clazz.Foo; import junit.framework.TestCase; public class SubClassMockTest extends TestCase { public void testSubClassMock() { MockMethod method = new MockMethod(Tester.class.getName(), "getSubPOJO"); SubPOJO sub = new SubPOJO(); ((Mock) sub).setupMock("getSubPojoData", new Integer(3)); ((Mock) sub).setupMock("getPojoData", new Integer(4)); method.setupInvoke(sub); MockService.getInstance().addMockMethod(method); Tester t = new Tester(); int i = t.testPOJOs(); assertEquals("Test failed, bah! ", 7, i); } } --- NEW FILE: SubPOJO.java --- package org.contestj.test.mock.subclass; public class SubPOJO extends POJO { public int getSubPojoData() { return 2; } } --- NEW FILE: Tester.java --- package org.contestj.test.mock.subclass; public class Tester { public int testPOJOs() { SubPOJO sub = getSubPOJO(); int i = sub.getPojoData() + sub.getSubPojoData(); return i; } public SubPOJO getSubPOJO() { return new SubPOJO(); } } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:17
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/mock/method In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/java/org/contestj/test/mock/method Added Files: MethodMockTest.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: MethodMockTest.java --- package org.contestj.test.mock.method; import org.contestj.mockservice.MockInvocationHandler; import org.contestj.mockservice.MockMethod; import org.contestj.mockservice.MockService; import org.contestj.test.mock.clazz.Bar; import org.contestj.test.mock.clazz.Foo; import junit.framework.TestCase; public class MethodMockTest extends TestCase { public void testMethodMock() { MockMethod method = new MockMethod(Bar.class.getName(), "getData"); method.setupInvoke(new Integer(2)); MockService.getInstance().addMockMethod(method); Foo f = new Foo(); int i = f.business2(); assertEquals("Test failed, bah! ", 4, i); } public void testMethodWithParamsMock() { MockMethod method = new MockMethod(Bar.class.getName(), "getData2", new Class[] {int.class}); method.setupInvoke(new Integer(2)); MockService.getInstance().addMockMethod(method); Foo f = new Foo(); int i = f.business3(); assertEquals("Test failed, bah! ", 4, i); } public void testStaticMethodMock() { MockMethod method = new MockMethod(Bar.class.getName(), "getData3"); method.setupInvoke(new Integer(4)); MockService.getInstance().addMockMethod(method); Foo f = new Foo(); int i = f.business4(); assertEquals("Test failed, bah! ", 4, i); } public void testVoidMethodMock() { MockMethod method = new MockMethod(Bar.class.getName(), "doStuff"); method.setupInvoke(new Integer(1)); MockService.getInstance().addMockMethod(method); Bar b = new Bar(); try { b.doStuff(); assertTrue("Void tests sucessfully mocked", true); } catch(Exception e) { assertTrue("Failed to mock void tests", false); } } public void testInvocationHandlerMethodMock() { Bar b = new Bar(); String input = "input"; MockInvocationHandler handler = new MockInvocationHandler() { public Object invoke(Object[] args) { //String s = (String) args; System.out.println("Inside invoke object, got: "+args[0].toString()); //return "blada"; return args[0]; } }; MockMethod mockMethod = new MockMethod(Bar.class.getName(), "returnStuff", new Class[] {String.class} ); mockMethod.setInvocationHandler(handler); //mockMethod.setTimedOnly(true, timeToWait); MockService.getInstance().addMockMethod(mockMethod); System.out.println("testing...."); assertEquals("Should have been original value", input, b.returnStuff(input)); } } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:16
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/mock/clazz In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/java/org/contestj/test/mock/clazz Added Files: Foo.java Bar.java ClazzMockTest.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: ClazzMockTest.java --- package org.contestj.test.mock.clazz; import org.contestj.introduction.Mock; import org.contestj.mockservice.MockMethod; import org.contestj.mockservice.MockService; import junit.framework.TestCase; /** * A ClazzMockTest. * * @author <a href="st...@gm...">Stale W. Pedersen</a> * @version $Revision: 1.1 $ */ public class ClazzMockTest extends TestCase { public void testMock() { MockMethod method = new MockMethod(Foo.class.getName(), "getBar"); Bar b = new Bar(); ((Mock) b).setupMock("getData", new Integer(2)); ((Mock) b).setupVoidMock("doStuff"); method.setupInvoke(b); MockService.getInstance().addMockMethod(method); Foo f = new Foo(); int i = f.business(); assertEquals("Method wasnt invoked correctly ", 4, i); } } --- NEW FILE: Bar.java --- package org.contestj.test.mock.clazz; public class Bar { public int getData() { return 1; } public int getData2(int i) { return i + 2; } public static int getData3() { return 3; } public void doStuff() { throw new RuntimeException("Error: you should never reach here..."); } public String returnStuff(String s) { return "stuff"; } } --- NEW FILE: Foo.java --- package org.contestj.test.mock.clazz; public class Foo { public int business() { Bar b = getBar(); int i =2 + b.getData(); b.doStuff(); return i; } public Bar getBar() { return new Bar(); } public int business2() { Bar b = new Bar(); int i =2 + b.getData(); return i; } public int business3() { Bar b = new Bar(); int i =2 + b.getData2(2); return i; } public int business4() { return Bar.getData3(); } } |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:51:27
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13251/contestj2/src/test/java Log Message: Directory /cvsroot/contestj/contestj/contestj2/src/test/java added to the repository |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:51:26
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13251/contestj2/src/test/java/org Log Message: Directory /cvsroot/contestj/contestj/contestj2/src/test/java/org added to the repository |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:51:25
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/duplicate In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13251/contestj2/src/test/java/org/contestj/test/duplicate Log Message: Directory /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/duplicate added to the repository |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:51:25
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/backport/example In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13251/contestj2/src/test/java/org/contestj/test/backport/example Log Message: Directory /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/backport/example added to the repository |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:51:24
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13251/contestj2/src/test/java/org/contestj Log Message: Directory /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj added to the repository |
|
From: Ståle P. <st...@us...> - 2007-06-20 14:51:22
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13251/contestj2/src/test/java/org/contestj/test Log Message: Directory /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test added to the repository |