Michael Hackett | 1 Dec 2005 16:27

Re: Using JMock where TestCase has already been extended

On Mon, 2005-28-11 at 12:00 -0500, Chris.Kreussling@... wrote:
> The "side effect" you lose is the automatic verification check for 
> UNCALLED methods you get if you extend MockObjectTestCase. But I've found 
> in our testing it's poor practice to rely on that. It's better to 
> explicitly add the call to verify() at the end of the testXXX() method.

This reminds me: Has anyone begun thinking about the transition to
JUnit 4? My understanding is that TestCase is gone from the new framework
(still present in the old hierarchy, though). The assertXXX methods are
invoked statically, and your test case classes can be part of any class
hierarchy.

It looks like it would be fairly easy to do the same with jMock. I've
already begun writing my own class with static versions of the
"syntactic sugar" and assertThat methods. And if you get used to calling
verify() manually, the rest of the transition should be fairly seamless.
(And with annotations/aspects, even that might be automated.) Anything
I've missed?

Is there any interest in making this a branch or subproject of the
official tree? In a few weeks, I hope to start moving our current
project to JUnit 4, and would be interested in finishing up the jMock
changes I've started on.

-- Michael

Favicon

Unknow 'match not found' error, and non matching results

I have an unexpected 'no match found' and we dont understand this error.
The interface I am mocking is the following. The notifyTvStatus method is invoked by another thread than the one the thread wich sets the 'expects' at the mock object.

public interface TvUpdateListener {
   public void notifyTvStatus(final String ipAddress, final boolean isStandby, final short channel);    
}

I wrote the following testcase:

/**
 * Test the selection of multiple channels
 */
public void testChannelSelection() {
   
   // set up
   final Mock mockTvListener = mock(TvUpdateListener.class);

   mockTvListener.expects(atLeastOnce()).method("notifyTvStatus").with(eq("172.16.30.183"), eq(false), eq(2));
   mockTvListener.expects(atLeastOnce()).method("notifyTvStatus").with(eq("172.16.30.183"), eq(false), eq(1));

       // Select channel 1
        tvProxy.selectChannel(1);

}

I expect the selectChannelCommand to invoke a callback on a subscribed TvUpdateListener. The asynchronously callback is done by a different thread. When this callback arrives at the mock object we get an unexpected error:

org.jmock.core.DynamicMockError: mockTvUpdateListener: no match found
Invoked: com.philips.cebds.driver.TvUpdateListener.notifyTvStatus(<172.16.30.183>, <false>, <1>)
Allowed:
expected at least once: notifyTvStatus( eq(<172.16.30.183>), eq(<false>), eq(<2>) ), is void
expected at least once: notifyTvStatus( eq(<172.16.30.183>), eq(<false>), eq(<1>) ), is void

        at org.jmock.core.AbstractDynamicMock.mockInvocation(Unknown Source)
        at org.jmock.core.CoreMock.invoke(Unknown Source)
        at $Proxy0.notifyTvStatus(Unknown Source)
        at com.philips.cebds.driver.RespondsServer.notifyTvStatus(RespondsServer.java:395)
        at com.philips.cebds.driver.RespondsServer.parseHeader040101(RespondsServer.java:497)
        at com.philips.cebds.driver.RespondsServer$SocketSessionThread.run(RespondsServer.java:221)
        at java.lang.Thread.run(Unknown Source)



I don't understand why the mock object detects a mismatch.
Does anybody has a solution/explanation?

Sent from the jMock - User forum at Nabble.com:
Unknow 'match not found' error, and non matching results
Jim MacDonald | 7 Dec 2005 20:17

Using cglib and JMock - cannot get access to the Object creation methods for concrete classes with non null contructors

Hi,

 

Hope someone is listening.

 

I am using the cglib library for creating concrete classes but not if they have non null constructors. I can derive my unit test form the cglib.MockObjectTestCase and that works fine but the methods mock.xxx that take constructor args cannot be seen.

 

Any idea?

 

Jim

Chris.Kreussling | 7 Dec 2005 21:10
Favicon

