diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-22 21:02:17 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-22 21:02:17 +0000 |
commit | 89c8dcc3b8db2fb2b044b093113a81aced0dabbd (patch) | |
tree | 46e690cd241aecabd4ec55352eb0a07162817ef7 /sonar-plugin-api/src/test | |
parent | 4da6caa4a5d513296cdc0f2bdd4e85d6c8301b78 (diff) | |
download | sonarqube-89c8dcc3b8db2fb2b044b093113a81aced0dabbd.tar.gz sonarqube-89c8dcc3b8db2fb2b044b093113a81aced0dabbd.zip |
sonar-plugin-api: use parallel junit tests
Diffstat (limited to 'sonar-plugin-api/src/test')
3 files changed, 33 insertions, 66 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java index 3ddbfb8d876..c7a5870e602 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java @@ -21,13 +21,12 @@ package org.sonar.api.utils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; import java.io.OutputStream; import java.net.URLClassLoader; import java.util.List; @@ -42,24 +41,10 @@ import static org.junit.matchers.JUnitMatchers.hasItems; public class ManifestUtilsTest { - private File tempDir; + @Rule + public TemporaryFolder tempDir = new TemporaryFolder(); - @Before - public void before() throws IOException { - tempDir = new File("target/test-tmp/ManifestUtilsTest/"); - FileUtils.forceMkdir(tempDir); - } - - @After - public void tryToCleanDirectory() { - try { - FileUtils.cleanDirectory(tempDir); - } catch (Exception e) { - // fails on windows because URLClassLoader locks jar files - } - } - - @Test + @Test public void emptyManifest() throws Exception { Manifest mf = new Manifest(); File jar = createJar(mf, "emptyManifest.jar"); @@ -99,7 +84,7 @@ public class ManifestUtilsTest { private File createJar(Manifest mf, String name) throws Exception { mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); - File file = new File(tempDir, name); + File file = tempDir.newFile(name); OutputStream out = new JarOutputStream(new FileOutputStream(file), mf); out.flush(); IOUtils.closeQuietly(out); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/TimeProfilerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/TimeProfilerTest.java index fc4c695cf75..a46e941549c 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/TimeProfilerTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/TimeProfilerTest.java @@ -19,75 +19,55 @@ */ package org.sonar.api.utils; -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.LoggerContext; -import ch.qos.logback.core.WriterAppender; -import ch.qos.logback.core.layout.EchoLayout; -import org.apache.commons.lang.StringUtils; +import org.junit.Before; import org.junit.Test; -import org.slf4j.LoggerFactory; +import org.slf4j.Logger; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertThat; -import static org.junit.internal.matchers.StringContains.containsString; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.*; public class TimeProfilerTest { + private Logger logger; + + @Before + public void before() { + logger = mock(Logger.class); + } + @Test public void testBasicProfiling() { - StringWriter writer = new StringWriter(); - TimeProfiler profiler = new TimeProfiler(mockLogger(writer)); - + TimeProfiler profiler = new TimeProfiler(logger); profiler.start("Cycle analysis"); - assertThat(writer.toString(), containsString("[INFO] Cycle analysis...")); + verify(logger).info("Cycle analysis..."); profiler.stop(); - assertThat(writer.toString(), containsString("[INFO] Cycle analysis done:")); + verify(logger).info(eq("{} done: {} ms"), eq("Cycle analysis"), anyInt()); } @Test - public void stopOnce() throws IOException { - StringWriter writer = new StringWriter(); - TimeProfiler profiler = new TimeProfiler(mockLogger(writer)); + public void stopOnce() { + TimeProfiler profiler = new TimeProfiler(logger); profiler.start("Cycle analysis"); profiler.stop(); profiler.stop(); profiler.stop(); - assertThat(StringUtils.countMatches(writer.toString(), "Cycle analysis done"), is(1)); + verify(logger, times(1)).info(anyString()); // start() executes log() with 1 parameter + verify(logger, times(1)).info(anyString(), anyString(), anyInt()); // stop() executes log() with 3 parameters } @Test - public void doNotLogNeverEndedTask() throws IOException { - StringWriter writer = new StringWriter(); - TimeProfiler profiler = new TimeProfiler(mockLogger(writer)); + public void doNotLogNeverEndedTask() { + TimeProfiler profiler = new TimeProfiler(logger); profiler.start("Cycle analysis"); profiler.start("New task"); profiler.stop(); profiler.stop(); - assertThat(writer.toString(), not(containsString("Cycle analysis done"))); - } - - - private static Logger mockLogger(Writer writer) { - WriterAppender writerAppender = new WriterAppender(); - writerAppender.setLayout(new EchoLayout()); - writerAppender.setWriter(writer); - writerAppender.setImmediateFlush(true); - writerAppender.start(); - - Logger logger = ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger(TimeProfilerTest.class); - logger.addAppender(writerAppender); - logger.setLevel(Level.INFO); - logger.setAdditive(true); - return logger; - + verify(logger, never()).info(eq("{} done: {} ms"), eq("Cycle analysis"), anyInt()); + verify(logger, times(1)).info(eq("{} done: {} ms"), eq("New task"), anyInt()); } } diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/test/java/foo/BarTest.java b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/test/java/foo/BarTest.java index ecd39bd391f..5d99561dd1c 100644 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/test/java/foo/BarTest.java +++ b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/test/java/foo/BarTest.java @@ -1,4 +1,6 @@ package foo; -public class BarTest { +import org.junit.Ignore; + +public abstract class BarTest { }
\ No newline at end of file |