Mauro Talevi | 26 Aug 16:57

Re: 2.5.1 Released

Nat Pryce wrote:

> We've just released jMock 2.5.1, a bug-fix release that improves error messages.

Maven artifacts uploaded too.  Will be sync-ed to maven central repo 
shortly.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Vivek R | 26 Aug 07:56

Mocking Objects

Hi,

Pardon me for a not so great subject :). Anyways, my question follows:

Consider src file X.java

Y obj1;
Z obj2 = Y.f();
obj2.g();

Consider the mocking file XMock.java
I am creating 2 mock objects

mock1 = mock object of class Y
mock2 = mock object of class Z;

/* Now, for the code :) */
one(mock1).f();will(returnValue(mock2));
one(mock2).g();

Q: Is this ok ? It throws an exception saying "forgot to mention an expectation?" on the line "obj2.g()" (in X.java)

Thanks
Vivek

Vivek R | 26 Aug 07:56

Mocking Objects

Hi,

Pardon me for a not so great subject :). Anyways, my question follows:

Consider src file X.java

Y obj1;
Z obj2 = Y.f();
obj2.g();

Consider the mocking file XMock.java
I am creating 2 mock objects

mock1 = mock object of class Y
mock2 = mock object of class Z;

/* Now, for the code :) */
one(mock1).f();will(returnValue(mock2));
one(mock2).g();

Q: Is this ok ? It throws an exception saying "forgot to mention an expectation?" on the line "obj2.g()" (in X.java)

Thanks
Vivek

Nat Pryce | 24 Aug 12:20

2.5.1 Released

We've just released jMock 2.5.1, a bug-fix release that improves error messages.

The changelog is at:

http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10336&styleName=Html&version=14527

--Nat

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

杨威 | 20 Aug 09:25

a question on jMock use

Hi,

      Sorry for inconvenience. I have a question on jMock use. Would you PLS give me some comments?

      I have a class Foo and an interface Goo like below:

       public class Foo {

        private Goo goo;

        private int i;

       

    public Foo (Goo aGoo) {

        goo = aGoo;

      i = goo.getCount();

        }

       

        public int getI (){

           return i;

        }

       

        public void incre () {

           goo.incre();

           i = goo.getCount();

        }

   

}

 

public interface Goo {

       

        public void incre ();

       

        public int getCount ();

   

}

 

And I set up a test case like below:

public class oneTest extends TestCase {

       

    protected void setUp() throws Exception {

           super.setUp();

    }

   

        protected void tearDown() throws Exception {

        super.tearDown();

        }

   

    public void testSth () {

        Mockery mockery = new Mockery();

    final Goo mockGoo = mockery.mock(Goo.class, "MockGoo");

       

    mockery.checking(new Expectations() {

               {

                one(mockGoo).incre();

                   one(mockGoo).getCount();

                    will(returnValue(1));

               }

        });

       

        Foo aFoo = new Foo(mockGoo);

       

    aFoo.incre();

       

    mockery.assertIsSatisfied();

        }

   

}

 

But after I run the test case I get below error. And if I remove “i = goo.getCount();” from Foo’s constructor, it is OK. Does it means that we sho uld not use the mock objects (in my code is Goo)’ method in the constructor of the class (in my code is Foo) to be tested?

 

Thank you very much!

-         Wei Yang

 

Error:

unexpected invocation: MockGoo.getCount()expectations: expected once, already invoked 1 time: MockGoo.incre(); returns a default value expected once, already invoked 1 time: MockGoo.getCount(); returns <1>what happened before this: MockGoo.getCount() MockGoo.incre() at org.jmock.internal.InvocationDispatcher.dispatch(InvocationDispatcher.java:56) at

org.jmock.Mockery.dispatch(Mockery.java:218) at

org.jmock.Mockery.access$000(Mockery.java:43) at

org.jmock.Mockery$MockObject.invoke(Mockery.java:258) at

org.jmock.internal.InvocationDiverter.invoke(InvocationDiverter.java:27) at

org.jmock.internal.FakeObjectMethods.invoke(FakeObjectMethods.java:38) at org.jmock.lib.JavaReflectionImposteriser$1.invoke(JavaReflectionImposteriser.java:33) at

$Proxy45.getCount(Unknown Source) at myTest.Foo.incre(Foo.java:18) at

myTest.oneTest.testSth(oneTest.java:32) at

sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)


MSN上小游戏,工作休闲两不误! 马上就开始玩!
MSanchez | 4 Aug 13:50

How to obtain current state of state-machine?


Hi.

Firstly; I'm very new to jMock so I apologize for any obvious oversights.

I'm using States but I can find no way to verify the final state at the end
of the test?  The only workaround I have found is declaring an (irrelevant)
method call in the desired state and making that call at the end of the test
to force a failure if the state is incorrect.

Thoughts?
--

-- 
View this message in context: http://www.nabble.com/How-to-obtain-current-state-of-state-machine--tp18809870p18809870.html
Sent from the jMock - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Mauro Talevi | 21 Jul 21:01

JMock 2.5.0 maven artifacts uploaded

Hi,

I've uploaded maven artifacts for release 2.5.0

Just follow instructions from http://jmock.org/maven.html replacing 
2.4.0 -> 2.5.0.

