From 00698f9e27439a0a5a7556a8df1d5e94e0a7e8ba Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Sat, 29 Sep 2018 12:54:37 +0900 Subject: [PATCH] ConfigTest: Fix tests for getting empty config value as int The tests were set up to expect an IllegalArgumentException when the Config.getInt method was called with a section.key that has not been set, or explicitly set to an empty string. However, the IllegalArgumentException never gets thrown because the getInt method returns the provided default ("1"), and because there was no call to "fail" after getInt, the incorrect behavior of the test was not noticed. Remove the try/catch around getInt, and instead assert that the expected default value is returned. Found by Error Prone, which reported: Not calling fail() when expecting an exception masks bugs See https://errorprone.info/bugpattern/MissingFail Change-Id: Ie8e692aba9fb8523241fb8f298d57493923d9f78 Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/lib/ConfigTest.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index 30a07421a..21d8d66ad 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -702,11 +702,7 @@ public void testExplicitlySetEmptyString() throws Exception { assertEquals("", c.getString("a", null, "y")); assertArrayEquals(new String[]{""}, c.getStringList("a", null, "y")); - try { - c.getInt("a", null, "y", 1); - } catch (IllegalArgumentException e) { - assertEquals("Invalid integer value: a.y=", e.getMessage()); - } + assertEquals(1, c.getInt("a", null, "y", 1)); assertNull(c.getString("a", null, "z")); assertArrayEquals(new String[]{}, c.getStringList("a", null, "z")); @@ -723,11 +719,7 @@ public void testParsedEmptyString() throws Exception { assertNull(c.getString("a", null, "y")); assertArrayEquals(new String[]{null}, c.getStringList("a", null, "y")); - try { - c.getInt("a", null, "y", 1); - } catch (IllegalArgumentException e) { - assertEquals("Invalid integer value: a.y=", e.getMessage()); - } + assertEquals(1, c.getInt("a", null, "y", 1)); assertNull(c.getString("a", null, "z")); assertArrayEquals(new String[]{}, c.getStringList("a", null, "z"));