]> source.dussan.org Git - jgit.git/commitdiff
CommitAndLogCommandTest: Open PrintWriter in try-with-resource 26/118726/1
authorDavid Pursehouse <david.pursehouse@gmail.com>
Mon, 5 Mar 2018 23:22:48 +0000 (08:22 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Mon, 5 Mar 2018 23:22:48 +0000 (08:22 +0900)
Change-Id: I0c7f07e27d1881d8856dac008110fcaa85c98fbb
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.java

index 1d5c6742c788a8db0e61df48ba9fb102f7da239e..ca0630ea357c5e329445645e57fd7f338351f20b 100644 (file)
@@ -120,9 +120,9 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
                        // create first file
                        File file = new File(db.getWorkTree(), "a.txt");
                        FileUtils.createNewFile(file);
-                       PrintWriter writer = new PrintWriter(file);
-                       writer.print("content1");
-                       writer.close();
+                       try (PrintWriter writer = new PrintWriter(file)) {
+                               writer.print("content1");
+                       }
 
                        // First commit - a.txt file
                        git.add().addFilepattern("a.txt").call();
@@ -131,9 +131,9 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
                        // create second file
                        file = new File(db.getWorkTree(), "b.txt");
                        FileUtils.createNewFile(file);
-                       writer = new PrintWriter(file);
-                       writer.print("content2");
-                       writer.close();
+                       try (PrintWriter writer = new PrintWriter(file)) {
+                               writer.print("content2");
+                       }
 
                        // Second commit - b.txt file
                        git.add().addFilepattern("b.txt").call();
@@ -231,9 +231,9 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
                        JGitInternalException, GitAPIException {
                File file = new File(db.getWorkTree(), "a.txt");
                FileUtils.createNewFile(file);
-               PrintWriter writer = new PrintWriter(file);
-               writer.print("content");
-               writer.close();
+               try (PrintWriter writer = new PrintWriter(file)) {
+                       writer.print("content");
+               }
 
                try (Git git = new Git(db)) {
                        git.add().addFilepattern("a.txt").call();
@@ -242,9 +242,9 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
                        assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
                                        tw.getObjectId(0).getName());
 
-                       writer = new PrintWriter(file);
-                       writer.print("content2");
-                       writer.close();
+                       try (PrintWriter writer = new PrintWriter(file)) {
+                               writer.print("content2");
+                       }
                        commit = git.commit().setMessage("second commit").call();
                        tw = TreeWalk.forPath(db, "a.txt", commit.getTree());
                        assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
@@ -265,9 +265,9 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
                        // create file
                        File file = new File(db.getWorkTree(), "a.txt");
                        FileUtils.createNewFile(file);
-                       PrintWriter writer = new PrintWriter(file);
-                       writer.print("content1");
-                       writer.close();
+                       try (PrintWriter writer = new PrintWriter(file)) {
+                               writer.print("content1");
+                       }
 
                        // First commit - a.txt file
                        git.add().addFilepattern("a.txt").call();