Class MockSystemReader
java.lang.Object
org.eclipse.jgit.util.SystemReader
org.eclipse.jgit.junit.MockSystemReader
Mock
SystemReader for tests.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FileBasedConfig(package private) long(package private) FileBasedConfigprivate FileBasedConfig -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClear propertiesgetClock()Get clock instance preferred by this system.longGet the current system timegetDateTimeInstance(int dateStyle, int timeStyle) Returns a date/time format instance for the given styles.Get value of the system variableGets the hostname of the local host.Get the jgit configuration located at $XDG_CONFIG_HOME/jgit/config.Get the locale to usegetProperty(String key) Get value of the system propertygetSimpleDateFormat(String pattern) Returns a simple date format instance as specified by the given pattern.Get the gitconfig configuration found in the system-wide "etc" directory.intgetTimezone(long when) Get the local time zoneGet system time zone, possibly mocked for testingGet the git configuration found in the user home.private voidopenJGitConfig(Config parent, FS fs) Open the jgit configuration located at $XDG_CONFIG_HOME/jgit/config.openSystemConfig(Config parent, FS fs) Open the gitconfig configuration found in the system-wide "etc" directory.openUserConfig(Config parent, FS fs) Open the git configuration found in the user home.private voidvoidAssign some properties for the currently executing platformvoidsetJGitConfig(FileBasedConfig jgitConfig) Set the jgit config stored at $XDG_CONFIG_HOME/jgit/configvoidsetProperty(String key, String value) Set a propertysetSystemGitConfig(FileBasedConfig systemGitConfig) Set the system-level git configvoidsetUnix()Emulate UnixsetUserGitConfig(FileBasedConfig userGitConfig) Set the user-level git configvoidEmulate Windowsvoidtick(int secDelta) Adjusts the current time in seconds.toString()Methods inherited from class SystemReader
checkPath, checkPath, getInstance, getSimpleDateFormat, isMacOS, isWindows, setInstance, setPlatformChecker
-
Field Details
-
now
long now -
values
-
userGitConfig
-
jgitConfig
-
systemGitConfig
FileBasedConfig systemGitConfig
-
-
Constructor Details
-
MockSystemReader
public MockSystemReader()Constructor forMockSystemReader
-
-
Method Details
-
setUserGitConfig
Set the user-level git config- Parameters:
userGitConfig- set another user-level git config- Returns:
- the old user-level git config
-
setJGitConfig
Set the jgit config stored at $XDG_CONFIG_HOME/jgit/config- Parameters:
jgitConfig- set the jgit configuration
-
setSystemGitConfig
Set the system-level git config- Parameters:
systemGitConfig- the new system-level git config- Returns:
- the old system-level config
-
init
-
clearProperties
public void clearProperties()Clear properties -
setProperty
-
getenv
Get value of the system variable- Specified by:
getenvin classSystemReader- Parameters:
variable- system variable to read- Returns:
- value of the system variable
-
getProperty
Get value of the system property- Specified by:
getPropertyin classSystemReader- Parameters:
key- of the system property to read- Returns:
- value of the system property
-
openUserConfig
Open the git configuration found in the user home. UseSystemReader.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.- Specified by:
openUserConfigin classSystemReader- Parameters:
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.- Returns:
- the git configuration found in the user home
-
openSystemConfig
Open the gitconfig configuration found in the system-wide "etc" directory. UseSystemReader.getSystemConfig()to get the current system-wide git configuration since it manages automatic reloading when the gitconfig file was modified and avoids unnecessary reloads.- Specified by:
openSystemConfigin classSystemReader- Parameters:
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.- Returns:
- the gitconfig configuration found in the system-wide "etc" directory
-
getUserConfig
Description copied from class:SystemReaderGet the git configuration found in the user home. The configuration will be reloaded automatically if the configuration file was modified. Also reloads the system config if the system config file was modified. If the configuration file wasn't modified returns the cached configuration.- Overrides:
getUserConfigin classSystemReader- Returns:
- the git configuration found in the user home
- Throws:
IOException- if something went wrong when reading filesConfigInvalidException- if configuration is invalid
-
getJGitConfig
Description copied from class:SystemReaderGet the jgit configuration located at $XDG_CONFIG_HOME/jgit/config. The configuration will be reloaded automatically if the configuration file was modified. If the configuration file wasn't modified returns the cached configuration.- Overrides:
getJGitConfigin classSystemReader- Returns:
- the jgit configuration located at $XDG_CONFIG_HOME/jgit/config
-
getSystemConfig
Description copied from class:SystemReaderGet the gitconfig configuration found in the system-wide "etc" directory. The configuration will be reloaded automatically if the configuration file was modified otherwise returns the cached system level config.- Overrides:
getSystemConfigin classSystemReader- Returns:
- the gitconfig configuration found in the system-wide "etc" directory
- Throws:
IOException- if something went wrong when reading filesConfigInvalidException- if configuration is invalid
-
getHostname
Gets the hostname of the local host. If no hostname can be found, the hostname is set to the default value "localhost".- Specified by:
getHostnamein classSystemReader- Returns:
- the canonical hostname
-
getCurrentTime
public long getCurrentTime()Get the current system time- Specified by:
getCurrentTimein classSystemReader- Returns:
- the current system time
-
getClock
Get clock instance preferred by this system.- Overrides:
getClockin classSystemReader- Returns:
- clock instance preferred by this system.
-
tick
public void tick(int secDelta) Adjusts the current time in seconds.- Parameters:
secDelta- number of seconds to add to the current time.- Since:
- 4.2
-
getTimezone
public int getTimezone(long when) Get the local time zone- Specified by:
getTimezonein classSystemReader- Parameters:
when- a system timestamp- Returns:
- the local time zone
-
getTimeZone
Get system time zone, possibly mocked for testing- Overrides:
getTimeZonein classSystemReader- Returns:
- system time zone, possibly mocked for testing
-
getLocale
Get the locale to use- Overrides:
getLocalein classSystemReader- Returns:
- the locale to use
-
getSimpleDateFormat
Returns a simple date format instance as specified by the given pattern.- Overrides:
getSimpleDateFormatin classSystemReader- Parameters:
pattern- the pattern as defined inSimpleDateFormat(String)- Returns:
- the simple date format
-
getDateTimeInstance
Returns a date/time format instance for the given styles.- Overrides:
getDateTimeInstancein classSystemReader- Parameters:
dateStyle- the date style as specified inDateFormat.getDateTimeInstance(int, int)timeStyle- the time style as specified inDateFormat.getDateTimeInstance(int, int)- Returns:
- the date format
-
setCurrentPlatform
public void setCurrentPlatform()Assign some properties for the currently executing platform -
setWindows
public void setWindows()Emulate Windows -
setUnix
public void setUnix()Emulate Unix -
resetOsNames
private void resetOsNames() -
toString
-
openJGitConfig
Description copied from class:SystemReaderOpen the jgit configuration located at $XDG_CONFIG_HOME/jgit/config. UseSystemReader.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.- Specified by:
openJGitConfigin classSystemReader- Parameters:
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.- Returns:
- the jgit configuration located at $XDG_CONFIG_HOME/jgit/config
-