Re: Using cglib and JMock - cannot get access to the Object creation methods for concrete classes with non null contructors

Which version of jMock?
-----
Chris Kreussling, Senior Technical Specialist
Federal Reserve Bank of New York
Tel: (212)720-1601, Alt: (646)720-1601
-----
"The Helpful Model: No matter how it looks, everyone is trying to be 
helpful.
The Principle of Addition: The best way to reduce ineffective behavior is 
by adding more effective behavior."
- Gerald M. Weinberg, "Quality Software Management, Volume 1: Systems 
Thinking"
-----
"When he was younger, Gensha went on a pilgrimage to many monasteries. 
While walking he stubbed his toe on a sharp rock. He cried out, "Where 
does this pain come from?" Not "this dumb rock" or "I am so stupid," but 
instead, "Where does this pain come from?" At that instant, he attained 
enlightenment."
- Zen Story
-----
All statements are my own and do not represent the views or positions of 
the Federal Reserve.

"Jim MacDonald" <JMacdonald@...> 
12/07/2005 02:17 PM
Please respond to
user@...

To
<user@...>
cc

Subject
[jmock-user] Using cglib and JMock - cannot get access to the Object 
creation methods for concrete classes with non null contructors

Hi,

Hope someone is listening.

I am using the cglib library for creating concrete classes but not if they 
have non null constructors. I can derive my unit test form the 
cglib.MockObjectTestCase and that works fine but the methods mock.xxx that 
take constructor args cannot be seen.

Any idea?

Jim

Jim MacDonald | 7 Dec 2005 23:10

RE: [BULK] - Re: [jmock-user] Using cglib and JMock - cannot get access to the Object creation methods for concrete classes with non null contructors

Hi Chris, thanks for the reply.

I'm using JMock 1.0.1 and jmcok-cglib-1.0.1 along with
cglib-nodep-2.1_3.

I decompiled the jmcok-cglib-1.0.1.jar file and it does not appear to
contain overloaded 'mock' methods that I expected.

Thanks
Jim

-----Original Message-----
From: Chris.Kreussling@...
[mailto:Chris.Kreussling@...] 
Sent: Wednesday, December 07, 2005 12:11 PM
To: user@...
Cc: user@...
Subject: [BULK] - Re: [jmock-user] Using cglib and JMock - cannot get
access to the Object creation methods for concrete classes with non null
contructors

Which version of jMock?
-----
Chris Kreussling, Senior Technical Specialist
Federal Reserve Bank of New York
Tel: (212)720-1601, Alt: (646)720-1601
-----
"The Helpful Model: No matter how it looks, everyone is trying to be 
helpful.
The Principle of Addition: The best way to reduce ineffective behavior
is 
by adding more effective behavior."
- Gerald M. Weinberg, "Quality Software Management, Volume 1: Systems 
Thinking"
-----
"When he was younger, Gensha went on a pilgrimage to many monasteries. 
While walking he stubbed his toe on a sharp rock. He cried out, "Where 
does this pain come from?" Not "this dumb rock" or "I am so stupid," but

instead, "Where does this pain come from?" At that instant, he attained 
enlightenment."
- Zen Story
-----
All statements are my own and do not represent the views or positions of

the Federal Reserve.

"Jim MacDonald" <JMacdonald@...> 
12/07/2005 02:17 PM
Please respond to
user@...

To
<user@...>
cc

Subject
[jmock-user] Using cglib and JMock - cannot get access to the Object 
creation methods for concrete classes with non null contructors

Hi,

Hope someone is listening.

I am using the cglib library for creating concrete classes but not if
they 
have non null constructors. I can derive my unit test form the 
cglib.MockObjectTestCase and that works fine but the methods mock.xxx
that 
take constructor args cannot be seen.

Any idea?

Jim

Chris.Kreussling | 7 Dec 2005 23:17
Favicon

Re: RE: [BULK] - Re: [jmock-user] Using cglib and JMock - cannot get access to the Object creation methods for concrete classes with non null contructors

Try the jmock SNAPSHOT release from June of this year.

I'm not familiar with the cglib version you're using. I've been using 
cglib 2.0 with jMock for mocking concrete classes.

