diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2013-12-02 11:48:31 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2013-12-02 15:54:25 +0100 |
commit | 025c1b1f06604968cc80e2ea0a04d5d0fd260308 (patch) | |
tree | fd16221006c9d78f56a83a6efc33204f15ebbda5 /sonar-application | |
parent | f79985eabb09cd91a2f6e0ff544a677afca63b0d (diff) | |
download | sonarqube-025c1b1f06604968cc80e2ea0a04d5d0fd260308.tar.gz sonarqube-025c1b1f06604968cc80e2ea0a04d5d0fd260308.zip |
SONAR-4756 Fix side effect (SONAR_HOME not set in webapp tests)
Diffstat (limited to 'sonar-application')
-rw-r--r-- | sonar-application/src/test/java/org/sonar/application/LoggingTest.java | 13 | ||||
-rw-r--r-- | sonar-application/src/test/java/org/sonar/application/WebappTest.java | 17 |
2 files changed, 27 insertions, 3 deletions
diff --git a/sonar-application/src/test/java/org/sonar/application/LoggingTest.java b/sonar-application/src/test/java/org/sonar/application/LoggingTest.java index 55b9e4beab8..fb63dff2637 100644 --- a/sonar-application/src/test/java/org/sonar/application/LoggingTest.java +++ b/sonar-application/src/test/java/org/sonar/application/LoggingTest.java @@ -24,6 +24,7 @@ import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.Valve; import org.apache.catalina.startup.Tomcat; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -31,16 +32,26 @@ import org.mockito.ArgumentMatcher; import org.mockito.Mockito; import org.slf4j.Logger; +import java.io.File; import java.util.Properties; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; public class LoggingTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); + @Before + public void setHome() { + File homeDir = temp.newFolder("home"); + System.setProperty("SONAR_HOME", homeDir.getAbsolutePath()); + } + @Test public void enable_access_logs_by_Default() throws Exception { Tomcat tomcat = mock(Tomcat.class, Mockito.RETURNS_DEEP_STUBS); diff --git a/sonar-application/src/test/java/org/sonar/application/WebappTest.java b/sonar-application/src/test/java/org/sonar/application/WebappTest.java index 19dc03ff94b..1c57ed714dc 100644 --- a/sonar-application/src/test/java/org/sonar/application/WebappTest.java +++ b/sonar-application/src/test/java/org/sonar/application/WebappTest.java @@ -21,6 +21,7 @@ package org.sonar.application; import org.apache.catalina.Context; import org.apache.catalina.startup.Tomcat; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -30,16 +31,28 @@ import java.util.Properties; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class WebappTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); + private Env env; + + @Before + public void initEnv() { + env = mock(Env.class); + File sonarHome = temp.newFolder("home"); + when(env.rootDir()).thenReturn(sonarHome); + System.setProperty("SONAR_HOME", sonarHome.getAbsolutePath()); + } + @Test public void fail_on_error() throws Exception { - Env env = mock(Env.class); File webDir = temp.newFolder("web"); when(env.file("web")).thenReturn(webDir); |