|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.sonar.api.utils.System2
public class System2
Proxy over System. It aims to improve testability of classes
that interact with low-level system methods, for example :
public class MyClass {
private final System2 system;
public MyClass(System2 s) {
this.system = s;
}
public long xxx() {
return system.now();
}
}
@Test
public void should_return_xxx() {
// using Mockito
System2 system = mock(System2.class);
long now = 123456789L;
doReturn(now).when(system).now();
assertThat(new MyClass(system).xxx()).isEqualTo(now);
}
Note that the name System2 was chosen to not conflict with System.
An instance is available in IoC container since 4.3.
| Field Summary | |
|---|---|
static System2 |
INSTANCE
|
| Constructor Summary | |
|---|---|
System2()
|
|
| Method Summary | |
|---|---|
String |
envVariable(String key)
Shortcut for System.getenv(String) |
Map<String,String> |
envVariables()
Shortcut for System.getenv() |
boolean |
isJavaAtLeast17()
True if Java 7 or Java 8 runtime environment |
boolean |
isOsWindows()
True if this is MS Windows. |
long |
now()
Shortcut for System.currentTimeMillis() |
void |
println(String obj)
|
Properties |
properties()
Shortcut for System.getProperties() |
String |
property(String key)
Shortcut for System.getProperty(String) |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final System2 INSTANCE
| Constructor Detail |
|---|
public System2()
| Method Detail |
|---|
public long now()
System.currentTimeMillis()
public Properties properties()
System.getProperties()
@CheckForNull public String property(String key)
System.getProperty(String)
public Map<String,String> envVariables()
System.getenv()
@CheckForNull public String envVariable(String key)
System.getenv(String)
public boolean isOsWindows()
public boolean isJavaAtLeast17()
public void println(String obj)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||