Browse Source

Explicitly specify charset in constructor of String

Change-Id: Ie9a9f917503019e7fa51ccbc11a5a3518b74434b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.2
David Pursehouse 6 years ago
parent
commit
a7d3fa3064
  1. 3
      org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java
  2. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
  3. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java
  4. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
  5. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogWriterTest.java
  6. 44
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java

3
org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java

@ -42,6 +42,7 @@
*/ */
package org.eclipse.jgit.lfs.server.fs; package org.eclipse.jgit.lfs.server.fs;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
@ -149,7 +150,7 @@ public class PushTest extends LfsServerTest {
new String(IO new String(IO
.readWholeStream(is, .readWholeStream(is,
(int) ldr.getSize()) (int) ldr.getSize())
.array())); .array(), UTF_8));
} }
} }

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java

@ -42,6 +42,7 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -231,7 +232,9 @@ public class ArchiveCommandTest extends RepositoryTestCase {
@Override @Override
public void putEntry(MockOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) { public void putEntry(MockOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) {
String content = mode != FileMode.TREE ? new String(loader.getBytes()) : null; String content = mode != FileMode.TREE
? new String(loader.getBytes(), UTF_8)
: null;
entries.put(path, content); entries.put(path, content);
} }

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java

@ -43,6 +43,7 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -1298,7 +1299,7 @@ public class CommitOnlyTest extends RepositoryTestCase {
final TreeWalk tw = TreeWalk.forPath(repo, path, final TreeWalk tw = TreeWalk.forPath(repo, path,
rw.parseTree(headId)); rw.parseTree(headId));
return new String(tw.getObjectReader().open(tw.getObjectId(0)) return new String(tw.getObjectReader().open(tw.getObjectId(0))
.getBytes()); .getBytes(), UTF_8);
} }
} catch (Exception e) { } catch (Exception e) {
return ""; return "";

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java

@ -38,6 +38,7 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -722,10 +723,10 @@ public class EolRepositoryTest extends RepositoryTestCase {
} }
e.attrs = e.attrs.trim(); e.attrs = e.attrs.trim();
e.file = new String( e.file = new String(
IO.readFully(new File(db.getWorkTree(), pathName))); IO.readFully(new File(db.getWorkTree(), pathName)), UTF_8);
DirCacheEntry dce = dirCache.getEntry(pathName); DirCacheEntry dce = dirCache.getEntry(pathName);
ObjectLoader open = walk.getObjectReader().open(dce.getObjectId()); ObjectLoader open = walk.getObjectReader().open(dce.getObjectId());
e.index = new String(open.getBytes()); e.index = new String(open.getBytes(), UTF_8);
e.indexContentLength = dce.getLength(); e.indexContentLength = dce.getLength();
} }

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogWriterTest.java

@ -42,6 +42,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.jgit.internal.storage.file; package org.eclipse.jgit.internal.storage.file;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
@ -75,7 +76,7 @@ public class ReflogWriterTest extends SampleDataRepositoryTestCase {
byte[] buffer = new byte[oneLine.getBytes().length]; byte[] buffer = new byte[oneLine.getBytes().length];
readReflog(buffer); readReflog(buffer);
assertEquals(oneLine, new String(buffer)); assertEquals(oneLine, new String(buffer, UTF_8));
} }
private void readReflog(byte[] buffer) private void readReflog(byte[] buffer)

44
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java

