Browse Source

BlockListTest: Add missing calls to fail()

Error Prone reports:

  Not calling fail() when expecting an exception masks bugs

See https://errorprone.info/bugpattern/MissingFail

Change-Id: I518b524de7cd3802f03b80450cad02ab3f79d57b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.2
David Pursehouse 6 years ago
parent
commit
0b292b9085
  1. 13
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/BlockListTest.java

13
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/BlockListTest.java

@ -47,6 +47,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Iterator; import java.util.Iterator;
@ -84,18 +85,21 @@ public class BlockListTest {
try { try {
list.get(-1); list.get(-1);
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(-1), badIndex.getMessage()); assertEquals(String.valueOf(-1), badIndex.getMessage());
} }
try { try {
list.get(0); list.get(0);
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(0), badIndex.getMessage()); assertEquals(String.valueOf(0), badIndex.getMessage());
} }
try { try {
list.get(4); list.get(4);
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(4), badIndex.getMessage()); assertEquals(String.valueOf(4), badIndex.getMessage());
} }
@ -114,6 +118,7 @@ public class BlockListTest {
try { try {
list.get(3); list.get(3);
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(3), badIndex.getMessage()); assertEquals(String.valueOf(3), badIndex.getMessage());
} }
@ -125,18 +130,21 @@ public class BlockListTest {
try { try {
list.set(-1, "foo"); list.set(-1, "foo");
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(-1), badIndex.getMessage()); assertEquals(String.valueOf(-1), badIndex.getMessage());
} }
try { try {
list.set(0, "foo"); list.set(0, "foo");
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(0), badIndex.getMessage()); assertEquals(String.valueOf(0), badIndex.getMessage());
} }
try { try {
list.set(4, "foo"); list.set(4, "foo");
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(4), badIndex.getMessage()); assertEquals(String.valueOf(4), badIndex.getMessage());
} }
@ -161,6 +169,7 @@ public class BlockListTest {
try { try {
list.set(3, "bar"); list.set(3, "bar");
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(3), badIndex.getMessage()); assertEquals(String.valueOf(3), badIndex.getMessage());
} }
@ -323,12 +332,14 @@ public class BlockListTest {
try { try {
list.add(-1, Integer.valueOf(42)); list.add(-1, Integer.valueOf(42));
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(-1), badIndex.getMessage()); assertEquals(String.valueOf(-1), badIndex.getMessage());
} }
try { try {
list.add(4, Integer.valueOf(42)); list.add(4, Integer.valueOf(42));
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(4), badIndex.getMessage()); assertEquals(String.valueOf(4), badIndex.getMessage());
} }
@ -341,12 +352,14 @@ public class BlockListTest {
try { try {
list.remove(-1); list.remove(-1);
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(-1), badIndex.getMessage()); assertEquals(String.valueOf(-1), badIndex.getMessage());
} }
try { try {
list.remove(4); list.remove(4);
fail("accepted out-of-bounds index");
} catch (IndexOutOfBoundsException badIndex) { } catch (IndexOutOfBoundsException badIndex) {
assertEquals(String.valueOf(4), badIndex.getMessage()); assertEquals(String.valueOf(4), badIndex.getMessage());
} }

Loading…
Cancel
Save