View Javadoc
1   package integrationTests;
2   
3   import org.junit.jupiter.api.MethodOrderer;
4   import org.junit.jupiter.api.Test;
5   import org.junit.jupiter.api.TestMethodOrder;
6   
7   @TestMethodOrder(MethodOrderer.MethodName.class)
8   class UnreachableStatementsTest extends CoverageTest {
9       UnreachableStatements tested;
10  
11      @Test
12      void staticClassInitializerShouldHaveNoBranches() {
13          assertLine(3, 0, 0, 0); // one execution for each test (the constructor), plus one for the static initializer
14      }
15  
16      @Test
17      void nonBranchingMethodWithUnreachableLines() {
18          try {
19              tested.nonBranchingMethodWithUnreachableLines();
20          } catch (AssertionError ignore) {
21          }
22  
23          assertLines(12, 15, 2);
24          assertLine(12, 1, 1, 1);
25          assertLine(13, 1, 1, 1);
26          assertLine(14, 1, 0, 0);
27          assertLine(15, 1, 0, 0);
28      }
29  
30      @Test
31      void branchingMethodWithUnreachableLines_avoidAssertion() {
32          tested.branchingMethodWithUnreachableLines(0);
33  
34          assertLines(24, 30, 3);
35          assertLine(24, 3, 2, 1);
36          assertLine(25, 1, 0, 0);
37          assertLine(26, 1, 0, 0);
38          assertLine(29, 1, 1, 1);
39          assertLine(30, 1, 1, 1);
40      }
41  
42      @Test
43      void branchingMethodWithUnreachableLines_hitAndFailAssertion() {
44          try {
45              tested.branchingMethodWithUnreachableLines(1);
46          } catch (AssertionError ignore) {
47          }
48  
49          // Accounts for executions from previous test.
50          assertLines(24, 30, 4);
51          assertLine(24, 3, 3, 2);
52          assertLine(25, 1, 1, 1);
53          assertLine(26, 1, 0, 0);
54      }
55  }