]> source.dussan.org Git - sonarqube.git/commitdiff
findbugs plugin: improve a unit test
authorsimonbrandhof <simon.brandhof@gmail.com>
Thu, 23 Sep 2010 08:24:10 +0000 (08:24 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Thu, 23 Sep 2010 08:24:10 +0000 (08:24 +0000)
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsMavenPluginHandlerTest.java

index 30bbd30d1993168061e3cba1a47c953aa6f2e901..63ee8840b0499ff5a1c8df576b6ca76cd15f83bf 100644 (file)
@@ -26,12 +26,15 @@ import org.hamcrest.core.Is;
 import static org.hamcrest.text.StringEndsWith.endsWith;\r
 import static org.junit.Assert.assertThat;\r
 import org.junit.Before;\r
+import org.junit.Rule;\r
 import org.junit.Test;\r
 import static org.mockito.Matchers.anyObject;\r
 import static org.mockito.Matchers.anyString;\r
 import static org.mockito.Matchers.argThat;\r
 import static org.mockito.Matchers.eq;\r
 import static org.mockito.Mockito.*;\r
+\r
+import org.junit.rules.TemporaryFolder;\r
 import org.sonar.api.CoreProperties;\r
 import org.sonar.api.batch.maven.MavenPlugin;\r
 import org.sonar.api.profiles.RulesProfile;\r
@@ -47,13 +50,16 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;\r
 \r
 public class FindbugsMavenPluginHandlerTest {\r
-  private static final String TARGET_TMP_TESTS = "target/tmp-tests";\r
 \r
+  @Rule\r
+  public TemporaryFolder tempFolder = new TemporaryFolder();\r
+  \r
   private Project project;\r
   private ProjectFileSystem fs;\r
   private File fakeSonarConfig;\r
   private MavenPlugin plugin;\r
   private FindbugsMavenPluginHandler handler;\r
+  private File findbugsTempDir;\r
 \r
   @Before\r
   public void setup() {\r
@@ -62,6 +68,7 @@ public class FindbugsMavenPluginHandlerTest {
     fakeSonarConfig = mock(File.class);\r
     plugin = mock(MavenPlugin.class);\r
     handler = createMavenPluginHandler();\r
+    findbugsTempDir = tempFolder.newFolder("findbugs");\r
   }\r
 \r
   @Test\r
@@ -166,7 +173,7 @@ public class FindbugsMavenPluginHandlerTest {
   }\r
 \r
   private void assertFindbugsIncludeFileIsSaved() {\r
-    File findbugsIncludeFile = new File(TARGET_TMP_TESTS + "/target/sonar/findbugs-include.xml");\r
+    File findbugsIncludeFile = new File(findbugsTempDir + "/target/sonar/findbugs-include.xml");\r
     assertThat(findbugsIncludeFile.exists(), is(true));\r
   }\r
 \r
@@ -176,7 +183,7 @@ public class FindbugsMavenPluginHandlerTest {
 \r
   private void mockProject(String effort) throws URISyntaxException, IOException {\r
     when(project.getPom()).thenReturn(new MavenProject());\r
-    when(project.getFileSystem()).thenReturn(new SimpleProjectFileSystem(new File(TARGET_TMP_TESTS)));\r
+    when(project.getFileSystem()).thenReturn(new SimpleProjectFileSystem(findbugsTempDir));\r
 \r
     Configuration conf = mock(Configuration.class);\r
     when(project.getConfiguration()).thenReturn(conf);\r