java.lang.IllegalStateException: the temporary folder has not yet been created
<p>I am creating a new <code>@Rule</code> for my use case which looks like  </p>

<pre><code>public class ActiveDirectoryConfigurationRule extends ExternalResource {

  @Rule
  public TemporaryFolder temporaryFolder = new TemporaryFolder();

  public File addActiveDirectoryConfigurationToFile(ActiveDirectoryConfiguration configuration) throws IOException {
    File file = temporaryFolder.newFile();
    objectMapper.writeValue(file, configuration);
    return file;
  }

  private ObjectMapper registerJdk8ModuleAndGetObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new Jdk8Module());
    return objectMapper;
  }
}
</code></pre>

<p>In my <code>Test</code> I use it as  </p>

<pre><code>public class ActiveDirectoryConfigurationStoreTest {

      @Rule
      public ActiveDirectoryConfigurationRule configurationRule = new ActiveDirectoryConfigurationRule();

          @Test
          public void getWhenConfigurationExists() throws Exception {
            ActiveDirectoryConfiguration activeDirectoryConfiguration = //....;
            File configurationToFile = configurationRule.addActiveDirectoryConfigurationToFile(activeDirectoryConfiguration);

            ActiveDirectoryConfigurationStore configurationStore = new ActiveDirectoryConfigurationStore(configurationToFile);
            Optional&lt;ActiveDirectoryConfiguration&gt; mayBeConfiguration = configurationStore.getConfiguration();
            assertTrue(mayBeConfiguration.isPresent());
          }
        }
</code></pre>

<p>When I run this test, I get error as  </p>

<pre><code>java.lang.IllegalStateException: the temporary folder has not yet been created

    at org.junit.rules.TemporaryFolder.getRoot(TemporaryFolder.java:145)
    at org.junit.rules.TemporaryFolder.newFile(TemporaryFolder.java:78)
    at com.conf.store.ActiveDirectoryConfigurationRule.addActiveDirectoryConfigurationToFile(ActiveDirectoryConfigurationRule.java:48)
    at com.conf.store.ActiveDirectoryConfigurationStoreTest.getWhenConfigurationExists(ActiveDirectoryConfigurationStoreTest.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
</code></pre>

<p>Seems like when creating your own <code>@Rule</code>, I am not able to depend on any existing <code>@Rule</code></p>

<p>Is that the issue? and how do I resolve it?</p>