1
2
3
4
5
6 package integration.tests.loops;
7
8 import static java.util.Arrays.asList;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.junit.jupiter.api.Disabled;
16 import org.junit.jupiter.api.Test;
17
18 import integration.tests.CoverageTest;
19
20 class ForStatementsTest extends CoverageTest {
21 ForStatements tested;
22
23 @Test
24 void forInSeparateLines() {
25 tested.forInSeparateLines();
26 tested.forInSeparateLines();
27
28 assertLines(14, 17, 3);
29 assertLine(14, 2, 2, 6);
30 assertLine(15, 1, 1, 4);
31 assertLine(17, 1, 1, 2);
32 }
33
34 @Test
35 void forInSingleLine() {
36 tested.forInSingleLine(1);
37 tested.forInSingleLine(2);
38
39 assertLines(20, 23, 2);
40 assertLine(21, 2, 2, 3);
41 assertLine(23, 1, 1, 2);
42 }
43
44 @Test
45 void forEachArrayElement() {
46 int sum = tested.forEachArrayElement(1, 2, 3);
47 assertEquals(6, sum);
48
49 assertLines(26, 32, 4);
50 assertLine(26, 1, 1, 1);
51 assertLine(28, 2, 2, 4);
52 assertLine(29, 1, 1, 3);
53 assertLine(32, 1, 1, 1);
54 }
55
56 @Test
57 void forEachCollectionElement() {
58 String result = tested.forEachCollectionElement(asList("a", "b", "c"));
59 assertEquals("abc", result);
60
61 assertLines(36, 42, 5);
62 assertLine(36, 1, 1, 1);
63 assertLine(38, 2, 2, 1);
64 assertLine(39, 1, 1, 3);
65 assertLine(42, 1, 1, 1);
66 }
67
68 @Test
69 void forUsingIterator() {
70 List<? extends Number> numbers = new ArrayList<Number>(asList(1, 0L, 2.0));
71 tested.forUsingIterator(numbers);
72
73 assertLines(46, 53, 6);
74 assertLine(46, 2, 2, 1);
75 assertLine(47, 1, 1, 3);
76 assertLine(49, 3, 3, 3);
77 assertLine(50, 1, 1, 1);
78 assertLine(53, 1, 1, 1);
79 }
80
81 @Disabled("for issue #254")
82 @Test
83 void forWithNestedIfWhichReturns() {
84 tested.forWithNestedIfWhichReturns(2, 1, 2, 3);
85 }
86 }