aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Borowitz <dborowitz@google.com>2015-07-15 18:04:10 -0700
committerDave Borowitz <dborowitz@google.com>2015-07-15 18:09:42 -0700
commit74a57f37441eb5faa1ad335b095fcb43bc924c1a (patch)
treed41ceeea187730e5844adba3960bf5fd92e74a36
parentc7c5fe718d6b1dee3f8537a97bc38b57542e9e53 (diff)
downloadjgit-74a57f37441eb5faa1ad335b095fcb43bc924c1a.tar.gz
jgit-74a57f37441eb5faa1ad335b095fcb43bc924c1a.zip
PushCertificateParser: Add fromString method
Change-Id: I74c3f65a9ff297f708d996a4c138456a31a466b8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateParserTest.java13
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateParser.java18
2 files changed, 28 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateParserTest.java
index 3a4b00d876..824766e165 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateParserTest.java
@@ -55,6 +55,7 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.io.StringReader;
import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
@@ -280,9 +281,7 @@ public class PushCertificateParserTest {
@Test
public void testParseReader() throws Exception {
- Reader reader = new InputStreamReader(
- new ByteArrayInputStream(
- Constants.encode(concatPacketLines(INPUT, 0, 18))));
+ Reader reader = new StringReader(concatPacketLines(INPUT, 0, 18));
PushCertificate streamCert = PushCertificateParser.fromReader(reader);
PacketLineIn pckIn = newPacketLineIn(INPUT);
@@ -321,6 +320,14 @@ public class PushCertificateParserTest {
}
@Test
+ public void testParseString() throws Exception {
+ String str = concatPacketLines(INPUT, 0, 18);
+ assertEquals(
+ PushCertificateParser.fromReader(new StringReader(str)),
+ PushCertificateParser.fromString(str));
+ }
+
+ @Test
public void testParseMultipleFromStream() throws Exception {
String input = concatPacketLines(INPUT, 0, 17);
assertFalse(input.contains(PushCertificateParser.END_CERT));
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateParser.java
index 7b827b9535..5174f85627 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateParser.java
@@ -156,6 +156,24 @@ public class PushCertificateParser {
return new PushCertificateParser().parse(r);
}
+ /**
+ * Parse a push certificate from a string.
+ *
+ * @see #fromReader(Reader)
+ * @param str
+ * input string.
+ * @return the parsed certificate.
+ * @throws PackProtocolException
+ * if the certificate is malformed.
+ * @throws IOException
+ * if there was an error reading from the input.
+ * @since 4.1
+ */
+ public static PushCertificate fromString(String str)
+ throws PackProtocolException, IOException {
+ return fromReader(new java.io.StringReader(str));
+ }
+
private boolean received;
private String version;
private PushCertificateIdent pusher;