@ScannerSide @ServerSide @ComputeEngineSide public class System2 extends java.lang.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
.
Clock
instead of System2
if you are only interested by date/time operationsConstructor and Description |
---|
System2() |
Modifier and Type | Method and Description |
---|---|
void |
close(java.lang.AutoCloseable closeable)
Closes the object and throws an
IllegalStateException on error. |
java.lang.String |
envVariable(java.lang.String key)
Shortcut for
System.getenv(String) |
java.util.Map<java.lang.String,java.lang.String> |
envVariables()
Shortcut for
System.getenv() |
java.util.TimeZone |
getDefaultTimeZone() |
java.net.URL |
getResource(java.lang.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.
|
java.util.Date |
newDate()
Deprecated.
in 5.2. Please use
now() |
long |
now()
|
void |
println(java.lang.String obj) |
java.util.Properties |
properties()
Shortcut for
System.getProperties() |
java.lang.String |
property(java.lang.String key)
Shortcut for
System.getProperty(String) |
System2 |
setProperty(java.lang.String key,
java.lang.String value)
Shortcut for
System{@link #setProperty(String, String)} |
public static final System2 INSTANCE
public long now()
public java.util.Properties properties()
System.getProperties()
@CheckForNull public java.lang.String property(java.lang.String key)
System.getProperty(String)
public System2 setProperty(java.lang.String key, java.lang.String value)
System{@link #setProperty(String, String)}
public java.util.Map<java.lang.String,java.lang.String> envVariables()
System.getenv()
@CheckForNull public java.lang.String envVariable(java.lang.String key)
System.getenv(String)
public boolean isOsWindows()
@Deprecated public boolean isJavaAtLeast17()
true
.public void println(java.lang.String obj)
@Deprecated public java.util.Date newDate()
now()
public java.util.TimeZone getDefaultTimeZone()
public java.net.URL getResource(java.lang.String name)
Class.getResource(String)
public void close(java.lang.AutoCloseable closeable)
IllegalStateException
on error.