« Return to Thread: exactly(n) function in JMock
Nat Pryce wrote:You have neither annotated the class with @RunWith(JMock.class) nor
explicitly called context.assertIsSatisfied() in any of your tests.
--Nat
2009/6/1 Julien D <myrddin22@hotmail.com>:
>
> Here's my test :
>
> import org.jmock.Expectations;
> import org.jmock.Mockery;
> import org.jmock.integration.junit4.JUnit4Mockery;
> import org.junit.Before;
> import org.junit.Test;
>
> public class ExactlyTest {
>
> private interface IDao {
> void someMetod();
> }
>
> private class SomeService {
>
> private IDao dao;
>
> private void someServiceMethod() {
> //First call
> dao.someMetod();
> //Second call
> dao.someMetod();
> }
>
> public void setDao(IDao dao) {
> this.dao = dao;
> }
> }
>
> //Mock context
> private Mockery context;
>
> private SomeService underTest;
>
> private IDao iDao;
>
> @Before
> public void before() throws Exception {
> context = new JUnit4Mockery();
> underTest = new SomeService();
> iDao = context.mock(IDao.class);
>
> underTest.setDao(iDao);
> }
>
> //Failing as expected
> @Test
> public void testExactlyOne() {
> context.checking(new Expectations() {{
> exactly(1).of (iDao).someMetod();
> }});
>
> underTest.someServiceMethod();
> }
>
> //Passing as expected
> @Test
> public void testExactlyTwo() {
> context.checking(new Expectations() {{
> exactly(2).of (iDao).someMetod();
> }});
>
> underTest.someServiceMethod();
> }
>
> //Passing as not expected
> @Test
> public void testExactlyAHundredMillionSuns() {
> context.checking(new Expectations() {{
> exactly(100).of (iDao).someMetod();
> }});
>
> underTest.someServiceMethod();
> }
> }
>
>
>
> Nat Pryce wrote:
>>
>> Can you create a small test that reproduces the problem? E.g. one
>> that fails but should not.
>>
>> --Nat
>>
>> 2009/5/29 Julien D <myrddin22@hotmail.com>:
>>>
>>> This problem seems pretty old. Does anyone know somthing about that ?
>>>
>>> For information I use jmock 2.5.1 and jmock-junit4 2.5.1.
>>>
>>>
>>> Julien D wrote:
>>>>
>>>> I'm facing the same problem.
>>>>
>>>> It seems to be a bug in JMock. See the JIRA
>>>> http://jira.codehaus.org/browse/JMOCK-129.
>>>>
>>>>
>>>> ravisankarvivek wrote:
>>>>>
>>>>> Hi,
>>>>> I am facing a slightly weird problem. I set an expectation as
>>>>>
>>>>> *exactly(n).of(<mock-obj>).f()*
>>>>>
>>>>> *Bug*
>>>>> Suppose the function f() is called 5 times; For any n < 5, the
>>>>> expectation
>>>>> fails. However, if I provide the value of n > 5, it passes for all!!
>>>>> Eg: *exactly(100).of(<mock-obj>).f()*
>>>>> The above expectation passes, even though the function f() is called
>>>>> only
>>>>> 5
>>>>> times!
>>>>>
>>>>> Any thoughts ?
>>>>>
>>>>> PS: The expectation is under a context and the syntax is perfectly
>>>>> fine.
>>>>> In
>>>>> short, the java file compiles fine!
>>>>>
>>>>> -Vivek
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/exactly%28n%29-function-in-JMock-tp20322373p23780192.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
>>>
>>>
>>>
>>
>>
>>
>> --
>> http://www.natpryce.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/exactly%28n%29-function-in-JMock-tp20322373p23814629.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
>
>
>
--
http://www.natpryce.com
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
« Return to Thread: exactly(n) function in JMock
| Free embeddable forum powered by Nabble | Forum Help |