diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2014-03-25 11:20:50 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2014-03-25 11:40:39 +0100 |
commit | 07cb91a63aff68ff0253f389b0b1eafa991e4cb6 (patch) | |
tree | a1081f4d98bd12073e9133e125083f12011cb425 /sonar-plugin-api | |
parent | c2bc9f0c49b4128399ae5146d33b1e612359618b (diff) | |
download | sonarqube-07cb91a63aff68ff0253f389b0b1eafa991e4cb6.tar.gz sonarqube-07cb91a63aff68ff0253f389b0b1eafa991e4cb6.zip |
Improve org.sonar.api.utils.System2 :
* add to picocontainer
* new method isJavaAtLeast17()
* fix Javadoc
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java | 19 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java | 11 |
2 files changed, 25 insertions, 5 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java index 44c90924939..bae39cb0974 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java @@ -20,6 +20,8 @@ package org.sonar.api.utils; import org.apache.commons.lang.SystemUtils; +import org.sonar.api.BatchComponent; +import org.sonar.api.ServerComponent; import javax.annotation.CheckForNull; import java.util.Map; @@ -28,7 +30,7 @@ import java.util.Properties; /** * Proxy over {@link java.lang.System}. It aims to improve testability of classes * that interact with low-level system methods, for example : - * + * <p/> * <pre> * public class MyClass { * private final System2 system; @@ -42,7 +44,7 @@ import java.util.Properties; * } * } * - * @Test + * {@literal @}Test * public void should_return_xxx() { * // using Mockito * System2 system = mock(System2.class); @@ -51,13 +53,14 @@ import java.util.Properties; * assertThat(new MyClass(system).xxx()).isEqualTo(now); * } * </pre> - * * <p/> * Note that the name System2 was chosen to not conflict with {@link java.lang.System}. + * <p/> + * An instance is available in IoC container since 4.3. * * @since 4.2 */ -public class System2 { +public class System2 implements BatchComponent, ServerComponent { public static final System2 INSTANCE = new System2(); @@ -105,6 +108,14 @@ public class System2 { return SystemUtils.IS_OS_WINDOWS; } + /** + * True if Java 7 or Java 8 runtime environment + * @since 4.3 + */ + public boolean isJavaAtLeast17() { + return SystemUtils.isJavaVersionAtLeast(1.7f); + } + public void println(String obj) { System.out.print(obj); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java index 6157218cf2e..d60c869c547 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java @@ -51,7 +51,7 @@ public class System2Test { @Test public void testEnvVariables() throws Exception { - Map<String,String> expected = System.getenv(); + Map<String, String> expected = System.getenv(); assertThat(System2.INSTANCE.envVariables()).isNotNull().isEqualTo(expected); } @@ -73,6 +73,15 @@ public class System2Test { } @Test + public void testIsJavaAtLeast17() throws Exception { + if (SystemUtils.IS_JAVA_1_6) { + assertThat(System2.INSTANCE.isJavaAtLeast17()).isFalse(); + } else { + assertThat(System2.INSTANCE.isJavaAtLeast17()).isTrue(); + } + } + + @Test public void testPrintln() throws Exception { // well, how to assert that ? Adding a System3 dependency to System2 ? :-) System2.INSTANCE.println("foo"); |