Julien D wrote:
> 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();
> }
> }
>
Does adding an "@RunWith(JMock.class)" annotation to your test suite help?
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email