Use StandardCharsets.UTF_8 in tests

Replace hard-coded "UTF-8" string with the constant.

Change-Id: Ie812add2df28e984090563ec7c6e2c0366616424
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2018-03-07 08:29:51 +09:00
parent 2c5b721161
commit 0b4e781f7c
9 changed files with 19 additions and 12 deletions

View File

@ -45,6 +45,8 @@
package org.eclipse.jgit.junit;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@ -250,7 +252,7 @@ public static File writeTrashFile(final Repository db,
public static void write(final File f, final String body)
throws IOException {
FileUtils.mkdirs(f.getParentFile(), true);
Writer w = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
Writer w = new OutputStreamWriter(new FileOutputStream(f), UTF_8);
try {
w.write(body);
} finally {
@ -270,7 +272,7 @@ public static void write(final File f, final String body)
*/
public static String read(final File file) throws IOException {
final byte[] body = IO.readFully(file);
return new String(body, 0, body.length, "UTF-8");
return new String(body, 0, body.length, UTF_8);
}
/**

View File

@ -45,6 +45,7 @@
package org.eclipse.jgit.junit;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
@ -351,7 +352,7 @@ public static String indexState(Repository repo, int includedOptions)
if (0 != (includedOptions & CONTENT)) {
sb.append(", content:"
+ new String(repo.open(entry.getObjectId(),
Constants.OBJ_BLOB).getCachedBytes(), "UTF-8"));
Constants.OBJ_BLOB).getCachedBytes(), UTF_8));
}
if (0 != (includedOptions & ASSUME_UNCHANGED))
sb.append(", assume-unchanged:"

View File

@ -46,6 +46,7 @@
package org.eclipse.jgit.junit;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import java.io.File;
@ -198,7 +199,7 @@ protected void deleteTrashFile(final String name) throws IOException {
protected static void checkFile(File f, final String checkData)
throws IOException {
try (Reader r = new InputStreamReader(new FileInputStream(f),
"UTF-8")) {
UTF_8)) {
if (checkData.length() > 0) {
char[] data = new char[checkData.length()];
assertEquals(data.length, r.read(data));

View File

@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.pgm;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@ -611,7 +612,7 @@ private Process spawnAssumingCommandPresent(String... cmdline) {
private BufferedReader readFromProcess(Process proc) throws Exception {
return new BufferedReader(
new InputStreamReader(proc.getInputStream(), "UTF-8"));
new InputStreamReader(proc.getInputStream(), UTF_8));
}
private void grepForEntry(String name, String mode, String... cmdline)
@ -749,7 +750,7 @@ private static String[] zipEntryContent(byte[] zipData, String path)
// found!
List<String> l = new ArrayList<>();
BufferedReader reader = new BufferedReader(
new InputStreamReader(in, "UTF-8"));
new InputStreamReader(in, UTF_8));
String line;
while ((line = reader.readLine()) != null)
l.add(line);

View File

@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.api;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import java.util.List;
@ -87,7 +88,7 @@ public void testAddAndRemoveNote() throws Exception {
git.notesAdd().setObjectId(commit2).setMessage("data").call();
Note note = git.notesShow().setObjectId(commit2).call();
String content = new String(db.open(note.getData()).getCachedBytes(),
"UTF-8");
UTF_8);
assertEquals(content, "data");
git.notesRemove().setObjectId(commit2).call();

View File

@ -606,7 +606,7 @@ private static void assertFileContentsEqual(File actFile, String string)
bos.write(buffer, 0, read);
read = fis.read(buffer);
}
String content = new String(bos.toByteArray(), "UTF-8");
String content = new String(bos.toByteArray(), UTF_8);
assertEquals(string, content);
}
}

View File

@ -410,7 +410,7 @@ private static void assertFileContentsEqual(File actFile, String string)
bos.write(buffer, 0, read);
read = fis.read(buffer);
}
String content = new String(bos.toByteArray(), "UTF-8");
String content = new String(bos.toByteArray(), UTF_8);
assertEquals(string, content);
}
}

View File

@ -2104,7 +2104,7 @@ private int countPicks() throws IOException {
int count = 0;
File todoFile = getTodoFile();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(todoFile), "UTF-8"))) {
new FileInputStream(todoFile), UTF_8))) {
String line = br.readLine();
while (line != null) {
int firstBlank = line.indexOf(' ');

View File

@ -43,6 +43,7 @@
package org.eclipse.jgit.dircache;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@ -235,7 +236,7 @@ private static File pathOf(final String name) {
private static Map<String, CGitIndexRecord> readLsFiles() throws Exception {
final LinkedHashMap<String, CGitIndexRecord> r = new LinkedHashMap<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(pathOf("gitgit.lsfiles")), "UTF-8"))) {
new FileInputStream(pathOf("gitgit.lsfiles")), UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
final CGitIndexRecord cr = new CGitIndexRecord(line);
@ -248,7 +249,7 @@ private static Map<String, CGitIndexRecord> readLsFiles() throws Exception {
private static Map<String, CGitLsTreeRecord> readLsTree() throws Exception {
final LinkedHashMap<String, CGitLsTreeRecord> r = new LinkedHashMap<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(pathOf("gitgit.lstree")), "UTF-8"))) {
new FileInputStream(pathOf("gitgit.lstree")), UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
final CGitLsTreeRecord cr = new CGitLsTreeRecord(line);