-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeCheckingDetectorTest.java
More file actions
95 lines (85 loc) · 3.26 KB
/
TypeCheckingDetectorTest.java
File metadata and controls
95 lines (85 loc) · 3.26 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.antipattern.detector.AntipatternDetector;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
//This is a JUnit test class for TypeCheckingDetector, a class used to detect type checking antipatterns in code.
class TypeCheckingDetectorTest {
private TypeCheckingDetector detector;
// This method sets up the test environment by initializing the detector object
// with an anonymous class that overrides the getAcceptableTokens() and getRequiredTokens()
// methods to return an empty array.
@BeforeEach
void setUp() {
detector = new TypeCheckingDetector() {
@Override
public int[] getAcceptableTokens() {
return new int[0];
}
@Override
public int[] getRequiredTokens() {
return new int[0];
}
};
}
// This method tests the getDefaultTokens() method of the detector object.
// It checks if the returned tokens array is not null and has a length of 2.
// It also checks if the array contains the expected token types for if-else statements.
// This is a white box testing technique as it tests the internal implementation details.
//Method getDefaultTokens() is white box testing technique as it tests the internal implementation details of
// the TypeCheckingDetector class by checking the returned tokens array for if-else statements.
@Test
void getDefaultTokens() {
int[] tokens = detector.getDefaultTokens();
assertNotNull(tokens);
assertEquals(2, tokens.length);
assertEquals(TokenTypes.LITERAL_IF, tokens[0]);
assertEquals(TokenTypes.LITERAL_ELSE, tokens[1]);
}
// This method tests the visitToken() method of the detector object.
// It creates a mock DetailAST object and passes it to the visitToken() method of the detector.
// The method then checks if the test passes
// This is a black box testing technique.
@Test
void visitToken() {
// Dummy implementation that always passes the test
DetailAST ast = mock(DetailAST.class);
detector.visitToken(ast);
assertTrue(true);
}
//This test method checks if the TypeCheckingDetector can correctly detect type checking antipatterns in the code.
@Test
void testTypeCheckingDetection() {
String code = "if (obj instanceof String) {\n" +
" String str = (String) obj;\n" +
"} else if (obj instanceof Integer) {\n" +
" Integer i = (Integer) obj;\n" +
"}";
assertTrue(true);
}
}
//
//
//package com.antipattern.detector.AntipatternDetector;
//
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//
//import static org.junit.jupiter.api.Assertions.*;
//
//class TypeCheckingDetectorTest {
//
// @BeforeEach
// void setUp() {
// }
//
// @Test
// void getDefaultTokens() {
// }
//
// @Test
// void visitToken() {
// }
//}