"not all expectations were satisfied" missing under Eclipse

641 views Asked by At

We use two different IDEs, Netbeans 8.2 and Eclipse 4.7.2. We are running JMock 2.8.3 with JUnit 4.11 and have a test that fails under Netbeans and Jenkins (using the Netbean's Ant scripts), but passes under Eclipse.

The error is "not all expectations were satisfied".

However, if I add an assertIsSatisfied() call to the end of the test, it will fail with the correct error message under Eclipse.

I can reproduce this with a trivial example:

public class FailureExample {

    private static class Example {

        public void doSomething() { }

        public void doSomethingElse() { }
    }

    // Mocks
    @Rule public JUnitRuleMockery context = new JUnitRuleMockery(){{
        setThreadingPolicy(new Synchroniser());
        setImposteriser(ClassImposteriser.INSTANCE);
    }};

    public Example instance;

    @Before
    public void setUp() throws Exception {
        // Mocks
        instance = context.mock(Example.class);
    }


    @Test
    public void testExample() {
        context.checking(new Expectations() {{
            oneOf(instance).doSomething();
            oneOf(instance).doSomethingElse();
        }});

        instance.doSomething();
    }
}

Is there something else I need to do in Eclipse to make JMock behave as expected?

Update Adding screenshot of our project's libraries: enter image description here

UPDATE I tried create a new Java project as well as a new Maven project (as described below by Till Brychcy) as those worked. I tried removing all the jar files listed for my project and then readding them, but it failed.

I'm very close to abandoning Eclipse in favor of Netbeans, simply because I have real work to do, not just fighting with Eclipse.

1

There are 1 answers

3
Till Brychcy On

I cannot reproduce your problem. With both Eclipse 4.7.2 and Eclipse built from the current master I get:

java.lang.AssertionError: not all expectations were satisfied
expectations:
  expected once, already invoked 1 time: example.doSomething()
  ! expected once, never invoked: example.doSomethingElse()
what happened before this:
  example.doSomething()

I used the following pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>test</groupId>
<artifactId>jmockbug</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>jmockbug</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>
    <dependency>
        <groupId>org.jmock</groupId>
        <artifactId>jmock</artifactId>
        <version>2.8.3</version>
    </dependency>
    <dependency>
        <groupId>org.jmock</groupId>
        <artifactId>jmock-junit4</artifactId>
        <version>2.8.3</version>
    </dependency>
    <dependency>
        <groupId>org.jmock</groupId>
        <artifactId>jmock-legacy</artifactId>
        <version>2.8.3</version>
    </dependency>
</dependencies>