GitConfigurationChecker { @PostConstruct public void start() { try { ensureExistingGlobalGitconfigFile(); checkExcludesfileProperty(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } GitConfigurationChecker();   GitConfigurationChecker(Path globalGitconfigFilePath, Path gitIgnoreFilePath); @PostConstruct void start();  }
@Test public void testWhenNoGitconfigFile() throws Exception { excludesfilePropertyContent = String.format("\n" + "[core]\n" + "\texcludesfile = %s" + "\n", gitignoreFilePath); checker.start(); Assert.assertTrue("New global .gitconfig file should be created in case it doesn't exists.", Files.exists(globalGitconfigFilePath)); Assert.assertTrue("New global .gitignore file should be created.", Files.exists(gitignoreFilePath)); Assert.assertEquals(excludesfilePropertyContent, new String(Files.readAllBytes(globalGitconfigFilePath))); Assert.assertEquals(GITIGNORE_FILE_CONTENT, new String(Files.readAllBytes(gitignoreFilePath))); }
@Test public void testWhenNoExcludesfilePropertyInGitconfigFile() throws Exception { excludesfilePropertyContent = String.format("\n" + "[core]\n" + "\texcludesfile = %s" + "\n", gitignoreFilePath); createGitconfigFile(false); final String existingGitconfigFileContent = new String(Files.readAllBytes(globalGitconfigFilePath)); checker.start(); Assert.assertTrue(Files.exists(globalGitconfigFilePath)); Assert.assertEquals("'core.excludesfile' property should be appended to the existing global .gitconfig file", existingGitconfigFileContent + excludesfilePropertyContent, new String(Files.readAllBytes(globalGitconfigFilePath))); Assert.assertEquals(GITIGNORE_FILE_CONTENT, new String(Files.readAllBytes(gitignoreFilePath))); }
@Test public void testWithExcludesfilePropertyInGitconfigFile() throws Exception { excludesfilePropertyContent = String.format("\n" + "[core]\n" + "\texcludesfile = %s" + "\n", existingGitignoreFilePath); createGitconfigFile(true); final byte[] existingGitconfigFileContent = Files.readAllBytes(globalGitconfigFilePath); final String existingGitignoreFileContent = new String(Files.readAllBytes(existingGitignoreFilePath)); checker.start(); Assert.assertArrayEquals( "Existing global .gitconfig file shouldn't be touched in case it already contains 'core.excludesfile' property.", existingGitconfigFileContent, Files.readAllBytes(globalGitconfigFilePath)); Assert.assertFalse( "New .gitignore file shouldn't be created in case existing global .gitconfig file already contains 'core.excludesfile' property.", Files.exists(gitignoreFilePath)); Assert.assertEquals("New content should be appended to the existing global .gitignore file.", existingGitignoreFileContent + GITIGNORE_FILE_CONTENT, new String(Files.readAllBytes(existingGitignoreFilePath))); }