Menu

First go at Interfaces for MockLib 2

Developers
Nobody
2005-11-10
2013-04-17
  • Nobody

    Nobody - 2005-11-10

    [code]
    package biz.xsoftware.mock2;

    /**
    * The factory class that creates MockObjects
    *
    * @author Dann Ormond
    *
    */
    public abstract class MockObjectFactory {
        public static MockObject createMock(Class[] interfacesToMock) {
            // TODO: Implement me!
            return null;
        }
       
       
        public static MockObject createMock(Class interfaceToMock) {
            return createMock(new Class[] { interfaceToMock });;
        }
        public static MockObject createMock(Class interfaceToMock, Object realObject) {
            // TODO: Implement me!
            return null;
        }
    }

    package biz.xsoftware.mock2;

    /**
    *
    * @author Dann Ormond
    *
    */
    public interface MockObject {
        /**
         * Expect a method to be called with no return value.  The default
         * timeout is 10 seconds.
         *
         * @param methodName the name of the method to expect
         * @param vargs the optional parmeter types of the method call
         * @return the CalledMethod information that will be filled after
         *         the method is called
         */
        public CalledMethod expect(String methodName, Class[] vargs);

        /**
         * Expect a method to be called an returning the specified return value. The default
         * timeout is 10 seconds.
         *
         * @param returnValue the value to return from the method call
         * @param methodName the name of the method to expect
         * @param vargs the optional parameter types of the method call
         * @return the CalledMethod information that will be filled after
         *         the method is called
         */
        public CalledMethod expect(Object returnValue, String methodName, Class[] vargs);

        /**
         * Expect a method to be called an throw an exception rather than return normal. The default
         * timeout is 10 seconds.
         *
         * @param methodName the name of the method to expect
         * @param throwable the exception to throw from the method
         * @param vargs the optional parameter types of the method call
         * @return the CalledMethod information that will be filled after
         *         the method is called
         */
        public CalledMethod expect(String methodName, Throwable throwable, Class[] vargs);
       
        /**
         * Expect a method to be called with the specified behavior to modify the
         * parameters and return value as needed. The default
         * timeout is 10 seconds.
         *
         * @param methodName the name of the method to expect
         * @param behavior the behavior to handle cloning managing of the return value
         * @param params the optional parameter types of the method call
         * @return the CalledMethod information that will be filled after
         *         the method is called
         */
        public CalledMethod expect(String methodName, Behavior behavior, Class[] params);

    /*******
    SAME METHODS AS ABOVE BUT WITH TIMEOUT PARAMETER
    *******/

        /**
         * Expect a method to be called with no return value.
         *
         * @param methodName the name of the method to expect
         * @param timeout The time to wait for method to be called before failing test
         * @param vargs the optional parmeter types of the method call
         * @return the CalledMethod information that will be filled after
         *         the method is called
         */
        public CalledMethod expect(String methodName, long timeout, Class[] vargs);

        /**
         * Expect a method to be called an returning the specified return value.
         *
         * @param returnValue the value to return from the method call
         * @param methodName the name of the method to expect
         * @param timeout The time to wait for method to be called before failing test
         * @param vargs the optional parameter types of the method call
         * @return the CalledMethod information that will be filled after
         *         the method is called
         */
        public CalledMethod expect(Object returnValue, String methodName, long timeout, Class[] vargs);

        /**
         * Expect a method to be called an throw an exception rather than return normal.
         *
         * @param methodName the name of the method to expect
         * @param throwable the exception to throw from the method
         * @param timeout The time to wait for method to be called before failing test
         * @param vargs the optional parameter types of the method call
         * @return the CalledMethod information that will be filled after
         *         the method is called
         */
        public CalledMethod expect(String methodName, Throwable throwable, long timeout, Class[] vargs);
       
        /**
         * Expect a method to be called with the specified behavior to modify the
         * parameters and return value as needed.
         *
         * @param methodName the name of the method to expect
         * @param behavior the behavior to handle cloning managing of the return value
         * @param timeout The time to wait for method to be called before failing test
         * @param params the optional parameter types of the method call
         * @return the CalledMethod information that will be filled after
         *         the method is called
         */
        public CalledMethod expect(String methodName, Behavior behavior, long timeout, Class[] params);
       
        /**
         * Verifies that the expected methods are called within the timeout.
         */
        public void verify();
       
        /**
         * Add a method to the ignore list.
         * @param methodName the name of the method to ignore
         * @param vargs the optional parameter types of the method call
         */
        public void addIgnoreMethod(String methodName, Class[] vargs);
       
        /**
         * Remove a method from the ignore list.
         * @param methodName the name of the method to ignore
         * @param vargs the optinal parameter types of the method call
         */
        public void removeIgnoreMethod(String methodName, Class[] vargs);
       
        /**
         * Sets the default return value for a method call and adds the method to
         * the ignore list.
         * @param returnValue the value to return for specific method calls
         * @param methodName the name of the method
         * @param vargs the optional parameter types of the method calls
         */
        public void setDefaultReturnValue(Object returnValue, String methodName, Class[] vargs);
       
        /**
         * Creates returns an instance of the mocked object.
         * @return an instance of the mocked object
         */
        public Object instance();
    }

    package biz.xsoftware.mock2;

    /**
    * A representation of a called method.  This bean holds the parameters,
    * method name, and the stack trace for a specific invocation of a method.
    *
    * @author Dann Ormond
    *
    */
    public interface CalledMethod {

        public String getMethodName();

        public Object[] getParameters();

        public String getStackTrace();
    }

    package biz.xsoftware.mock2;

    /**
    * A marker interface that signifies that the implementation is a behavior
    * and cloner class.  Methods for the behavior has the exact same signature as the
    * method.  The cloner method has the <methodName>Clone with the same signature
    * as the method to clone the parameters and returns the cloned parameters as
    * an object array.
    *
    * @author Dann Ormond
    *
    */
    public interface Behavior {

    }
    [/code]

     
    • Nobody

      Nobody - 2005-11-10

      shucks, the forum doesn't show code too well.  I am not sure I like the position of the timeout variable, but with varargs, it can't be placed at the end either.  any ideas?

       
    • ormy

      ormy - 2005-11-11

      Is it possible to get a zip file uploaded for download of the interfaces.  I don't wanto to copy and paste to make the files.

      Thanks!

       
    • Nobody

      Nobody - 2005-11-20

      that would be fine.  go ahead and do it :).  Actually, where would we post this zip? and I think more likely is you should just check this into the netmocklib project?  What do you think?

      hmmm...I am not getting auto email notification on these.  I better check my settings.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.