Browse Source
* master: Update Orbit to S20200219023850 for 2012-03 M3 Revert "Prepend hostname to subsection used to store file timestamp resolution" Remove use of org.bouncycastle.util.encoders.Hex Remove use of org.bouncycastle.util.io.TeeOutputStream Make the IMatcher public API SimilarityRenameDetector: Fix inconsistent indentation Use indexOf(char) and lastIndexOf(char) rather than String versions Reorder modifiers to follow Java Language Specification GitmoduleEntry: Remove redundant import of class from same package Remove redundant "static" qualifier from enum declarations RevWalk: stop mixing lines of history in topo sort Upgrade plexus-compiler-{eclipse|javac|javac-errorprone} to 2.8.6 Upgrade maven-shade-plugin to 3.2.2 Removed unused imports Documentation/technical/reftable: improve repo layout Change-Id: I558eff2abda44342fbaf1662fda07e2bcc6d4ee3 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>stable-5.7
Matthias Sohn
5 years ago
110 changed files with 701 additions and 281 deletions
@ -0,0 +1,49 @@
|
||||
/* |
||||
* Copyright (C) 2010, Google Inc. |
||||
* Copyright (C) 2020 Michael Dardis and others |
||||
* |
||||
* This program and the accompanying materials are made available under the |
||||
* terms of the Eclipse Distribution License v. 1.0 which is available at |
||||
* https://www.eclipse.org/org/documents/edl-v10.php.
|
||||
* |
||||
* SPDX-License-Identifier: BSD-3-Clause |
||||
*/ |
||||
|
||||
package org.eclipse.jgit.util; |
||||
|
||||
import static org.eclipse.jgit.util.Hex.decode; |
||||
import static org.eclipse.jgit.util.Hex.toHexString; |
||||
import static org.junit.Assert.assertEquals; |
||||
|
||||
import org.eclipse.jgit.junit.JGitTestUtil; |
||||
import org.eclipse.jgit.lib.Constants; |
||||
import org.junit.Test; |
||||
|
||||
public class HexTest { |
||||
@Test |
||||
public void testEncode() { |
||||
assertEquals("68690a", toHexString(b("hi\n"))); |
||||
assertEquals("0001020d0a0971", toHexString(b("\0\1\2\r\n\tq"))); |
||||
} |
||||
|
||||
@Test |
||||
public void testDecode() { |
||||
JGitTestUtil.assertEquals(b("hi\n"), decode("68690a")); |
||||
JGitTestUtil.assertEquals(b("\0\1\2\r\n\tq"), decode("0001020d0a0971")); |
||||
JGitTestUtil.assertEquals(b("\u000EB"), decode("0E42")); |
||||
} |
||||
|
||||
@Test |
||||
public void testEncodeMatchesDecode() { |
||||
String[] testStrings = { "", "cow", "a", "a secret string", |
||||
"\0\1\2\r\n\t" }; |
||||
for (String e : testStrings) { |
||||
JGitTestUtil.assertEquals(b(e), decode(toHexString(b(e)))); |
||||
} |
||||
} |
||||
|
||||
private static byte[] b(String str) { |
||||
return Constants.encode(str); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,81 @@
|
||||
/* |
||||
* Copyright (C) 2020, Michael Dardis. and others |
||||
* |
||||
* This program and the accompanying materials are made available under the |
||||
* terms of the Eclipse Distribution License v. 1.0 which is available at |
||||
* https://www.eclipse.org/org/documents/edl-v10.php.
|
||||
* |
||||
* SPDX-License-Identifier: BSD-3-Clause |
||||
*/ |
||||
package org.eclipse.jgit.util.io; |
||||
|
||||
import static org.junit.Assert.assertArrayEquals; |
||||
import static org.junit.Assert.assertFalse; |
||||
import static org.junit.Assert.assertTrue; |
||||
|
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.IOException; |
||||
|
||||
import org.eclipse.jgit.lib.Constants; |
||||
import org.junit.Test; |
||||
|
||||
public class TeeOutputStreamTest { |
||||
|
||||
@Test |
||||
public void test() throws IOException { |
||||
byte[] data = Constants.encode("Hello World"); |
||||
|
||||
TestOutput first = new TestOutput(); |
||||
TestOutput second = new TestOutput(); |
||||
try (TeeOutputStream tee = new TeeOutputStream(first, second)) { |
||||
tee.write(data); |
||||
assertArrayEquals("Stream output must match", first.toByteArray(), |
||||
second.toByteArray()); |
||||
|
||||
tee.write(1); |
||||
assertArrayEquals("Stream output must match", first.toByteArray(), |
||||
second.toByteArray()); |
||||
|
||||
tee.write(data, 1, 4); // Test partial write methods
|
||||
assertArrayEquals("Stream output must match", first.toByteArray(), |
||||
second.toByteArray()); |
||||
} |
||||
assertTrue("First stream should be closed", first.closed); |
||||
assertTrue("Second stream should be closed", second.closed); |
||||
} |
||||
|
||||
@Test |
||||
public void testCloseException() { |
||||
TestOutput first = new TestOutput() { |
||||
@Override |
||||
public void close() throws IOException { |
||||
throw new IOException(); |
||||
} |
||||
|
||||
}; |
||||
TestOutput second = new TestOutput(); |
||||
|
||||
@SuppressWarnings("resource") |
||||
TeeOutputStream tee = new TeeOutputStream(first, second); |
||||
try { |
||||
tee.close(); |
||||
} catch (IOException ex) { |
||||
// Expected from first closed
|
||||
} |
||||
assertFalse("First stream should not be closed", first.closed); |
||||
assertTrue("Second stream should still be closed if first close failed", |
||||
second.closed); |
||||
} |
||||
|
||||
private static class TestOutput extends ByteArrayOutputStream { |
||||
|
||||
private boolean closed; |
||||
|
||||
@Override |
||||
public void close() throws IOException { |
||||
closed = true; |
||||
super.close(); |
||||
} |
||||
} |
||||
|
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue