public class MockSystemReader extends SystemReader
SystemReader
for tests.Modifier and Type | Class and Description |
---|---|
private static class |
MockSystemReader.MockConfig |
Modifier and Type | Field and Description |
---|---|
private FileBasedConfig |
jgitConfig |
(package private) long |
now |
(package private) FileBasedConfig |
systemGitConfig |
private FileBasedConfig |
userGitConfig |
(package private) java.util.Map<java.lang.String,java.lang.String> |
values |
Constructor and Description |
---|
MockSystemReader()
Constructor for
MockSystemReader |
Modifier and Type | Method and Description |
---|---|
void |
clearProperties()
Clear properties
|
MonotonicClock |
getClock()
Get clock instance preferred by this system.
|
long |
getCurrentTime()
Get the current system time
|
java.text.DateFormat |
getDateTimeInstance(int dateStyle,
int timeStyle)
Returns a date/time format instance for the given styles.
|
java.lang.String |
getenv(java.lang.String variable)
Get value of the system variable
|
java.lang.String |
getHostname()
Gets the hostname of the local host.
|
FileBasedConfig |
getJGitConfig()
Get the jgit configuration located at $XDG_CONFIG_HOME/jgit/config.
|
java.util.Locale |
getLocale()
Get the locale to use
|
java.lang.String |
getProperty(java.lang.String key)
Get value of the system property
|
java.text.SimpleDateFormat |
getSimpleDateFormat(java.lang.String pattern)
Returns a simple date format instance as specified by the given pattern.
|
StoredConfig |
getSystemConfig()
Get the gitconfig configuration found in the system-wide "etc" directory.
|
java.util.TimeZone |
getTimeZone()
Get system time zone, possibly mocked for testing
|
int |
getTimezone(long when)
Get the local time zone
|
StoredConfig |
getUserConfig()
Get the git configuration found in the user home.
|
private void |
init(java.lang.String n) |
FileBasedConfig |
openJGitConfig(Config parent,
FS fs)
Open the jgit configuration located at $XDG_CONFIG_HOME/jgit/config.
|
FileBasedConfig |
openSystemConfig(Config parent,
FS fs)
Open the gitconfig configuration found in the system-wide "etc"
directory.
|
FileBasedConfig |
openUserConfig(Config parent,
FS fs)
Open the git configuration found in the user home.
|
private void |
resetOsNames() |
void |
setCurrentPlatform()
Assign some properties for the currently executing platform
|
void |
setJGitConfig(FileBasedConfig jgitConfig)
Set the jgit config stored at $XDG_CONFIG_HOME/jgit/config
|
void |
setProperty(java.lang.String key,
java.lang.String value)
Set a property
|
FileBasedConfig |
setSystemGitConfig(FileBasedConfig systemGitConfig)
Set the system-level git config
|
void |
setUnix()
Emulate Unix
|
FileBasedConfig |
setUserGitConfig(FileBasedConfig userGitConfig)
Set the user-level git config
|
void |
setWindows()
Emulate Windows
|
void |
tick(int secDelta)
Adjusts the current time in seconds.
|
java.lang.String |
toString() |
checkPath, checkPath, getInstance, getSimpleDateFormat, isMacOS, isWindows, setInstance, setPlatformChecker
long now
final java.util.Map<java.lang.String,java.lang.String> values
private FileBasedConfig userGitConfig
private FileBasedConfig jgitConfig
FileBasedConfig systemGitConfig
public FileBasedConfig setUserGitConfig(FileBasedConfig userGitConfig)
userGitConfig
- set another user-level git configpublic void setJGitConfig(FileBasedConfig jgitConfig)
jgitConfig
- set the jgit configurationpublic FileBasedConfig setSystemGitConfig(FileBasedConfig systemGitConfig)
systemGitConfig
- the new system-level git configprivate void init(java.lang.String n)
public void clearProperties()
public void setProperty(java.lang.String key, java.lang.String value)
key
- value
- public java.lang.String getenv(java.lang.String variable)
getenv
in class SystemReader
variable
- system variable to readpublic java.lang.String getProperty(java.lang.String key)
getProperty
in class SystemReader
key
- of the system property to readpublic FileBasedConfig openUserConfig(Config parent, FS fs)
SystemReader.getUserConfig()
to get the current git configuration in the user
home since it manages automatic reloading when the gitconfig file was
modified and avoids unnecessary reloads.openUserConfig
in class SystemReader
parent
- a config with values not found directly in the returned configfs
- the file system abstraction which will be necessary to perform
certain file system operations.public FileBasedConfig openSystemConfig(Config parent, FS fs)
SystemReader.getSystemConfig()
to get the current system-wide
git configuration since it manages automatic reloading when the gitconfig
file was modified and avoids unnecessary reloads.openSystemConfig
in class SystemReader
parent
- a config with values not found directly in the returned
config. Null is a reasonable value here.fs
- the file system abstraction which will be necessary to perform
certain file system operations.public StoredConfig getUserConfig() throws java.io.IOException, ConfigInvalidException
SystemReader
getUserConfig
in class SystemReader
java.io.IOException
- if something went wrong when reading filesConfigInvalidException
- if configuration is invalidpublic FileBasedConfig getJGitConfig()
SystemReader
getJGitConfig
in class SystemReader
public StoredConfig getSystemConfig() throws java.io.IOException, ConfigInvalidException
SystemReader
getSystemConfig
in class SystemReader
java.io.IOException
- if something went wrong when reading filesConfigInvalidException
- if configuration is invalidpublic java.lang.String getHostname()
getHostname
in class SystemReader
public long getCurrentTime()
getCurrentTime
in class SystemReader
public MonotonicClock getClock()
getClock
in class SystemReader
public void tick(int secDelta)
secDelta
- number of seconds to add to the current time.public int getTimezone(long when)
getTimezone
in class SystemReader
when
- a system timestamppublic java.util.TimeZone getTimeZone()
getTimeZone
in class SystemReader
public java.util.Locale getLocale()
getLocale
in class SystemReader
public java.text.SimpleDateFormat getSimpleDateFormat(java.lang.String pattern)
getSimpleDateFormat
in class SystemReader
pattern
- the pattern as defined in
SimpleDateFormat.SimpleDateFormat(String)
public java.text.DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
getDateTimeInstance
in class SystemReader
dateStyle
- the date style as specified in
DateFormat.getDateTimeInstance(int, int)
timeStyle
- the time style as specified in
DateFormat.getDateTimeInstance(int, int)
public void setCurrentPlatform()
public void setWindows()
public void setUnix()
private void resetOsNames()
public java.lang.String toString()
toString
in class java.lang.Object
public FileBasedConfig openJGitConfig(Config parent, FS fs)
SystemReader
SystemReader.getJGitConfig()
to get the current jgit configuration in the
user home since it manages automatic reloading when the jgit config file
was modified and avoids unnecessary reloads.openJGitConfig
in class SystemReader
parent
- a config with values not found directly in the returned configfs
- the file system abstraction which will be necessary to perform
certain file system operations.