-----
Chris Kreussling, Senior Technical Specialist
Federal Reserve Bank of New York
Tel: (212)720-1601, Alt: (646)720-1601
-----
"The Helpful Model: No matter how it looks, everyone is trying to be 
helpful.
The Principle of Addition: The best way to reduce ineffective behavior is 
by adding more effective behavior."
- Gerald M. Weinberg, "Quality Software Management, Volume 1: Systems 
Thinking"
-----
"When he was younger, Gensha went on a pilgrimage to many monasteries. 
While walking he stubbed his toe on a sharp rock. He cried out, "Where 
does this pain come from?" Not "this dumb rock" or "I am so stupid," but 
instead, "Where does this pain come from?" At that instant, he attained 
enlightenment."
- Zen Story
-----
All statements are my own and do not represent the views or positions of 
the Federal Reserve.

"Jim MacDonald" <JMacdonald@...> wrote on 12/07/2005 05:10:28 PM:

> Hi Chris, thanks for the reply.
> 
> I'm using JMock 1.0.1 and jmcok-cglib-1.0.1 along with
> cglib-nodep-2.1_3.
> 
> I decompiled the jmcok-cglib-1.0.1.jar file and it does not appear to
> contain overloaded 'mock' methods that I expected.
> 
> Thanks
> Jim
> 
> -----Original Message-----
> From: Chris.Kreussling@...
[mailto:Chris.Kreussling@...] 
> Sent: Wednesday, December 07, 2005 12:11 PM
> To: user@...
> Cc: user@...
> Subject: [BULK] - Re: [jmock-user] Using cglib and JMock - cannot get
> access to the Object creation methods for concrete classes with non null
> contructors
> 
> Which version of jMock?
> -----
> Chris Kreussling, Senior Technical Specialist
> Federal Reserve Bank of New York
> Tel: (212)720-1601, Alt: (646)720-1601
> -----
> "The Helpful Model: No matter how it looks, everyone is trying to be 
> helpful.
> The Principle of Addition: The best way to reduce ineffective behavior
> is 
> by adding more effective behavior."
> - Gerald M. Weinberg, "Quality Software Management, Volume 1: Systems 
> Thinking"
> -----
> "When he was younger, Gensha went on a pilgrimage to many monasteries. 
> While walking he stubbed his toe on a sharp rock. He cried out, "Where 
> does this pain come from?" Not "this dumb rock" or "I am so stupid," but
> 
> instead, "Where does this pain come from?" At that instant, he attained 
> enlightenment."
> - Zen Story
> -----
> All statements are my own and do not represent the views or positions of
> 
> the Federal Reserve.
> 
> 
> 
> 
> "Jim MacDonald" <JMacdonald@...> 
> 12/07/2005 02:17 PM
> Please respond to
> user@...
> 
> 
> To
> <user@...>
> cc
> 
> Subject
> [jmock-user] Using cglib and JMock - cannot get access to the Object 
> creation methods for concrete classes with non null contructors
> 
> 
> 
> 
> 
> 
> Hi,
> 
> Hope someone is listening.
> 
> I am using the cglib library for creating concrete classes but not if
> they 
> have non null constructors. I can derive my unit test form the 
> cglib.MockObjectTestCase and that works fine but the methods mock.xxx
> that 
> take constructor args cannot be seen.
> 
> Any idea?
> 
> Jim
> 

Jim MacDonald | 7 Dec 2005 23:51

RE: [BULK] - Re: [jmock-user] RE: [BULK] - Re: [jmock-user] Using cglib and JMock - cannot get access to the Object creation methods for concrete classes with non null contructors

Chris,

Thanks. I compared the snapshot with the 'stable release' and they are
different. The 1.0.1 release does not have the correct overloaded
methods.

Thanks
Jim

-----Original Message-----
From: Chris.Kreussling@...
[mailto:Chris.Kreussling@...] 
Sent: Wednesday, December 07, 2005 2:18 PM
To: Jim MacDonald
Cc: user@...
Subject: [BULK] - Re: [jmock-user] RE: [BULK] - Re: [jmock-user] Using
cglib and JMock - cannot get access to the Object creation methods for
concrete classes with non null contructors