Note that new module jmock-script has been added.

Any issues with it please let me know.

Cheers

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

new naming scheme generates ~almost always~ unique names from the caller stack trace

Hi,

As recently switching to JMock 2.5 from 1.x have found it strange that 
jmock complains about non-unique method names. While I understand that 
good mock names are important for identifying the mock, I think most of 
the time it would be enough if the caller test-method name would become 
automatically part of the mock name.

For example, you have this test method (note line numbers below):

10    // my test method
11    public void testMath() {
12      firstMath = context.mock(Math.class);
13      secondMath = context.mock(Math.class);
14      ...more...
15    }

Then using the following naming scheme you will automatically get the 
math(testMath:12) and math(testMath:13) generated names for firstMath 
and secondMath mocks.  Feel free to use this:
Cheers,
Zoltan

    /**
     * Mock object naming scheme generates unique names, by putting the 
caller's stack trace in the name.
     */
    public class UniqueStackTraceMethodNamingScheme implements 
MockObjectNamingScheme {

        private MockObjectNamingScheme delegate;

        /**
         * Default constructor, uses {@link CamelCaseNamingScheme} for 
generating the name.
         */
        public UniqueStackTraceMethodNamingScheme() {
            this(new CamelCaseNamingScheme());
        }

        /**
         * Constructor with a delegate naming scheme.
         * @param delegate The delegate
         */
        public UniqueStackTraceMethodNamingScheme(MockObjectNamingScheme 
delegate) {
            this.delegate = delegate;
        }

        /* (non-Javadoc)
         * @see 
org.jmock.lib.CamelCaseNamingScheme#defaultNameFor(java.lang.Class)
         */
        public String defaultNameFor(Class<?> typeToMock) {
            String name = delegate.defaultNameFor(typeToMock);
            StackTraceElement st = findCallerStackTraceElement();
            String nameFromStackTrace = st == null ? "" : 
                "(" + /*st.getClassName() + "." +*/ st.getMethodName() + 
":" + st.getLineNumber() +")";
            return name + nameFromStackTrace;
        }

        /**
         * Find the caller method, which is used for name generation.
         * @return
         */
        protected StackTraceElement findCallerStackTraceElement() {
            StackTraceElement[] stElements = (new 
Exception()).getStackTrace();
            StackTraceElement callerStackTraceElem = null;

            for (StackTraceElement stackTraceElement : stElements) {
                if (acceptStackTrace(stackTraceElement)) {
                    callerStackTraceElem = stackTraceElement;
                    break;
                }
            }
            return callerStackTraceElem;
        }

        /**
         * Check if this is the real caller method. Override this to do 
custom finding for method name
         * @param element
         * @return
         */
        protected boolean acceptStackTrace(StackTraceElement element) {
            // ignore all stack trace elements on this class
            String cname = this.getClass().getName();
            if (element.getClassName().equals(cname)) {
                return false;
            }
            // ignore all jmock classes
            if (element.getClassName().startsWith("org.jmock")) {
                return false;
            }
            return true;
        }
    }

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Owen Rogers | 17 Jul 22:43

problem downloading jmock dependencies using maven2

i'm encountering some problems downloading the jmock jars using the specified maven configuration (http://www.jmock.org/maven.html).
for some reason, the .pom and the .sha1 files get downloaded into my local repository, but the jar files don't. i'm using repo1.maven.org as the download location for the dependency. i can see the jar files on the site (http://repo1.maven.org/maven2/org/jmock/jmock-junit4/2.5.0-RC1/) but they don't get downloaded. i'm using maven 2.0.9.
is there some other repository that i should be using instead?
cheers,
owen.
--
Owen Rogers | http://exortech.com/blog
smallenergygroup | http://smallenergygroup.com |
Haroon Rafique | 16 Jul 20:37

mocking concrete classes with final toString method

Hi there,

I'm using jmock 2.5.0RC1. When trying to mock concrete classes with final 
toString methods, I'm getting:

java.lang.IllegalArgumentException: 
ClassNameHere has a final toString method

Looking through jira and the changelogs, this is a direct result of this 
bug:
 	http://jira.codehaus.org/browse/JMOCK-150
and was implemented in changeset:
 	http://fisheye.codehaus.org/changelog/jmock?cs=1152

Is there a middle ground somewhere? I'm working with 3rd party classes 
where I have no control over their class structure. JMOCK-150 seems like 
squashing a bug with a hammer.

The original bug reporter mentioned that:

 	* an un-expected exception during the assertIsSatisfied() check
           (got the exception when tring to describe the mocked class using
           the final toString() which uses other methods from the original
           class)

Could the code in Mockery.assertIsSatisfied() look for the fact that a 
ClassImposteriser is being used and to bypass the toString method in case 
it is final? pseudo-code follows:

new ExpectationError("not all expectations were satisfied",
 	!toStringMethodIsFinalAndUsingClassImposteriser(dispatcher) ?
 	dispatcher :
 	dispatcher.getClass().getName()
);

Cheers,
--
Haroon Rafique
<haroon.rafique@...>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Nat Pryce | 14 Jul 13:05

JMock 2.5.0 Released

JMock 2.5.0 has been released.

The full changelog is at:

http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10336&styleName=Html&version=13840

--Nat

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane