assertEquals("", c.getString("foo", null, "bar"));
}
@Test
public void test007_readUserConfig() {
final MockSystemReader mockSystemReader = new MockSystemReader();
SystemReader.setInstance(mockSystemReader);
final String hostname = mockSystemReader.getHostname();
final Config userGitConfig = mockSystemReader.openUserConfig(null,
FS.DETECTED);
final Config localConfig = new Config(userGitConfig);
mockSystemReader.clearProperties();
String authorName;
String authorEmail;
// no values defined nowhere
authorName = localConfig.get(UserConfig.KEY).getAuthorName();
authorEmail = localConfig.get(UserConfig.KEY).getAuthorEmail();
assertEquals(Constants.UNKNOWN_USER_DEFAULT, authorName);
assertEquals(Constants.UNKNOWN_USER_DEFAULT + "@" + hostname, authorEmail);
assertTrue(localConfig.get(UserConfig.KEY).isAuthorNameImplicit());
assertTrue(localConfig.get(UserConfig.KEY).isAuthorEmailImplicit());
// the system user name is defined
mockSystemReader.setProperty(Constants.OS_USER_NAME_KEY, "os user name");
localConfig.uncache(UserConfig.KEY);
authorName = localConfig.get(UserConfig.KEY).getAuthorName();
assertEquals("os user name", authorName);
assertTrue(localConfig.get(UserConfig.KEY).isAuthorNameImplicit());
if (hostname != null && hostname.length() != 0) {
authorEmail = localConfig.get(UserConfig.KEY).getAuthorEmail();
assertEquals("os user name@" + hostname, authorEmail);
}
assertTrue(localConfig.get(UserConfig.KEY).isAuthorEmailImplicit());
// the git environment variables are defined
mockSystemReader.setProperty(Constants.GIT_AUTHOR_NAME_KEY, "git author name");
mockSystemReader.setProperty(Constants.GIT_AUTHOR_EMAIL_KEY, "author@email");
localConfig.uncache(UserConfig.KEY);
authorName = localConfig.get(UserConfig.KEY).getAuthorName();
authorEmail = localConfig.get(UserConfig.KEY).getAuthorEmail();
assertEquals("git author name", authorName);
assertEquals("author@email", authorEmail);