You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2013/05/13 22:23:38 UTC
svn commit: r1482081 -
/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java
Author: oheger
Date: Mon May 13 20:23:37 2013
New Revision: 1482081
URL: http://svn.apache.org/r1482081
Log:
Simplified handling of temporary files in test class.
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java?rev=1482081&r1=1482080&r2=1482081&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java Mon May 13 20:23:37 2013
@@ -35,8 +35,9 @@ import java.util.Set;
import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl;
import org.apache.commons.configuration.builder.FileBasedConfigurationBuilder;
-import org.junit.After;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
/**
* Test class for INIConfiguration.
@@ -102,18 +103,9 @@ public class TestINIConfiguration
private static final String INI_DATA_GLOBAL = INI_DATA_GLOBAL_ONLY
+ INI_DATA;
- /** A test ini file. */
- private static final File TEST_FILE = new File("target/test.ini");
-
- @After
- public void tearDown() throws Exception
- {
- if (TEST_FILE.exists())
- {
- assertTrue("Cannot remove test file: " + TEST_FILE, TEST_FILE
- .delete());
- }
- }
+ /** A helper object for creating temporary files. */
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
/**
* Creates a INIConfiguration object that is initialized from
@@ -157,11 +149,13 @@ public class TestINIConfiguration
* Writes a test ini file.
*
* @param content the content of the file
+ * @return the newly created file
* @throws IOException if an error occurs
*/
- private static void writeTestFile(String content) throws IOException
+ private File writeTestFile(String content) throws IOException
{
- PrintWriter out = new PrintWriter(new FileWriter(TEST_FILE));
+ File file = folder.newFile();
+ PrintWriter out = new PrintWriter(new FileWriter(file));
try
{
out.println(content);
@@ -170,6 +164,7 @@ public class TestINIConfiguration
{
out.close();
}
+ return file;
}
/**
@@ -261,12 +256,12 @@ public class TestINIConfiguration
public void testLoadFromBuilder() throws ConfigurationException,
IOException
{
- writeTestFile(INI_DATA);
+ File file = writeTestFile(INI_DATA);
FileBasedConfigurationBuilder<INIConfiguration> builder =
new FileBasedConfigurationBuilder<INIConfiguration>(
INIConfiguration.class);
builder.configure(new FileBasedBuilderParametersImpl()
- .setFile(TEST_FILE));
+ .setFile(file));
INIConfiguration config = builder.getConfiguration();
checkContent(config);
}