Browse Source

Fix tests for Ant task "git-clone"

If project.init() isn't called GitCloneTaskTest fails when started from
Eclipse, according to [1] calling init() is necessary to properly
initialize the Ant project programmatically.

Always set the destination folder in order to ensure that all test
resources are created under the project's target folder and do not
pollute the project's source tree with test data.

[1]
http://ant.1045680.n5.nabble.com/project-createTask-not-working-with-ant-1-8-2-td3385716.html

Change-Id: Icbeb62680b018a92673faa58828b5e850564c7a8
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-2.0
Matthias Sohn 13 years ago
parent
commit
ee90d6afba
  1. 11
      org.eclipse.jgit.ant.test/src/org/eclipse/jgit/ant/tasks/GitCloneTaskTest.java

11
org.eclipse.jgit.ant.test/src/org/eclipse/jgit/ant/tasks/GitCloneTaskTest.java

@ -45,6 +45,7 @@ package org.eclipse.jgit.ant.tasks;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.DefaultLogger;
@ -60,13 +61,17 @@ public class GitCloneTaskTest extends LocalDiskRepositoryTestCase {
private GitCloneTask task; private GitCloneTask task;
private Project project; private Project project;
private File dest;
@Before @Before
public void before() { public void before() throws IOException {
project = new Project(); project = new Project();
project.init();
enableLogging(); enableLogging();
project.addTaskDefinition("git-clone", GitCloneTask.class); project.addTaskDefinition("git-clone", GitCloneTask.class);
task = (GitCloneTask) project.createTask("git-clone"); task = (GitCloneTask) project.createTask("git-clone");
dest = createTempFile();
task.setDest(dest);
} }
@Test(expected = BuildException.class) @Test(expected = BuildException.class)
@ -97,8 +102,6 @@ public class GitCloneTaskTest extends LocalDiskRepositoryTestCase {
FileRepository repo = createBareRepository(); FileRepository repo = createBareRepository();
File directory = repo.getDirectory(); File directory = repo.getDirectory();
task.setUri("file://" + directory); task.setUri("file://" + directory);
File dest = createTempFile();
task.setDest(dest);
task.execute(); task.execute();
assertTrue(RepositoryCache.FileKey.isGitRepository(new File(dest, ".git"), FS.DETECTED)); assertTrue(RepositoryCache.FileKey.isGitRepository(new File(dest, ".git"), FS.DETECTED));
@ -110,8 +113,6 @@ public class GitCloneTaskTest extends LocalDiskRepositoryTestCase {
File directory = repo.getDirectory(); File directory = repo.getDirectory();
task.setUri("file://" + directory); task.setUri("file://" + directory);
task.setBare(true); task.setBare(true);
File dest = createTempFile();
task.setDest(dest);
task.execute(); task.execute();
assertTrue(RepositoryCache.FileKey.isGitRepository(dest, FS.DETECTED)); assertTrue(RepositoryCache.FileKey.isGitRepository(dest, FS.DETECTED));

Loading…
Cancel
Save