@ScannerSide @ServerSide @ComputeEngineSide public class System2 extends Object
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);
}
System.
| Constructor and Description |
|---|
System2() |
| Modifier and Type | Method and Description |
|---|---|
void |
close(AutoCloseable closeable)
Closes the object and throws an
IllegalStateException on error. |
String |
envVariable(String key)
Shortcut for
System.getenv(String) |
Map<String,String> |
envVariables()
Shortcut for
System.getenv() |
TimeZone |
getDefaultTimeZone() |
URL |
getResource(String name) |
boolean |
isJavaAtLeast17()
Deprecated.
in 6.4. Java 8+ is required, so this method always returns
true. |
boolean |
isOsWindows()
True if this is MS Windows.
|
Date |
newDate()
Deprecated.
in 5.2. Please use
now() |
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) |
System2 |
setProperty(String key,
String value)
Shortcut for
System{@link #setProperty(String, String)} |
public System2()
public long now()
System.currentTimeMillis()public Properties properties()
System.getProperties()@CheckForNull public String property(String key)
System.getProperty(String)public System2 setProperty(String key, String value)
System{@link #setProperty(String, String)}public Map<String,String> envVariables()
System.getenv()@CheckForNull public String envVariable(String key)
System.getenv(String)public boolean isOsWindows()
@Deprecated public boolean isJavaAtLeast17()
true.@Deprecated public Date newDate()
now()public TimeZone getDefaultTimeZone()
public URL getResource(String name)
Class.getResource(String)public void close(AutoCloseable closeable)
IllegalStateException on error.Copyright © 2009–2017 SonarSource. All rights reserved.