View Javadoc
1   package integrationTests.loops;
2   
3   import org.junit.jupiter.api.Assertions;
4   import org.junit.jupiter.api.Test;
5   
6   import integrationTests.CoverageTest;
7   
8   class WhileStatementsTest extends CoverageTest {
9       WhileStatements tested;
10  
11      @Test
12      void whileBlockInSeparateLines() {
13          tested.whileBlockInSeparateLines();
14  
15          assertLines(12, 17, 4);
16          assertLine(12, 1, 1, 1);
17          assertLine(14, 1, 1, 6);
18          assertLine(15, 1, 1, 5);
19          assertLine(17, 1, 1, 1);
20      }
21  
22      @Test
23      void whileBlockInSingleLine() {
24          tested.whileBlockInSingleLine(0);
25          tested.whileBlockInSingleLine(1);
26          tested.whileBlockInSingleLine(2);
27  
28          assertLines(20, 23, 2);
29          assertLine(21, 2, 2, 6);
30          assertLine(23, 1, 1, 3);
31      }
32  
33      @Test
34      void whileWithIfElse() {
35          tested.whileWithIfElse(0);
36          tested.whileWithIfElse(1);
37          tested.whileWithIfElse(2);
38  
39          assertLines(126, 137, 5);
40      }
41  
42      @Test
43      void whileWithContinue() {
44          tested.whileWithContinue(0);
45          tested.whileWithContinue(1);
46          tested.whileWithContinue(2);
47  
48          assertLines(26, 35, 6);
49          assertLine(26, 1, 1, 6);
50          assertLine(27, 1, 1, 3);
51          assertLine(28, 1, 1, 2);
52          assertLine(29, 1, 1, 2);
53          assertLine(32, 1, 1, 1);
54          assertLine(35, 1, 1, 3);
55      }
56  
57      @Test
58      void whileWithBreak() {
59          tested.whileWithBreak(0);
60          tested.whileWithBreak(1);
61          tested.whileWithBreak(2);
62  
63          assertLines(39, 47, 5);
64          assertLine(39, 2, 2, 4);
65          assertLine(40, 1, 1, 3);
66          assertLine(41, 1, 1, 2);
67          assertLine(44, 1, 1, 1);
68          assertLine(47, 1, 1, 3);
69      }
70  
71      @Test
72      void nestedWhile() {
73          tested.nestedWhile(0, 2);
74          tested.nestedWhile(1, 1);
75  
76          assertLines(51, 58, 4);
77          assertLine(51, 2, 2, 3);
78          assertLine(52, 1, 1, 1);
79          assertLine(53, 1, 0, 0);
80          assertLine(56, 1, 1, 1);
81          assertLine(58, 1, 1, 2);
82      }
83  
84      @Test
85      void doWhileInSeparateLines() {
86          tested.doWhileInSeparateLines();
87  
88          assertLines(61, 66, 4);
89          assertLine(61, 1, 1, 1);
90          assertLine(64, 1, 1, 3);
91          assertLine(65, 2, 2, 3);
92          assertLine(66, 1, 1, 1);
93      }
94  
95      @Test
96      void bothKindsOfWhileCombined() {
97          tested.bothKindsOfWhileCombined(0, 0);
98          tested.bothKindsOfWhileCombined(0, 2);
99          tested.bothKindsOfWhileCombined(1, 1);
100 
101         assertLines(69, 83, 5);
102         assertLine(71, 1, 1, 5);
103         assertLine(74, 2, 2, 5);
104         assertLine(77, 1, 1, 4);
105         assertLine(79, 2, 2, 4);
106     }
107 
108     @Test
109     void whileTrueEndingWithAnIf() {
110         tested.whileTrueEndingWithAnIf(0);
111 
112         // TODO: assertions
113     }
114 
115     @Test
116     void whileTrueStartingWithAnIf() {
117         tested.whileTrueStartingWithAnIf(0);
118 
119         // TODO: assertions
120     }
121 
122     @Test
123     void whileTrueWithoutExitCondition() {
124         Assertions.assertThrows(IllegalStateException.class, () -> {
125             tested.whileTrueWithoutExitCondition();
126         });
127     }
128 
129     @Test
130     public void whileTrueContainingTryFinally() {
131         Assertions.assertThrows(IllegalStateException.class, () -> {
132             tested.whileTrueContainingTryFinally();
133         });
134     }
135 }