0

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.

  • This similiar question may provide a clue as to the problem, but I'm not sure what to do with it: https://stackoverflow.com/questions/21916100/junit-jmock-junitrulemockery-what-am-i-missing#22090405 – Stephen M -on strike- May 11 '18 at 18:03

1 Answers1

0

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>

Till Brychcy
  • 2,876
  • 1
  • 18
  • 28
  • We aren't using Maven. Added a screenshot from Eclipse showing the Library dependencies in the project properties. – Stephen M -on strike- May 04 '18 at 19:27
  • Just to be sure, I've retried with older asm and cglib versions and jdk 1.8.0 _162 as in your screen shot, and still cannot reproduce your problem. Maybe you could try yourself with my pom.xml in a fresh workspace. – Till Brychcy May 04 '18 at 20:14
  • I built a Maven project and used your pom.xml dependencies and it does work there. Now, if I just knew how to make it work correctly under a regular Java project as we aren't converting everything into Maven projects. More likely, I'll abandon Eclipse in favor of Netbeans (where it works correctly). – Stephen M -on strike- May 11 '18 at 16:11