@@ -0,0 +1,2446 @@
+package hudson.plugins.git;%0A%0Aimport hudson.EnvVars;%0Aimport hudson.model.TaskListener;%0Aimport hudson.util.StreamTaskListener;%0Aimport org.jenkinsci.plugins.gitclient.GitClient;%0Aimport org.jvnet.hudson.test.TemporaryDirectoryAllocator;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0A%0Aimport org.apache.commons.io.FileUtils;%0A%0Aimport static junit.framework.TestCase.assertTrue;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.Rule;%0Aimport org.junit.rules.ExpectedException;%0A%0Apublic class GitAPIBadInitTest %7B%0A%0A    private final TemporaryDirectoryAllocator temporaryDirectoryAllocator;%0A    private final EnvVars env;%0A%0A    public GitAPIBadInitTest() %7B%0A        temporaryDirectoryAllocator = new TemporaryDirectoryAllocator();%0A        env = new EnvVars();%0A    %7D%0A%0A    @Rule%0A    public ExpectedException thrown = ExpectedException.none();%0A%0A    private File tempDir;%0A    private TaskListener listener;%0A%0A    @Before%0A    public void setUp() throws IOException, InterruptedException %7B%0A        tempDir = temporaryDirectoryAllocator.allocate();%0A        listener = StreamTaskListener.fromStderr();%0A    %7D%0A%0A    @After%0A    public void tearDown() throws InterruptedException %7B%0A        temporaryDirectoryAllocator.disposeAsync();%0A    %7D%0A%0A    @Test%0A    public void testInitExistingDirectory() throws Exception %7B%0A        GitClient git = new GitAPI(%22git%22, tempDir, listener, env);%0A        git.init();%0A        File gitDir = new File(tempDir, %22.git%22);%0A        assertTrue(gitDir + %22 not created%22, gitDir.exists());%0A        assertTrue(gitDir + %22 not a directory%22, gitDir.isDirectory());%0A    %7D%0A%0A    @Test%0A    public void testInitNoDirectory() throws Exception %7B%0A        File nonExistentDirectory = new File(tempDir, %22dir-does-not-exist%22);%0A        GitClient git = new GitAPI(%22git%22, nonExistentDirectory, listener, env);%0A        thrown.expect(GitException.class);%0A        thrown.expectMessage(%22Could not init %22 + nonExistentDirectory.getAbsolutePath());%0A        git.init();%0A    %7D%0A%0A    @Test%0A    public void testInitExistingFile() throws Exception %7B%0A        File existingFile = new File(tempDir, %22file-exists%22);%0A        FileUtils.writeStringToFile(existingFile, %22git init should fail due to this file%22, %22UTF-8%22);%0A        GitClient git = new GitAPI(%22git%22, existingFile, listener, env);%0A        thrown.expect(GitException.class);%0A        thrown.expectMessage(%22Could not init %22 + existingFile.getAbsolutePath());%0A        git.init();%0A    %7D%0A%7D%0A

Add GitAPI.init() failure mode tests