]> source.dussan.org Git - jgit.git/commitdiff
HugeFileTest: Make Git a class member and open in try-with-resource 98/66598/2
authorDavid Pursehouse <david.pursehouse@sonymobile.com>
Mon, 15 Feb 2016 08:41:05 +0000 (17:41 +0900)
committerDavid Pursehouse <david.pursehouse@sonymobile.com>
Mon, 15 Feb 2016 09:04:07 +0000 (18:04 +0900)
There's only one test method in this module and it's quite long, so
rather than using a try-with-resource and having to indent a huge
block of existing code, make the Git a member variable that gets
initialised and closed in @Before and @After annotated methods.

The methods are named 'before' and 'after' rather than the conventional
'setUp' and 'tearDown' so as not to conflict with the names of the
existing methods in LocalDiskRepositoryTestCase.

Change-Id: I5a4a9b59f244c450dbcae9fdde7d9e0f0cd24e6f
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/HugeFileTest.java

index 5449d02a0846e3bf526c862d14666db9d7e8ea9a..4208f4d8e36012e81f7900cdc42155671c417a84 100644 (file)
@@ -51,6 +51,8 @@ import java.util.Collection;
 
 import org.eclipse.jgit.api.ResetCommand.ResetType;
 import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -60,12 +62,26 @@ public class HugeFileTest extends RepositoryTestCase {
 
        private long lastt = t;
 
+       private Git git;
+
        private void measure(String name) {
                long c = System.currentTimeMillis();
                System.out.println(name + ", dt=" + (c - lastt) / 1000.0 + "s");
                lastt = c;
        }
 
+       @Before
+       public void before() {
+               git = new Git(db);
+       }
+
+       @After
+       public void after() {
+               if (git != null) {
+                       git.close();
+               }
+       }
+
        @Ignore("Test takes way too long (~10 minutes) to be part of the standard suite")
        @Test
        public void testAddHugeFile() throws Exception {
@@ -75,7 +91,6 @@ public class HugeFileTest extends RepositoryTestCase {
                rf.setLength(4429185024L);
                rf.close();
                measure("Created file");
-               Git git = new Git(db);
 
                git.add().addFilepattern("a.txt").call();
                measure("Added file");