Try the jmock SNAPSHOT release from June of this year.

I'm not familiar with the cglib version you're using. I've been using 
cglib 2.0 with jMock for mocking concrete classes.

-----
Chris Kreussling, Senior Technical Specialist
Federal Reserve Bank of New York
Tel: (212)720-1601, Alt: (646)720-1601
-----
"The Helpful Model: No matter how it looks, everyone is trying to be 
helpful.
The Principle of Addition: The best way to reduce ineffective behavior
is 
by adding more effective behavior."
- Gerald M. Weinberg, "Quality Software Management, Volume 1: Systems 
Thinking"
-----
"When he was younger, Gensha went on a pilgrimage to many monasteries. 
While walking he stubbed his toe on a sharp rock. He cried out, "Where 
does this pain come from?" Not "this dumb rock" or "I am so stupid," but

instead, "Where does this pain come from?" At that instant, he attained 
enlightenment."
- Zen Story
-----
All statements are my own and do not represent the views or positions of

the Federal Reserve.

"Jim MacDonald" <JMacdonald@...> wrote on 12/07/2005 05:10:28 PM:

> Hi Chris, thanks for the reply.
> 
> I'm using JMock 1.0.1 and jmcok-cglib-1.0.1 along with
> cglib-nodep-2.1_3.
> 
> I decompiled the jmcok-cglib-1.0.1.jar file and it does not appear to
> contain overloaded 'mock' methods that I expected.
> 
> Thanks
> Jim
> 
> -----Original Message-----
> From: Chris.Kreussling@... [mailto:Chris.Kreussling@...]

> Sent: Wednesday, December 07, 2005 12:11 PM
> To: user@...
> Cc: user@...
> Subject: [BULK] - Re: [jmock-user] Using cglib and JMock - cannot get
> access to the Object creation methods for concrete classes with non
null
> contructors
> 
> Which version of jMock?
> -----
> Chris Kreussling, Senior Technical Specialist
> Federal Reserve Bank of New York
> Tel: (212)720-1601, Alt: (646)720-1601
> -----
> "The Helpful Model: No matter how it looks, everyone is trying to be 
> helpful.
> The Principle of Addition: The best way to reduce ineffective behavior
> is 
> by adding more effective behavior."
> - Gerald M. Weinberg, "Quality Software Management, Volume 1: Systems 
> Thinking"
> -----
> "When he was younger, Gensha went on a pilgrimage to many monasteries.

> While walking he stubbed his toe on a sharp rock. He cried out, "Where

> does this pain come from?" Not "this dumb rock" or "I am so stupid,"
but
> 
> instead, "Where does this pain come from?" At that instant, he
attained 
> enlightenment."
> - Zen Story
> -----
> All statements are my own and do not represent the views or positions
of
> 
> the Federal Reserve.
> 
> 
> 
> 
> "Jim MacDonald" <JMacdonald@...> 
> 12/07/2005 02:17 PM
> Please respond to
> user@...
> 
> 
> To
> <user@...>
> cc
> 
> Subject
> [jmock-user] Using cglib and JMock - cannot get access to the Object 
> creation methods for concrete classes with non null contructors
> 
> 
> 
> 
> 
> 
> Hi,
> 
> Hope someone is listening.
> 
> I am using the cglib library for creating concrete classes but not if
> they 
> have non null constructors. I can derive my unit test form the 
> cglib.MockObjectTestCase and that works fine but the methods mock.xxx
> that 
> take constructor args cannot be seen.
> 
> Any idea?
> 
> Jim
> 

Geoffrey Wiseman | 7 Dec 2005 22:48

RE: Unknow 'match not found' error, and non matching results