@ -43,6 +43,7 @@
package org.eclipse.jgit.util; package org.eclipse.jgit.util;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -77,8 +78,8 @@ public class RunExternalScriptTest {
new ProcessBuilder("sh", script.getPath()), out, err, new ProcessBuilder("sh", script.getPath()), out, err,
new ByteArrayInputStream(inputStr.getBytes())); new ByteArrayInputStream(inputStr.getBytes()));
assertEquals(0, rc); assertEquals(0, rc);
assertEquals(inputStr, new String(out.toByteArray())); assertEquals(inputStr, new String(out.toByteArray(), UTF_8));
assertEquals("", new String(err.toByteArray())); assertEquals("", new String(err.toByteArray(), UTF_8));
} }
@Test @Test
@ -88,8 +89,8 @@ public class RunExternalScriptTest {
new ProcessBuilder("sh", script.getPath()), out, err, new ProcessBuilder("sh", script.getPath()), out, err,
(InputStream) null); (InputStream) null);
assertEquals(0, rc); assertEquals(0, rc);
assertEquals("", new String(out.toByteArray())); assertEquals("", new String(out.toByteArray(), UTF_8));
assertEquals("", new String(err.toByteArray())); assertEquals("", new String(err.toByteArray(), UTF_8));
} }
@Test @Test
@ -99,8 +100,8 @@ public class RunExternalScriptTest {
new ProcessBuilder("sh", new ProcessBuilder("sh",
script.getPath(), "a", "b", "c"), out, err, (InputStream) null); script.getPath(), "a", "b", "c"), out, err, (InputStream) null);
assertEquals(0, rc); assertEquals(0, rc);
assertEquals("3,a,b,c,,,\n", new String(out.toByteArray())); assertEquals("3,a,b,c,,,\n", new String(out.toByteArray(), UTF_8));
assertEquals("", new String(err.toByteArray())); assertEquals("", new String(err.toByteArray(), UTF_8));
} }
@Test @Test
@ -110,8 +111,8 @@ public class RunExternalScriptTest {
new ProcessBuilder("sh", script.getPath(), "a", "b", "c"), new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
out, err, (InputStream) null); out, err, (InputStream) null);
assertEquals(3, rc); assertEquals(3, rc);
assertEquals("", new String(out.toByteArray())); assertEquals("", new String(out.toByteArray(), UTF_8));
assertEquals("", new String(err.toByteArray())); assertEquals("", new String(err.toByteArray(), UTF_8));
} }
@Test @Test
@ -121,8 +122,8 @@ public class RunExternalScriptTest {
new ProcessBuilder("sh", script.getPath()), null, err, new ProcessBuilder("sh", script.getPath()), null, err,
(InputStream) null); (InputStream) null);
assertEquals(0, rc); assertEquals(0, rc);
assertEquals("", new String(out.toByteArray())); assertEquals("", new String(out.toByteArray(), UTF_8));
assertEquals("", new String(err.toByteArray())); assertEquals("", new String(err.toByteArray(), UTF_8));
} }
@Test @Test
@ -132,8 +133,8 @@ public class RunExternalScriptTest {
new ProcessBuilder("sh", script.getPath()), null, err, new ProcessBuilder("sh", script.getPath()), null, err,
(InputStream) null); (InputStream) null);
assertEquals(0, rc); assertEquals(0, rc);
assertEquals("", new String(out.toByteArray())); assertEquals("", new String(out.toByteArray(), UTF_8));
assertEquals("hi" + LF, new String(err.toByteArray())); assertEquals("hi" + LF, new String(err.toByteArray(), UTF_8));
} }
@Test @Test
@ -144,8 +145,8 @@ public class RunExternalScriptTest {
new ProcessBuilder("sh", script.getPath(), "a", "b", "c"), new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
out, err, new ByteArrayInputStream(inputStr.getBytes())); out, err, new ByteArrayInputStream(inputStr.getBytes()));
assertEquals(5, rc); assertEquals(5, rc);
assertEquals(inputStr, new String(out.toByteArray())); assertEquals(inputStr, new String(out.toByteArray(), UTF_8));
assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray())); assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray(), UTF_8));
} }
@Test(expected = IOException.class) @Test(expected = IOException.class)
@ -174,8 +175,9 @@ public class RunExternalScriptTest {
ExecutionResult res = FS.DETECTED.execute(pb, ExecutionResult res = FS.DETECTED.execute(pb,
new ByteArrayInputStream(inputStr.getBytes())); new ByteArrayInputStream(inputStr.getBytes()));
assertEquals(0, res.getRc()); assertEquals(0, res.getRc());
assertEquals(inputStr, new String(res.getStdout().toByteArray())); assertEquals(inputStr,
assertEquals("", new String(res.getStderr().toByteArray())); new String(res.getStdout().toByteArray(), UTF_8));
assertEquals("", new String(res.getStderr().toByteArray(), UTF_8));
} }
@Test @Test
@ -184,8 +186,9 @@ public class RunExternalScriptTest {
ProcessBuilder pb = new ProcessBuilder("sh", script.getPath()); ProcessBuilder pb = new ProcessBuilder("sh", script.getPath());
ExecutionResult res = FS.DETECTED.execute(pb, null); ExecutionResult res = FS.DETECTED.execute(pb, null);
assertEquals(0, res.getRc()); assertEquals(0, res.getRc());
assertEquals("", new String(res.getStdout().toByteArray())); assertEquals("", new String(res.getStdout().toByteArray(), UTF_8));
assertEquals("hi" + LF, new String(res.getStderr().toByteArray())); assertEquals("hi" + LF,
new String(res.getStderr().toByteArray(), UTF_8));
} }
@Test @Test
@ -199,9 +202,10 @@ public class RunExternalScriptTest {
ExecutionResult res = FS.DETECTED.execute(pb, ExecutionResult res = FS.DETECTED.execute(pb,
new ByteArrayInputStream(inputStr.getBytes())); new ByteArrayInputStream(inputStr.getBytes()));
assertEquals(5, res.getRc()); assertEquals(5, res.getRc());
assertEquals(inputStr, new String(res.getStdout().toByteArray())); assertEquals(inputStr,
new String(res.getStdout().toByteArray(), UTF_8));
assertEquals("3,a,b,c,,," + LF, assertEquals("3,a,b,c,,," + LF,
new String(res.getStderr().toByteArray())); new String(res.getStderr().toByteArray(), UTF_8));
} }
private File writeTempFile(String body) throws IOException { private File writeTempFile(String body) throws IOException {

Loading…
Cancel
Save