Skip to content
Snippets Groups Projects
Commit f3b1cd92 authored by Jack MacLauchlan CS2015's avatar Jack MacLauchlan CS2015
Browse files

more tests

parent 88f3dc6d
No related branches found
No related tags found
No related merge requests found
......@@ -99,7 +99,7 @@ class GitCommands {
tempDir.toFile().deleteOnExit();
Git.cloneRepository()
// .setURI(System.getProperty("user.dir"))
.setURI("/home/jack/Documents/testrepo/.git")
.setURI(repo.getDirectory().toString())
.setDirectory(tempDir.toFile())
.setBranchesToClone(Collections.singleton("refs/heads/issues"))
.setBranch("refs/heads/issues")
......
......@@ -27,9 +27,8 @@ public class IssueRepo {
public IssueRepo() {
try {
// setGitDir(System.getProperty("user.dir") + "/.git");
setGitDir("/home/jack/Documents/test/.git");
readTree(getCurrentCommit());
setGitDir(System.getProperty("user.dir") + "/.git");
// setGitDir("/home/jack/Documents/test/.git");
} catch (IOException e) {
System.err.println(e.getMessage());
}
......@@ -40,6 +39,7 @@ public class IssueRepo {
.setGitDir(new File(gitDirPath))
.build();
this.git = new GitCommands(repository);
readTree(getCurrentCommit());
}
public boolean writeIssues(String commitMessage) throws IOException {
......
package git;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.TempDirectory;
import util.Util;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ExtendWith(TempDirectory.class)
class GitCommandsTest {
private Repository repository;
private Git git;
@BeforeEach
void setUp(@TempDirectory.TempDir Path tempDir) throws GitAPIException {
this.git = Git.init().setDirectory(new File(tempDir.toString())).call();
git.commit().setMessage("init").call();
git.checkout().setOrphan(true).setCreateBranch(true).setName("issues").call();
this.repository = git.getRepository();
}
@AfterEach
void tearDown() {
repository.close();
}
private String initTestRemote() throws IOException, GitAPIException {
Path cloneDir = Files.createTempDirectory("ddit-test");
cloneDir.toFile().deleteOnExit();
Git remoteGit = Git.init().setDirectory(cloneDir.toFile()).call();
remoteGit.commit().setMessage("init").call();
remoteGit.checkout().setOrphan(true).setCreateBranch(true).setName("issues").call();
return cloneDir.toString();
}
@Test
void testPullEmptyRemote() throws IOException, GitAPIException {
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
System.setOut(new java.io.PrintStream(out));
String remote = initTestRemote();
GitCommands commands = new GitCommands(repository);
commands.pull(remote);
assertEquals("Issues pulled" + System.lineSeparator(), out.toString());
Util.deleteDirectory(remote);
}
}
......@@ -115,6 +115,16 @@ class NicknameTests {
assertFalse(nicknames.updateNickname("123", "another"));
}
@Test
void updateInvalidNicknameAlreadyInUseOut() {
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
System.setOut(new java.io.PrintStream(out));
nicknames.addNickname("123", "nickname");
nicknames.addNickname("321", "another");
nicknames.updateNickname("123", "another");
assertEquals("This hash/nickname is already in use as a nickname" + System.lineSeparator(), out.toString());
}
@Test
void testGetter() {
assertNotNull(nicknames.getIssueNicknames());
......
......@@ -40,7 +40,6 @@ class PojoTests {
assertEquals(1, issue.getTags().size());
}
@Test
void testUserUnEquals() {
User user = new User("test", "test");
......@@ -140,6 +139,42 @@ class PojoTests {
assertEquals(issue, issue);
}
@Test
void testIssueToString() {
String title = "title";
String desc = "desc";
long time = System.currentTimeMillis();
String hash = DigestUtils.sha256Hex(title + desc + time);
Issue issue = new Issue();
issue.setHash(hash);
Issue issue1 = new Issue();
issue1.setHash(hash);
assertEquals(issue.toString(), issue1.toString());
}
@Test
void testIssueToString2() {
String title = "title";
String desc = "desc";
long time = System.currentTimeMillis();
String hash = DigestUtils.sha256Hex(title + desc + time);
Issue issue = new Issue();
issue.setHash(hash);
Issue issue1 = new Issue();
issue1.setHash("different");
assertNotEquals(issue.toString(), issue1.toString());
}
@Test
void testIssueHashCode() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment