Skip to content

Commit 33b2526

Browse files
committed
chore: more coverage
1 parent 8445122 commit 33b2526

File tree

2 files changed

+57
-20
lines changed

2 files changed

+57
-20
lines changed

src/main/java/org/fugerit/java/junit5/tag/check/facade/TagScanFacade.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.junit.jupiter.api.Tag;
66

77
import java.lang.reflect.Method;
8-
import java.net.URLClassLoader;
98
import java.util.*;
109

1110
@Slf4j
@@ -15,30 +14,14 @@ private TagScanFacade() {}
1514

1615
public static Map<ExecutedTest, Set<String>> extractTagsFromExecutedTests(
1716
List<ExecutedTest> executedTests,
18-
URLClassLoader classLoader) {
19-
17+
ClassLoader classLoader) {
2018
Map<ExecutedTest, Set<String>> testTagMap = new LinkedHashMap<>();
21-
2219
for (ExecutedTest test : executedTests) {
2320
try {
2421
Class<?> testClass = classLoader.loadClass(test.getClassName());
2522
Method testMethod = findTestMethod(testClass, test.getMethodName());
26-
2723
if (testMethod != null) {
28-
Set<String> tags = new HashSet<>();
29-
30-
// Get tags from method
31-
Tag[] methodTags = testMethod.getAnnotationsByType(Tag.class);
32-
for (Tag tag : methodTags) {
33-
tags.add(tag.value());
34-
}
35-
36-
// Get tags from class
37-
Tag[] classTags = testClass.getAnnotationsByType(Tag.class);
38-
for (Tag tag : classTags) {
39-
tags.add(tag.value());
40-
}
41-
24+
Set<String> tags = getMethodTag(testMethod, testClass);
4225
testTagMap.put(test, tags);
4326
} else {
4427
log.warn("Could not find method: {} #{}", test.getClassName(), test.getMethodName());
@@ -49,10 +32,24 @@ public static Map<ExecutedTest, Set<String>> extractTagsFromExecutedTests(
4932
testTagMap.put(test, Collections.emptySet());
5033
}
5134
}
52-
5335
return testTagMap;
5436
}
5537

38+
private static Set<String> getMethodTag(Method testMethod, Class<?> testClass) {
39+
Set<String> tags = new HashSet<>();
40+
// Get tags from method
41+
Tag[] methodTags = testMethod.getAnnotationsByType(Tag.class);
42+
for (Tag tag : methodTags) {
43+
tags.add(tag.value());
44+
}
45+
// Get tags from class
46+
Tag[] classTags = testClass.getAnnotationsByType(Tag.class);
47+
for (Tag tag : classTags) {
48+
tags.add(tag.value());
49+
}
50+
return tags;
51+
}
52+
5653
private static Method findTestMethod(Class<?> testClass, String methodName) {
5754
// Try exact match first
5855
for (Method method : testClass.getDeclaredMethods()) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.fugerit.java.junit5.tag.check;
2+
3+
import org.fugerit.java.junit5.tag.check.facade.TagScanFacade;
4+
import org.fugerit.java.junit5.tag.check.model.ExecutedTest;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.math.BigDecimal;
9+
import java.util.*;
10+
11+
class TagScanFacadeTest {
12+
13+
@Test
14+
void testClassNotFound() {
15+
List<ExecutedTest> executedTests = new ArrayList<>();
16+
ExecutedTest test = new ExecutedTest( "acme.MyClass", "myMethod", Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, BigDecimal.ONE );
17+
executedTests.add( test );
18+
Map<ExecutedTest, Set<String>> testTagMap = TagScanFacade.extractTagsFromExecutedTests( executedTests, Thread.currentThread().getContextClassLoader() );
19+
Assertions.assertTrue( testTagMap.get( test ).isEmpty() );
20+
}
21+
22+
@Test
23+
void testMethodNotFound() {
24+
List<ExecutedTest> executedTests = new ArrayList<>();
25+
ExecutedTest test = new ExecutedTest( TagScanFacadeTest.class.getName(), "myMethod", Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, BigDecimal.ONE );
26+
executedTests.add( test );
27+
Map<ExecutedTest, Set<String>> testTagMap = TagScanFacade.extractTagsFromExecutedTests( executedTests, Thread.currentThread().getContextClassLoader() );
28+
Assertions.assertTrue( testTagMap.get( test ).isEmpty() );
29+
}
30+
31+
@Test
32+
void testTagNotFound() {
33+
List<ExecutedTest> executedTests = new ArrayList<>();
34+
ExecutedTest test = new ExecutedTest( TagScanFacadeTest.class.getName(), "testMethodNotFound", Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, BigDecimal.ONE );
35+
executedTests.add( test );
36+
Map<ExecutedTest, Set<String>> testTagMap = TagScanFacade.extractTagsFromExecutedTests( executedTests, Thread.currentThread().getContextClassLoader() );
37+
Assertions.assertTrue( testTagMap.get( test ).isEmpty() );
38+
}
39+
40+
}

0 commit comments

Comments
 (0)