aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-runner-dist/src/test
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-06-16 17:38:52 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-06-19 17:08:54 +0200
commitf2e74b6d6935082e4d75a5ddfaf66e8ba1079f1f (patch)
treeddecebafb089a6a2518aa96a3fcbd03b852ec13c /sonar-runner-dist/src/test
parente4ba9869d57dc4dd92648b5c8406d26fcd550d46 (diff)
downloadsonar-scanner-cli-f2e74b6d6935082e4d75a5ddfaf66e8ba1079f1f.tar.gz
sonar-scanner-cli-f2e74b6d6935082e4d75a5ddfaf66e8ba1079f1f.zip
SONARUNNER-138 Allow to redirect logs to a custom stream
Diffstat (limited to 'sonar-runner-dist/src/test')
-rw-r--r--sonar-runner-dist/src/test/java/org/sonar/runner/StatsTest.java23
1 files changed, 15 insertions, 8 deletions
diff --git a/sonar-runner-dist/src/test/java/org/sonar/runner/StatsTest.java b/sonar-runner-dist/src/test/java/org/sonar/runner/StatsTest.java
index b7062ad..edf61ba 100644
--- a/sonar-runner-dist/src/test/java/org/sonar/runner/StatsTest.java
+++ b/sonar-runner-dist/src/test/java/org/sonar/runner/StatsTest.java
@@ -19,8 +19,10 @@
*/
package org.sonar.runner;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
+import org.sonar.home.log.LogListener;
+
+import org.sonar.runner.impl.Logs;
+
import java.io.UnsupportedEncodingException;
import org.junit.Test;
@@ -31,17 +33,22 @@ public class StatsTest {
@Test
public void shouldPrintStats() throws UnsupportedEncodingException {
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- System.setOut(new PrintStream(output));
+ final StringBuffer sb = new StringBuffer();
+ Logs.setListener(new LogListener() {
+ @Override
+ public void log(String msg, Level level) {
+ sb.append(msg + System.lineSeparator());
+ }
+ });
new Stats().start().stop();
- String out = output.toString("UTF-8");
- String[] lines = out.split("\n");
+ String out = sb.toString();
+ String[] lines = out.split(System.lineSeparator());
assertThat(lines).hasSize(2);
- assertThat(lines[0]).startsWith("Total time: ");
- assertThat(lines[1]).startsWith("Final Memory: ");
+ assertThat(lines[0]).contains("Total time: ");
+ assertThat(lines[1]).contains("Final Memory: ");
}
@Test