diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-12-13 10:57:26 -0800 |
---|---|---|
committer | Chris Aniszczyk <caniszczyk@gmail.com> | 2010-12-13 16:03:29 -0600 |
commit | f5434c2a86fcf55c06cac3b750483e289a53890d (patch) | |
tree | c43913709301e054588e3ea7d8fc4dafadc53120 | |
parent | 5ac5871d16642bbb4b617adaded37f99dcd2fff8 (diff) | |
download | jgit-f5434c2a86fcf55c06cac3b750483e289a53890d.tar.gz jgit-f5434c2a86fcf55c06cac3b750483e289a53890d.zip |
Remove remaining uses of FileWriter
FileWriter uses the platform default encoding, which might not
be UTF-8. JGit prefers UTF-8 everywhere for string encodings,
so make the unit tests more predictable by ensuring use of UTF-8.
Change-Id: I75bb9f962ee230b73ca3a942bffd7a8a28674ba5
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java | 11 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java | 15 |
2 files changed, 6 insertions, 20 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java index 3d7f77972e..c1e24617e0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java @@ -43,7 +43,6 @@ package org.eclipse.jgit.api; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; @@ -150,13 +149,9 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { db.updateRef(Constants.HEAD).link("refs/heads/side"); RevCommit firstSide = git.commit().setMessage("first side commit").setAuthor(author).call(); - FileWriter wr = new FileWriter(new File(db.getDirectory(), - Constants.MERGE_HEAD)); - wr.write(ObjectId.toString(db.resolve("refs/heads/master"))); - wr.close(); - wr = new FileWriter(new File(db.getDirectory(), Constants.MERGE_MSG)); - wr.write("merging"); - wr.close(); + write(new File(db.getDirectory(), Constants.MERGE_HEAD), ObjectId + .toString(db.resolve("refs/heads/master"))); + write(new File(db.getDirectory(), Constants.MERGE_MSG), "merging"); RevCommit commit = git.commit().call(); RevCommit[] parents = commit.getParents(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java index 4b4ee06f3c..2057020cdf 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java @@ -49,9 +49,7 @@ package org.eclipse.jgit.storage.file; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; -import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import org.eclipse.jgit.JGitText; @@ -313,15 +311,13 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { ConfigInvalidException { final File cfg = new File(db.getDirectory(), "config"); final FileBasedConfig c = new FileBasedConfig(cfg, db.getFS()); - final FileWriter pw = new FileWriter(cfg); final String configStr = " [core];comment\n\tfilemode = yes\n" + "[user]\n" + " email = A U Thor <thor@example.com> # Just an example...\n" + " name = \"A Thor \\\\ \\\"\\t \"\n" + " defaultCheckInComment = a many line\\n\\\ncomment\\n\\\n" + " to test\n"; - pw.write(configStr); - pw.close(); + write(cfg, configStr); c.load(); assertEquals("yes", c.getString("core", null, "filemode")); assertEquals("A U Thor <thor@example.com>", c @@ -346,12 +342,10 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { public void test008_FailOnWrongVersion() throws IOException { final File cfg = new File(db.getDirectory(), "config"); - final FileWriter pw = new FileWriter(cfg); final String badvers = "ihopethisisneveraversion"; final String configStr = "[core]\n" + "\trepositoryFormatVersion=" + badvers + "\n"; - pw.write(configStr); - pw.close(); + write(cfg, configStr); try { new FileRepository(db.getDirectory()); @@ -616,11 +610,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { } public void test027_UnpackedRefHigherPriorityThanPacked() throws IOException { - PrintWriter writer = new PrintWriter(new FileWriter(new File(db.getDirectory(), "refs/heads/a"))); String unpackedId = "7f822839a2fe9760f386cbbbcb3f92c5fe81def7"; - writer.print(unpackedId); - writer.print('\n'); - writer.close(); + write(new File(db.getDirectory(), "refs/heads/a"), unpackedId + "\n"); ObjectId resolved = db.resolve("refs/heads/a"); assertEquals(unpackedId, resolved.name()); |