From 00b76c8a744d42460034005e725ea2f0dfeb33fe Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 1 Feb 2016 23:09:09 +0100 Subject: [PATCH] Use INFO level by default in unit tests --- .../sonar-process/src/test/resources/logback-test.xml | 2 +- .../sonar-search/src/test/resources/logback-test.xml | 2 +- sonar-application/src/test/resources/logback-test.xml | 2 +- sonar-batch/src/test/resources/logback-test.xml | 2 +- .../main/java/org/sonar/api/utils/log/LogTester.java | 11 +++-------- .../org/sonar/api/utils/log/ConsoleLoggersTest.java | 2 ++ .../java/org/sonar/api/utils/log/LogTesterTest.java | 6 ++---- 7 files changed, 11 insertions(+), 16 deletions(-) diff --git a/server/sonar-process/src/test/resources/logback-test.xml b/server/sonar-process/src/test/resources/logback-test.xml index f2d5a6a466f..9c9ff1aab01 100644 --- a/server/sonar-process/src/test/resources/logback-test.xml +++ b/server/sonar-process/src/test/resources/logback-test.xml @@ -7,7 +7,7 @@ - + diff --git a/server/sonar-search/src/test/resources/logback-test.xml b/server/sonar-search/src/test/resources/logback-test.xml index ff2270cc122..df0bb26d407 100644 --- a/server/sonar-search/src/test/resources/logback-test.xml +++ b/server/sonar-search/src/test/resources/logback-test.xml @@ -31,7 +31,7 @@ - + diff --git a/sonar-application/src/test/resources/logback-test.xml b/sonar-application/src/test/resources/logback-test.xml index f62e5c2b41d..4c62d576dee 100644 --- a/sonar-application/src/test/resources/logback-test.xml +++ b/sonar-application/src/test/resources/logback-test.xml @@ -11,7 +11,7 @@ - + diff --git a/sonar-batch/src/test/resources/logback-test.xml b/sonar-batch/src/test/resources/logback-test.xml index 304e617b1c3..da6be3344a2 100644 --- a/sonar-batch/src/test/resources/logback-test.xml +++ b/sonar-batch/src/test/resources/logback-test.xml @@ -35,7 +35,7 @@ - + diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogTester.java index 4290cc6d16b..25bd90bc669 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogTester.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogTester.java @@ -19,9 +19,8 @@ */ package org.sonar.api.utils.log; -import org.junit.rules.ExternalResource; - import java.util.List; +import org.junit.rules.ExternalResource; /** * For tests only @@ -58,12 +57,8 @@ import java.util.List; */ public class LogTester extends ExternalResource { - private LoggerLevel initialLevel; - @Override protected void before() throws Throwable { - initialLevel = Loggers.getFactory().getLevel(); - // this shared instance breaks compatibility with parallel execution of tests LogInterceptors.set(new ListInterceptor()); setLevel(LoggerLevel.INFO); @@ -72,7 +67,7 @@ public class LogTester extends ExternalResource { @Override protected void after() { LogInterceptors.set(NullInterceptor.NULL_INSTANCE); - setLevel(initialLevel); + setLevel(LoggerLevel.INFO); } LoggerLevel getLevel() { @@ -81,7 +76,7 @@ public class LogTester extends ExternalResource { /** * Enable/disable debug logs. Info, warn and error logs are always enabled. - * By default debug logs are enabled when LogTester is started. + * By default INFO logs are enabled when LogTester is started. */ public LogTester setLevel(LoggerLevel level) { Loggers.getFactory().setLevel(level); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleLoggersTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleLoggersTest.java index 4c0dd961e2a..fa8b2db317d 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleLoggersTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleLoggersTest.java @@ -40,5 +40,7 @@ public class ConsoleLoggersTest { underTest.setLevel(LoggerLevel.DEBUG); assertThat(underTest.getLevel()).isEqualTo(LoggerLevel.DEBUG); + + underTest.setLevel(LoggerLevel.INFO); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogTesterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogTesterTest.java index f396b2f5d6b..0521837bc3b 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogTesterTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogTesterTest.java @@ -29,8 +29,6 @@ public class LogTesterTest { @Test public void info_level_by_default() throws Throwable { - LoggerLevel initial = underTest.getLevel(); - // when LogTester is used, then info logs are enabled by default underTest.before(); assertThat(underTest.getLevel()).isEqualTo(LoggerLevel.INFO); @@ -43,8 +41,8 @@ public class LogTesterTest { // reset to initial level after execution of test underTest.after(); - assertThat(underTest.getLevel()).isEqualTo(initial); - assertThat(Loggers.getFactory().getLevel()).isEqualTo(initial); + assertThat(underTest.getLevel()).isEqualTo(LoggerLevel.INFO); + assertThat(Loggers.getFactory().getLevel()).isEqualTo(LoggerLevel.INFO); } @Test -- 2.39.5