Skip to content

Commit 30bbc78

Browse files
committed
try with resources
1 parent ac6ced4 commit 30bbc78

File tree

8 files changed

+339
-305
lines changed

8 files changed

+339
-305
lines changed

src/test/java/pl/project13/jgit/DescribeCommandAbbrevIntegrationTest.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package pl.project13.jgit;
1919

2020
import com.google.common.base.Optional;
21+
import org.eclipse.jgit.api.Git;
2122
import org.eclipse.jgit.lib.Repository;
2223
import org.jetbrains.annotations.NotNull;
2324
import org.junit.Test;
@@ -64,20 +65,20 @@ public void shouldGiveTheCommitIdAndDirtyMarkerWhenNothingElseCanBeFound() throw
6465
.withGitRepoInParent(AvailableGitTestRepo.WITH_LIGHTWEIGHT_TAG_BEFORE_ANNOTATED_TAG)
6566
.create();
6667

67-
Repository repo = git().getRepository();
68+
try (final Git git = git(); final Repository repo = git.getRepository()) {
69+
// when
70+
DescribeResult res = DescribeCommand
71+
.on(repo)
72+
.withMojo(mojo)
73+
.abbrev(2) // 2 is enough to be unique in this small repo
74+
.call();
6875

69-
// when
70-
DescribeResult res = DescribeCommand
71-
.on(repo)
72-
.withMojo(mojo)
73-
.abbrev(2) // 2 is enough to be unique in this small repo
74-
.call();
76+
// then
77+
// git will notice this, and fallback to use 4 chars
78+
String smallestAbbrevGitWillUse = abbrev("b6a73ed747dd8dc98642d731ddbf09824efb9d48", 2);
7579

76-
// then
77-
// git will notice this, and fallback to use 4 chars
78-
String smallestAbbrevGitWillUse = abbrev("b6a73ed747dd8dc98642d731ddbf09824efb9d48", 2);
79-
80-
assertThat(res.prefixedCommitId()).isEqualTo("g" + smallestAbbrevGitWillUse);
80+
assertThat(res.prefixedCommitId()).isEqualTo("g" + smallestAbbrevGitWillUse);
81+
}
8182
}
8283

8384
@Test
@@ -89,20 +90,20 @@ public void onGitCommitIdsRepo_shouldNoticeThat2CharsIsTooLittleToBeUniqueAndUse
8990
.withGitRepoInParent(AvailableGitTestRepo.GIT_COMMIT_ID)
9091
.create();
9192

92-
Repository repo = git().getRepository();
93-
94-
// when
95-
DescribeResult res = DescribeCommand
96-
.on(repo)
97-
.withMojo(mojo)
98-
.abbrev(2) // way too small to be unique in git-commit-id's repo!
99-
.call();
93+
try (final Git git = git(); final Repository repo = git.getRepository()) {
94+
// when
95+
DescribeResult res = DescribeCommand
96+
.on(repo)
97+
.withMojo(mojo)
98+
.abbrev(2) // way too small to be unique in git-commit-id's repo!
99+
.call();
100100

101-
// then
102-
// git will notice this, and fallback to use 4 chars
103-
String smallestAbbrevGitWillUse = abbrev("7181832b7d9afdeb86c32cf51214abfca63625be", 4);
101+
// then
102+
// git will notice this, and fallback to use 4 chars
103+
String smallestAbbrevGitWillUse = abbrev("7181832b7d9afdeb86c32cf51214abfca63625be", 4);
104104

105-
assertThat(res.prefixedCommitId()).isEqualTo("g" + smallestAbbrevGitWillUse);
105+
assertThat(res.prefixedCommitId()).isEqualTo("g" + smallestAbbrevGitWillUse);
106+
}
106107
}
107108

108109
String abbrev(@NotNull String id, int n) {

0 commit comments

Comments
 (0)