Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -149,8 +150,9 @@ void testGetHistory() throws Exception {
@Test
void testGetHistorySubdir() throws Exception {
// Add a subdirectory with some history.
runHgCommand(repositoryRoot, "import",
Paths.get(getClass().getResource("/history/hg-export-subdir.txt").toURI()).toString());
URL exportURL = getClass().getResource("/history/hg-export-subdir.txt");
assertNotNull(exportURL);
runHgCommand(repositoryRoot, "import", Paths.get(exportURL.toURI()).toString());

MercurialRepository mr = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot);
History hist = mr.getHistory(new File(repositoryRoot, "subdir"));
Expand Down Expand Up @@ -206,8 +208,9 @@ public static void runHgCommand(File reposRoot, String... args) {
@Test
void testGetHistoryBranch() throws Exception {
// Branch the repo and add one changeset.
runHgCommand(repositoryRoot, "unbundle",
Paths.get(getClass().getResource("/history/hg-branch.bundle").toURI()).toString());
URL bundleURL = getClass().getResource("/history/hg-branch.bundle");
assertNotNull(bundleURL);
runHgCommand(repositoryRoot, "unbundle", Paths.get(bundleURL.toURI()).toString());
// Switch to the branch.
runHgCommand(repositoryRoot, "update", "mybranch");

Expand Down Expand Up @@ -249,26 +252,28 @@ void testGetHistoryBranch() throws Exception {
@Test
void testGetHistoryGet() throws Exception {
MercurialRepository mr = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot);
String exp_str = "This will be a first novel of mine.\n"
+ "\n"
+ "Chapter 1.\n"
+ "\n"
+ "Let's write some words. It began like this:\n"
+ "\n"
+ "...\n";
String exp_str = """
This will be a first novel of mine.

Chapter 1.

Let's write some words. It began like this:

...
""";
byte[] buffer = new byte[1024];

InputStream input = mr.getHistoryGet(repositoryRoot.getCanonicalPath(),
"novel.txt", REVISIONS[0]);
assertNotNull(input);

String str = "";
StringBuilder stringBuilder = new StringBuilder();
int len;
while ((len = input.read(buffer)) > 0) {
str += new String(buffer, 0, len);
stringBuilder.append(new String(buffer, 0, len));
}
assertNotSame(0, str.length());
assertEquals(exp_str, str);
assertNotSame(0, stringBuilder.length());
assertEquals(exp_str, stringBuilder.toString());
}

/**
Expand Down Expand Up @@ -403,8 +408,9 @@ void testGetLastHistoryEntry() throws Exception {
@ValueSource(booleans = {true, false})
void testMergeCommits(boolean isMergeCommitsEnabled) throws Exception {
// The bundle will add a branch and merge commit in the default branch.
runHgCommand(repositoryRoot, "unbundle",
Paths.get(getClass().getResource("/history/hg-merge.bundle").toURI()).toString());
URL mergeURL = getClass().getResource("/history/hg-merge.bundle");
assertNotNull(mergeURL);
runHgCommand(repositoryRoot, "unbundle", Paths.get(mergeURL.toURI()).toString());
runHgCommand(repositoryRoot, "update");

RuntimeEnvironment env = RuntimeEnvironment.getInstance();
Expand Down Expand Up @@ -463,7 +469,7 @@ void testAnnotationPositive(Triple<String, List<String>, List<String>> triple) t
HistoryGuru.completeAnnotationWithHistory(annotation, history, hgRepo);
List<HistoryEntry> relevantEntries = history.getHistoryEntries().stream().
filter(e -> annotation.getRevisions().contains(e.getRevision())).
collect(Collectors.toList());
toList();
assertFalse(relevantEntries.isEmpty());
for (HistoryEntry entry : relevantEntries) {
assertTrue(annotation.getRevisions().contains(entry.getRevision()));
Expand All @@ -485,7 +491,9 @@ void testBuildTagListEmpty() throws Exception {
MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot);
assertNotNull(hgRepo);
hgRepo.buildTagList(new File(hgRepo.getDirectoryName()), CommandTimeoutType.INDEXER);
assertEquals(0, hgRepo.getTagList().size());
Set<TagEntry> tags = hgRepo.getTagList();
assertNotNull(tags);
assertEquals(0, tags.size());
IOUtils.removeRecursive(repositoryRootPath);
}

Expand All @@ -498,6 +506,7 @@ void testBuildTagListInitial() throws Exception {
assertNotNull(hgRepo);
hgRepo.buildTagList(new File(hgRepo.getDirectoryName()), CommandTimeoutType.INDEXER);
var tags = hgRepo.getTagList();
assertNotNull(tags);
assertEquals(1, tags.size());
Set<TagEntry> expectedTags = new TreeSet<>();
TagEntry tagEntry = new MercurialTagEntry(7, "start_of_novel");
Expand Down Expand Up @@ -525,8 +534,9 @@ void testBuildTagListOneMore() throws Exception {
runHgCommand(this.repositoryRoot, "clone", this.repositoryRoot.toString(), repositoryRootPath.toString());

// Branch the repo and add one changeset.
runHgCommand(repositoryRoot, "unbundle",
Paths.get(getClass().getResource("/history/hg-branch.bundle").toURI()).toString());
URL bundleURL = getClass().getResource("/history/hg-branch.bundle");
assertNotNull(bundleURL);
runHgCommand(repositoryRoot, "unbundle", Paths.get(bundleURL.toURI()).toString());

// Switch to the branch and add tag.
final String myBranch = "mybranch";
Expand Down
Loading