KentBeck/junit — Issue #342: TemporaryFolder.newFile(String) throws IllegalStateException in junit-4.10
Author: vyazelenko
Created: 2011-10-15 11:00:51+00:00
State: open

Before Junit 4.10 I was using TemporaryFolder API to create files and directories directly in the test without usage of @Rule annotation. Since new release the code doesn't work anymore as IllegalStateException is thrown.

The cause of the error is the fact that 2 (newFile(String) and newFolder(String...)) out of 4 methods in TemporaryFolder class call getRoot() method which checks if folder variable is not null and if it is it throws IllegalStateException.

I can imagine that by design TemporaryFolder should not be used directly but only via @Rule. However then API must be symmetric in usage of getRoot(), so either all four methods should call it or none should.