diff options
author | Jonathan Nieder <jrn@google.com> | 2015-06-30 14:42:39 -0700 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2015-07-06 12:41:06 -0700 |
commit | 761f070866f224b4c9f4abed6e1231518677e848 (patch) | |
tree | 8c3754b300d1f1d1edb04a64285feffa5905fb9e /org.eclipse.jgit.test/tst/org/eclipse/jgit/lib | |
parent | 0c7ad12c767d34ab90505c405ad6f0b70ee670ec (diff) | |
download | jgit-761f070866f224b4c9f4abed6e1231518677e848.tar.gz jgit-761f070866f224b4c9f4abed6e1231518677e848.zip |
Throw InvalidObjectIdException from ObjectId.fromString("tooshort")
ObjectId.fromString already throws InvalidObjectIdException for most
malformed object ids, but for this kind it previously threw
IllegalArgumentException. Since InvalidObjectIdException is a child of
IllegalArgumentException, callers that catch IllegalArgumentException
will continue to work.
Change-Id: I24e1422d51607c86a1cb816a495703279e461f01
Signed-off-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/lib')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java index abf57d6cd3..2198b87aa5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java @@ -49,6 +49,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import org.eclipse.jgit.errors.InvalidObjectIdException; + import org.junit.Test; public class ObjectIdTest { @@ -124,6 +126,21 @@ public class ObjectIdTest { assertEquals(x.toLowerCase(), oid.name()); } + @Test(expected = InvalidObjectIdException.class) + public void testFromString_short() { + ObjectId.fromString("cafe1234"); + } + + @Test(expected = InvalidObjectIdException.class) + public void testFromString_nonHex() { + ObjectId.fromString("0123456789abcdefghij0123456789abcdefghij"); + } + + @Test(expected = InvalidObjectIdException.class) + public void testFromString_shortNonHex() { + ObjectId.fromString("6789ghij"); + } + @Test public void testGetByte() { byte[] raw = new byte[20]; |