Unitils EasyMock and JUnit @Rule from JUnit 4.10 to 4.11

349 views Asked by At

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
0

There are 0 answers