Skip to content

Commit

Permalink
CARROT-1113: Temporary file left on disk after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dweiss committed Sep 25, 2015
1 parent 312965f commit ca4fc95
Showing 1 changed file with 3 additions and 32 deletions.
Expand Up @@ -109,7 +109,7 @@ public void testLexicalDataFromTheSameResourceDirIsShared() throws IOException
@Test
public void testLexicalDataIsReloadedOnDemand() throws IOException
{
final File tempDir1 = createTempDir();
final File tempDir1 = newTempDir();
FileUtils.writeStringToFile(new File(tempDir1, "stopwords.en"), "uniquea");

final String resourceLookupKey = AttributeUtils.getKey(
Expand Down Expand Up @@ -182,10 +182,10 @@ ImmutableMap.<String, Object> of(reloadResourcesKey, true), TestComponent.class)
@Test
public void testSeparateLexicalDataForDifferentResourceLookup() throws IOException
{
final File tempDir1 = createTempDir();
final File tempDir1 = newTempDir();
FileUtils.writeStringToFile(new File(tempDir1, "stopwords.en"), "uniquea");

final File tempDir2 = createTempDir();
final File tempDir2 = newTempDir();
FileUtils.writeStringToFile(new File(tempDir2, "stopwords.en"), "uniqueb");

final IResourceLocator classpathLocator = Location.CONTEXT_CLASS_LOADER.locator;
Expand Down Expand Up @@ -234,33 +234,4 @@ public void testSeparateLexicalDataForDifferentResourceLookup() throws IOExcepti
assertFalse(data.isCommonWord(new MutableCharArray("uniqueb")));
}
}

/**
* Creates a temporary folder and deletes it on VM exit.
*/
private File createTempDir()
{
try
{
File tempFile = File.createTempFile("tempdir", null);
if (tempFile.exists() && !tempFile.delete())
{
throw new RuntimeException("Could not delete temp. folder: "
+ tempFile.getAbsolutePath());
}
if (!tempFile.mkdir())
{
throw new RuntimeException("Could not create temp. folder: "
+ tempFile.getAbsolutePath());
}

tempFile.deleteOnExit();

return tempFile;
}
catch (IOException e)
{
throw new RuntimeException("Could not create temp directory.", e);
}
}
}

0 comments on commit ca4fc95

Please sign in to comment.