]> source.dussan.org Git - jgit.git/commitdiff
ProtocolV2ParserTest: Fix incorrect usage of ExpectedException 32/129832/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Sat, 22 Sep 2018 10:28:50 +0000 (19:28 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 25 Sep 2018 01:42:03 +0000 (10:42 +0900)
There should only be one statement after the expect(...) method.

Any additional statements after the statement that is expected to
throw will never be executed in a passing test. This can lead to
inappropriately passing tests where later incorrect assertions are
skipped by the thrown exception.

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

Change-Id: I0d6350fafb281b6bdb04289f4cd5eb4bb159628b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java

index c2e8b5b6213d7ff00316b5841c917439c6595b75..39309a1d55cd3da25945542aece0f460f5c93cb1 100644 (file)
@@ -264,25 +264,26 @@ public class ProtocolV2ParserTest {
 
        @Test
        public void testFetchMustNotHaveMultipleFilters() throws IOException {
-               thrown.expect(PackProtocolException.class);
                PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
                                "filter blob:none",
                                "filter blob:limit=12",
                                PacketLineIn.END);
                ProtocolV2Parser parser = new ProtocolV2Parser(
                                ConfigBuilder.start().allowFilter().done());
-               FetchV2Request request = parser.parseFetchRequest(pckIn,
+
+               thrown.expect(PackProtocolException.class);
+               parser.parseFetchRequest(pckIn,
                                testRepo.getRepository().getRefDatabase());
-               assertEquals(0, request.getFilterBlobLimit());
        }
 
        @Test
        public void testFetchFilterWithoutAllowFilter() throws IOException {
-               thrown.expect(PackProtocolException.class);
                PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
                                "filter blob:limit=12", PacketLineIn.END);
                ProtocolV2Parser parser = new ProtocolV2Parser(
                                ConfigBuilder.getDefault());
+
+               thrown.expect(PackProtocolException.class);
                parser.parseFetchRequest(pckIn,
                                testRepo.getRepository().getRefDatabase());
        }
@@ -315,9 +316,6 @@ public class ProtocolV2ParserTest {
 
        @Test
        public void testFetchWithRefInWantUnknownRef() throws Exception {
-               thrown.expect(PackProtocolException.class);
-               thrown.expectMessage(containsString("refs/heads/branchC"));
-
                PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
                                "want e4980cdc48cfa1301493ca94eb70523f6788b819",
                                "want-ref refs/heads/branchC",
@@ -330,6 +328,8 @@ public class ProtocolV2ParserTest {
                testRepo.update("branchA", one);
                testRepo.update("branchB", two);
 
+               thrown.expect(PackProtocolException.class);
+               thrown.expectMessage(containsString("refs/heads/branchC"));
                parser.parseFetchRequest(pckIn,
                                testRepo.getRepository().getRefDatabase());
        }