-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConditionalTestLogicTest.java
71 lines (64 loc) · 1.09 KB
/
ConditionalTestLogicTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* This test has Conditional Test Logic, which means the
* methods have if statements, switch statements, while loops, for loops, or for each loops
*
* link: https://testsmells.org/pages/testsmellexamples.html#ConditionalTestLogic
*/
public class ConditionalTestLogicTest {
@Test
public void testConditionalIf()
{
if(3 == 3)
{
assertEquals(3, 3);
}
}
@Test
public void testConditionalSwitch()
{
String animal = "cat";
switch(animal){
case "cat":
assertEquals("cat", animal);
case "dog":
case "pig":
case "platypus":
default:
assertNotEquals("cat", animal);
}
}
@Test
public void testConditionalWhile()
{
int x = 0;
int y = 0;
while (x<5)
{
assertEquals(x, y);
x++;
y++;
}
}
@Test
public void testConditionalFor()
{
int x = 0;
for(int y = 0; y<5; y++)
{
assertEquals(x, y);
x++;
}
}
@Test
public void testConditionalForEach()
{
int[] x = {0,1,2,3,4};
int y = 0;
for (int i: x) {
assertEquals(i, y);
y++;
}
}
}