From 043b1f9cd36a3c83f3c9ef515c88eddd2c3845dd Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Mon, 1 Dec 2008 00:40:34 +0100 Subject: [PATCH] Close files opened by unit testing framework Signed-off-by: Robin Rosenberg Signed-off-by: Shawn O. Pearce --- .../tst/org/spearce/jgit/lib/RepositoryTestCase.java | 12 ++++++++---- .../tst/org/spearce/jgit/lib/T0007_Index.java | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java index aaa35926..376a76ef 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java @@ -165,10 +165,14 @@ public abstract class RepositoryTestCase extends TestCase { protected static void checkFile(File f, final String checkData) throws IOException { Reader r = new InputStreamReader(new FileInputStream(f), "ISO-8859-1"); - char[] data = new char[(int) f.length()]; - if (f.length() != r.read(data)) - throw new IOException("Internal error reading file data from "+f); - assertEquals(checkData, new String(data)); + try { + char[] data = new char[(int) f.length()]; + if (f.length() != r.read(data)) + throw new IOException("Internal error reading file data from "+f); + assertEquals(checkData, new String(data)); + } finally { + r.close(); + } } protected Repository db; diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0007_Index.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0007_Index.java index 69f3a48b..499812eb 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0007_Index.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0007_Index.java @@ -424,9 +424,13 @@ public class T0007_Index extends RepositoryTestCase { private String content(File f) throws IOException { byte[] buf = new byte[(int) f.length()]; FileInputStream is = new FileInputStream(f); - int read = is.read(buf); - assertEquals(f.length(), read); - return new String(buf, 0); + try { + int read = is.read(buf); + assertEquals(f.length(), read); + return new String(buf, 0); + } finally { + is.close(); + } } private void delete(File f) throws IOException { -- 2.11.4.GIT