0

I have the Problem that when I use the @RuleAnnotation from JUnit for my TemporaryFolder and want to use Mocks from unitils.easymock at the same time I get an IlleagalStateException in JUnit 4.11, whereas in JUnit 4.10 it still works.

So the following test runs under JUnit 4.10 and throws the IllegalStateException in 4.11:

import java.io.File;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.unitils.UnitilsJUnit4;

public class MyTest extends UnitilsJUnit4 {

    @Rule
    public TemporaryFolder temporaryFolder = new TemporaryFolder();

    @Test
    public void testSomething() throws IOException {
        File newFile = temporaryFolder.newFile();
    }

}

Even if I use the Annotation for the Mocking capability instead of extends UnitilsJUnit4 it doesn't work in JUnit 4.11:

@RunWith(UnitilsJUnit4TestClassRunner.class)
public class MyTest {
 ...
}

The error message when testing this code is:

java.lang.IllegalStateException: the temporary folder has not yet been created

Something new I just additionally found out: In JUnit 4.10 I can also enforce the same error when passing a String in the newFile() call:

        File newFile = temporaryFolder.newFile("");

My question:

What is the proper way to make TemporaryFolders or @Rules in general work together with unitils.easymock.annotation.Mocks in JUnit 4.11?

Or is Mocking with the easymock @Mock annotation and @Rules at the same time simply not possible?

Versions:

easymock 3.4
unitils 3.4.3
DEX
  • 95
  • 1
  • 7
  • I would suspect a problem in delegating between rules. Can you provide a fully failing unit test? – Henri Nov 17 '16 at 15:58
  • @Henri Thanks for your reply! I just edited the question (see edit comment for details). Hopefully that makes the error reproducable. – DEX Nov 18 '16 at 15:56

0 Answers0