Package org.eclipse.jgit.junit
Class MockSystemReader
- java.lang.Object
-
- org.eclipse.jgit.util.SystemReader
-
- org.eclipse.jgit.junit.MockSystemReader
-
public class MockSystemReader extends SystemReader
MockSystemReader
for tests.
-
-
Constructor Summary
Constructors Constructor Description MockSystemReader()
Constructor forMockSystemReader
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearProperties()
Clear propertiesMonotonicClock
getClock()
Get clock instance preferred by this system.long
getCurrentTime()
Get the current system timeDateFormat
getDateTimeInstance(int dateStyle, int timeStyle)
Returns a date/time format instance for the given styles.String
getenv(String variable)
Get value of the system variableString
getHostname()
Gets the hostname of the local host.FileBasedConfig
getJGitConfig()
Get the jgit configuration located at $XDG_CONFIG_HOME/jgit/config.Locale
getLocale()
Get the locale to useString
getProperty(String key)
Get value of the system propertySimpleDateFormat
getSimpleDateFormat(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.int
getTimezone(long when)
Get the local time zoneTimeZone
getTimeZone()
Get system time zone, possibly mocked for testingStoredConfig
getUserConfig()
Get the git configuration found in the user home.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.void
setCurrentPlatform()
Assign some properties for the currently executing platformvoid
setJGitConfig(FileBasedConfig jgitConfig)
Set the jgit config stored at $XDG_CONFIG_HOME/jgit/configvoid
setProperty(String key, String value)
Set a propertyFileBasedConfig
setSystemGitConfig(FileBasedConfig systemGitConfig)
Set the system-level git configvoid
setUnix()
Emulate UnixFileBasedConfig
setUserGitConfig(FileBasedConfig userGitConfig)
Set the user-level git configvoid
setWindows()
Emulate Windowsvoid
tick(int secDelta)
Adjusts the current time in seconds.String
toString()
-
Methods inherited from class org.eclipse.jgit.util.SystemReader
checkPath, checkPath, getDefaultCharset, getInstance, getSimpleDateFormat, isLinux, isMacOS, isWindows, setInstance, setPlatformChecker
-
-
-
-
Method Detail
-
setUserGitConfig
public FileBasedConfig setUserGitConfig(FileBasedConfig userGitConfig)
Set the user-level git config- Parameters:
userGitConfig
- set another user-level git config- Returns:
- the old user-level git config
- Since:
- 5.1.9
-
setJGitConfig
public void setJGitConfig(FileBasedConfig jgitConfig)
Set the jgit config stored at $XDG_CONFIG_HOME/jgit/config- Parameters:
jgitConfig
- set the jgit configuration- Since:
- 5.5
-
setSystemGitConfig
public FileBasedConfig setSystemGitConfig(FileBasedConfig systemGitConfig)
Set the system-level git config- Parameters:
systemGitConfig
- the new system-level git config- Returns:
- the old system-level config
- Since:
- 5.1.9
-
clearProperties
public void clearProperties()
Clear properties
-
setProperty
public void setProperty(String key, String value)
Set a property- Parameters:
key
-value
-
-
getenv
public String getenv(String variable)
Get value of the system variable- Specified by:
getenv
in classSystemReader
- Parameters:
variable
- system variable to read- Returns:
- value of the system variable
-
getProperty
public String getProperty(String key)
Get value of the system property- Specified by:
getProperty
in classSystemReader
- Parameters:
key
- of the system property to read- Returns:
- value of the system property
-
openUserConfig
public FileBasedConfig openUserConfig(Config parent, FS fs)
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:
openUserConfig
in 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
public FileBasedConfig openSystemConfig(Config parent, FS fs)
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:
openSystemConfig
in 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
public StoredConfig getUserConfig() throws IOException, ConfigInvalidException
Description copied from class:SystemReader
Get 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:
getUserConfig
in classSystemReader
- Returns:
- the git configuration found in the user home
- Throws:
IOException
- if something went wrong when reading filesConfigInvalidException
- if configuration is invalid
-
getJGitConfig
public FileBasedConfig getJGitConfig()
Description copied from class:SystemReader
Get 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:
getJGitConfig
in classSystemReader
- Returns:
- the jgit configuration located at $XDG_CONFIG_HOME/jgit/config
-
getSystemConfig
public StoredConfig getSystemConfig() throws IOException, ConfigInvalidException
Description copied from class:SystemReader
Get 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:
getSystemConfig
in 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
public String 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:
getHostname
in classSystemReader
- Returns:
- the canonical hostname
-
getCurrentTime
public long getCurrentTime()
Get the current system time- Specified by:
getCurrentTime
in classSystemReader
- Returns:
- the current system time
-
getClock
public MonotonicClock getClock()
Get clock instance preferred by this system.- Overrides:
getClock
in 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:
getTimezone
in classSystemReader
- Parameters:
when
- a system timestamp- Returns:
- the local time zone
-
getTimeZone
public TimeZone getTimeZone()
Get system time zone, possibly mocked for testing- Overrides:
getTimeZone
in classSystemReader
- Returns:
- system time zone, possibly mocked for testing
-
getLocale
public Locale getLocale()
Get the locale to use- Overrides:
getLocale
in classSystemReader
- Returns:
- the locale to use
-
getSimpleDateFormat
public SimpleDateFormat getSimpleDateFormat(String pattern)
Returns a simple date format instance as specified by the given pattern.- Overrides:
getSimpleDateFormat
in classSystemReader
- Parameters:
pattern
- the pattern as defined inSimpleDateFormat(String)
- Returns:
- the simple date format
-
getDateTimeInstance
public DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
Returns a date/time format instance for the given styles.- Overrides:
getDateTimeInstance
in 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
-
openJGitConfig
public FileBasedConfig openJGitConfig(Config parent, FS fs)
Description copied from class:SystemReader
Open 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:
openJGitConfig
in 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
-
-