git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 7/8] Close files opened by unit testing framework

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Nov 30, 2008, 23:40 UTC
Message-ID
<1228088435-23722-8-git-send-email-robin.rosenberg@dewire.com>
In-Reply-To
<1228088435-23722-7-git-send-email-robin.rosenberg@dewire.com>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../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 aaa3592..376a76e 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 @@ protected File writeTrashFile(final String name, final String data)
 	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 69f3a48..499812e 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 void test031_executeBit_coreModeFalse() throws IllegalArgumentException, 
 	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 {
-- 
1.6.0.3.640.g6331a
Previous: Robin RosenbergNext: Robin Rosenberg
Message 13 of 15 in “RepositoryTestCase cleanups”
  1. 0/4 RepositoryTestCase cleanupsRobin Rosenberg, Nov 27, 2008
  2. Shawn O. PearceNov 27, 2008
  3. Robin RosenbergNov 29, 2008
  4. Johannes SchindelinDec 1, 2008
  5. Robin RosenbergNov 30, 2008
  6. 0/8 Unit test cleanupsRobin Rosenberg, Nov 30, 2008
  7. 1/8 Drop unneeded code in unit testsRobin Rosenberg, Nov 30, 2008
  8. 2/8 Cleanup malformed test casesRobin Rosenberg, Nov 30, 2008
  9. 3/8 Turn off memory mapping in JGit unit tests by defaultRobin Rosenberg, Nov 30, 2008
  10. 4/8 Add a counter to make sure the test repo name is uniqueRobin Rosenberg, Nov 30, 2008
  11. 5/8 Make the cleanup less verbose when it fails to delete temporary stuff.Robin Rosenberg, Nov 30, 2008
  12. 6/8 Cleanup after each test.Robin Rosenberg, Nov 30, 2008
  13. 7/8 Close files opened by unit testing frameworkRobin Rosenberg, Nov 30, 2008
  14. 8/8 Hard failure on unit test cleanups if they fail.Robin Rosenberg, Nov 30, 2008
  15. Shawn O. PearceDec 2, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.