Hard to say from this alone; I'd say that JUnit and JMock are not always clear about type issues -- so sometimes you get something like when a function expects a string like:
  new String( "http://www.jmock.org);
And gets a URL, like:
  new URL( "http://www.jmock.org);
 
When this happens, sometimes you see errors in assertEquals() or verify() that imply that there's no match when it looks like there is one.  Now, in this case, I'm not sure that that's relevant.
 
Easiest way to find an answer would be to debug, I think.  You could even set an exception breakpoint to catch the mock failure.
 
    - Geoffrey

From: Stefan85 (sent by Nabble.com) [mailto:lists-k7Aasz8DSOfQT0dZR+AlfA@public.gmane.org]
Sent: Wednesday, December 07, 2005 5:03 AM
To: user-sXN/XchZ9OexIXFVlbCvtR2eb7JE58TQ@public.gmane.org
Subject: [jmock-user] Unknow 'match not found' error, and non matching results

I have an unexpected 'no match found' and we dont understand this error.
The interface I am mocking is the following. The notifyTvStatus method is invoked by another thread than the one the thread wich sets the 'expects' at the mock object.

public interface TvUpdateListener {
   public void notifyTvStatus(final String ipAddress, final boolean isStandby, final short channel);    
}

I wrote the following testcase:

/**
 * Test the selection of multiple channels
 */
public void testChannelSelection() {
   
   // set up
   final Mock mockTvListener = mock(TvUpdateListener.class);

   mockTvListener.expects(atLeastOnce()).method("notifyTvStatus").with(eq("172.16.30.183"), eq(false), eq(2));
   mockTvListener.expects(atLeastOnce()).method("notifyTvStatus").with(eq("172.16.30.183"), eq(false), eq(1));

       // Select channel 1
        tvProxy.selectChannel(1);

}

I expect the selectChannelCommand to invoke a callback on a subscribed TvUpdateListener. The asynchronously callback is done by a different thread. When this callback arrives at the mock object we get an unexpected error:

org.jmock.core.DynamicMockError: mockTvUpdateListener: no match found
Invoked: com.philips.cebds.driver.TvUpdateListener.notifyTvStatus(<172.16.30.183>, <false>, <1>)
Allowed:
expected at least once: notifyTvStatus( eq(<172.16.30.183>), eq(<false>), eq(<2>) ), is void
expected at least once: notifyTvStatus( eq(<172.16.30.183>), eq(<false>), eq(<1>) ), is void

        at org.jmock.core.AbstractDynamicMock.mockInvocation(Unknown Source)
        at org.jmock.core.CoreMock.invoke(Unknown Source)
        at $Proxy0.notifyTvStatus(Unknown Source)
        at com.philips.cebds.driver.RespondsServer.notifyTvStatus(RespondsServer.java:395)
        at com.philips.cebds.driver.RespondsServer.parseHeader040101(RespondsServer.java:497)
        at com.philips.cebds.driver.RespondsServer$SocketSessionThread.run(RespondsServer.java:221)
        at java.lang.Thread.run(Unknown Source)



I don't understand why the mock object detects a mismatch.
Does anybody has a solution/explanation?
Sent from the jMock - User forum at Nabble.com:
Unknow 'match not found' error, and non matching results
Nick Sieger | 8 Dec 2005 16:25
Picon
Gravatar

Re: Unknow 'match not found' error, and non matching results


On 12/7/05, Stefan85 (sent by Nabble.com) <lists-k7Aasz8DSOfQT0dZR+AlfA@public.gmane.org> wrote:
I have an unexpected 'no match found' and we dont understand this error.
The interface I am mocking is the following. The notifyTvStatus method is invoked by another thread than the one the thread wich sets the 'expects' at the mock object.
[...]
I don't understand why the mock object detects a mismatch.
Does anybody has a solution/explanation?

I don't see anything immediately wrong with your code.  I've had this type of problem in the past as well.  Usually for me I'm bitten by the fact that the objects that are being compared by the "eq" are a different type but coincidentally have the same stringified form, so the error message doesn't show you how they differ.  Could this be the problem?

Cheers,
/Nick
Mark Mendel | 8 Dec 2005 18:18

jDummy on sourceforge

I found a home for the project:
    http://jdummy.sourceforge.net/

jDummy is an extension to jMock, a library for testing Java code with
mock objects. jDummy objects offer several advanatages over vanilla
jMock objects--without sacrifcing any of the benefits of the jMock
library.


Gmane