From d342495fbd1f889b5a59680b70964bbbff0860b8 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 10 Jan 2017 19:59:14 +0000 Subject: [PATCH] builder:{Checkstyle,Readme}WriterTest: use @Rule TemporaryFolder --- .../ruleset/builder/CheckstyleWriterTest.java | 10 ++++++++-- .../ruleset/builder/ReadmeWriterTest.java | 13 ++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java index 9b5afd9..8874b1e 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java @@ -5,6 +5,7 @@ import me.andrz.builder.map.MapBuilder; import org.junit.Before; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; import org.mockito.MockitoAnnotations; import java.io.IOException; @@ -48,6 +49,9 @@ public class CheckstyleWriterTest { @org.junit.Rule public ExpectedException exception = ExpectedException.none(); + @org.junit.Rule + public TemporaryFolder folder = new TemporaryFolder(); + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); @@ -61,10 +65,12 @@ public class CheckstyleWriterTest { .put(getOutputFile(RuleLevel.COMPLEXITY)) .build(); outputProperties.setRulesetFiles(outputFiles); - outputDirectory = Files.createTempDirectory("test"); + outputDirectory = folder.newFolder() + .toPath(); outputProperties.setDirectory(outputDirectory); templateProperties = new TemplateProperties(); - checkstyleTemplate = Files.createTempFile("checkstyle-template", ".xml"); + checkstyleTemplate = folder.newFile("checkstyle-template.xml") + .toPath(); Files.write( checkstyleTemplate, TEMPLATE.getBytes(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING); templateProperties.setCheckstyleXml(checkstyleTemplate); diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java index 4847f13..f64ab97 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java @@ -3,6 +3,7 @@ package net.kemitix.checkstyle.ruleset.builder; import lombok.val; import org.junit.Before; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -42,13 +43,19 @@ public class ReadmeWriterTest { private Path readme; + @org.junit.Rule + public TemporaryFolder folder = new TemporaryFolder(); + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - template = Files.createTempFile("README", ".md"); + template = folder.newFile("README-template.md") + .toPath(); Files.write(template, Arrays.asList("i:%s", "ce:%s", "se:%s", "cd:%s", "sd:%s")); - fragments = Files.createTempDirectory("fragments"); - readme = Files.createTempFile("README", ".md"); + fragments = folder.newFolder("fragments") + .toPath(); + readme = folder.newFile("README.md") + .toPath(); templateProperties = new TemplateProperties(); templateProperties.setReadmeTemplate(template); templateProperties.setReadmeFragments(fragments);