FileRepositoryBuilderTest: Don't explicitly close BufferedWriter in try-with-resource
The BufferedWriter is opened in a try-with-resource and thus will be automatically closed. Presumably the close was added to make sure it is closed before the subsequent test statements are executed. Instead of explicitly closing it, let the try-with-resource automatically close it, and move the subsequent statements out of the try-block. Change-Id: If5fada2f580ef9cbaad3a0b9216b5200b917781a Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
fa61fd6f61
commit
b2ee02f53b
|
@ -124,18 +124,18 @@ public void absoluteGitDirRef() throws Exception {
|
|||
File dotGit = new File(dir, Constants.DOT_GIT);
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(dotGit.toPath(),
|
||||
UTF_8)) {
|
||||
writer.append("gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
|
||||
writer.append("gitdir: " + repo1.getDirectory().getAbsolutePath());
|
||||
}
|
||||
FileRepositoryBuilder builder = new FileRepositoryBuilder();
|
||||
|
||||
builder.setWorkTree(dir);
|
||||
builder.setMustExist(true);
|
||||
Repository repo2 = builder.build();
|
||||
|
||||
assertEquals(repo1.getDirectory().getAbsolutePath(), repo2
|
||||
.getDirectory().getAbsolutePath());
|
||||
assertEquals(repo1.getDirectory().getAbsolutePath(),
|
||||
repo2.getDirectory().getAbsolutePath());
|
||||
assertEquals(dir, repo2.getWorkTree());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void relativeGitDirRef() throws Exception {
|
||||
|
@ -145,8 +145,8 @@ public void relativeGitDirRef() throws Exception {
|
|||
File dotGit = new File(dir, Constants.DOT_GIT);
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(dotGit.toPath(),
|
||||
UTF_8)) {
|
||||
writer.append("gitdir: ../" + Constants.DOT_GIT).close();
|
||||
|
||||
writer.append("gitdir: ../" + Constants.DOT_GIT);
|
||||
}
|
||||
FileRepositoryBuilder builder = new FileRepositoryBuilder();
|
||||
builder.setWorkTree(dir);
|
||||
builder.setMustExist(true);
|
||||
|
@ -154,11 +154,10 @@ public void relativeGitDirRef() throws Exception {
|
|||
|
||||
// The tmp directory may be a symlink so the actual path
|
||||
// may not
|
||||
assertEquals(repo1.getDirectory().getCanonicalPath(), repo2
|
||||
.getDirectory().getCanonicalPath());
|
||||
assertEquals(repo1.getDirectory().getCanonicalPath(),
|
||||
repo2.getDirectory().getCanonicalPath());
|
||||
assertEquals(dir, repo2.getWorkTree());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scanWithGitDirRef() throws Exception {
|
||||
|
@ -168,20 +167,20 @@ public void scanWithGitDirRef() throws Exception {
|
|||
try (BufferedWriter writer = Files.newBufferedWriter(dotGit.toPath(),
|
||||
UTF_8)) {
|
||||
writer.append(
|
||||
"gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
|
||||
"gitdir: " + repo1.getDirectory().getAbsolutePath());
|
||||
}
|
||||
FileRepositoryBuilder builder = new FileRepositoryBuilder();
|
||||
|
||||
builder.setWorkTree(dir);
|
||||
builder.findGitDir(dir);
|
||||
assertEquals(repo1.getDirectory().getAbsolutePath(), builder
|
||||
.getGitDir().getAbsolutePath());
|
||||
assertEquals(repo1.getDirectory().getAbsolutePath(),
|
||||
builder.getGitDir().getAbsolutePath());
|
||||
builder.setMustExist(true);
|
||||
Repository repo2 = builder.build();
|
||||
|
||||
// The tmp directory may be a symlink
|
||||
assertEquals(repo1.getDirectory().getCanonicalPath(), repo2
|
||||
.getDirectory().getCanonicalPath());
|
||||
assertEquals(repo1.getDirectory().getCanonicalPath(),
|
||||
repo2.getDirectory().getCanonicalPath());
|
||||
assertEquals(dir, repo2.getWorkTree());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue