github-api/src/test/java/me/brianlong/git/CommandUnitTest.java

52 lines
1.4 KiB
Java

package me.brianlong.git;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ListBranchCommand.ListMode;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.util.FileUtils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
public class CommandUnitTest {
private final static GitHubTestCredentials githubCreds = new GitHubTestCredentials();
private static File tmpdir;
private static Git git;
@BeforeClass
public static void init() throws GitAPIException, IOException {
tmpdir = new File(System.getProperty("java.io.tmpdir"), "git-" + UUID.randomUUID().toString() + ".tmp");
git = new CloneCommand()
.setURI("git@github.com:bmlong137/env-docker-adbp.git")
.setCredentialsProvider(githubCreds.toJGitCredentialsProvider())
.setDirectory(tmpdir)
.call();
}
@AfterClass
public static void cleanup() throws IOException {
git.close();
FileUtils.delete(tmpdir, FileUtils.RECURSIVE);
}
@Test
public void lotsOfBranches() throws GitAPIException {
List<Ref> remoteBranches = git.branchList().setListMode(ListMode.REMOTE).call();
Assert.assertNotNull(remoteBranches);
Assert.assertTrue(remoteBranches.size() > 5);
}
}