]> source.dussan.org Git - jgit.git/commitdiff
BlockListTest: Add missing calls to fail() 84/130184/1
authorDavid Pursehouse <david.pursehouse@gmail.com>
Sat, 29 Sep 2018 04:16:58 +0000 (13:16 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Sat, 29 Sep 2018 04:16:58 +0000 (13:16 +0900)
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>
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/BlockListTest.java

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