Skip to content

Commit 01be1e0

Browse files
LarsEckartisidorejlink
committed
F!! allow multi level @testable detection
Co-Authored-By: Llewellyn Falco <[email protected]> Co-Authored-By: Johannes Link <[email protected]>
1 parent e70a7d6 commit 01be1e0

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

approvaltests-tests/src/test/java/org/approvaltests/namer/AttributeStackSelectorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ void testDetectionOfAnnotationsThatAreMarkedTestable()
1919
StackTraceElement element = ThreadUtils.getStackTrace()[2];
2020
assertTrue(AttributeStackSelector.isTestableMethod(element));
2121
}
22+
@Example()
23+
void testDetectionOfAnnotationsThatAreIndirectlyMarkedTestable()
24+
{
25+
StackTraceElement element = ThreadUtils.getStackTrace()[2];
26+
assertTrue(AttributeStackSelector.isTestableMethod(element));
27+
}
2228
@Test
2329
void unrollLambda()
2430
{

approvaltests/src/main/java/org/approvaltests/namer/AttributeStackSelector.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.spun.util.io.StackElementSelector;
66
import com.spun.util.tests.TestUtils;
77
import org.junit.platform.commons.annotation.Testable;
8+
import org.junit.platform.commons.util.AnnotationUtils;
89

910
import java.lang.annotation.Annotation;
1011
import java.lang.reflect.Method;
@@ -90,20 +91,11 @@ public static boolean isTestableMethod(StackTraceElement element)
9091
{ return false; }
9192
for (Method method : methods)
9293
{
93-
Annotation[] annotations = method.getAnnotations();
94-
for (Annotation annotation : annotations)
95-
{
96-
if (isTestableAnnotation(annotation))
97-
{ return true; }
98-
}
94+
if (AnnotationUtils.isAnnotated(method, Testable.class))
95+
{ return true; }
9996
}
10097
return false;
10198
}
102-
public static boolean isTestableAnnotation(Annotation annotation)
103-
{
104-
Class<? extends Annotation> annotationType = annotation.annotationType();
105-
return annotationType.isAnnotationPresent(Testable.class);
106-
}
10799
private boolean isJunit3Test(Class<?> clazz)
108100
{
109101
Class<?> testcase = loadClass("junit.framework.TestCase");

0 commit comments

Comments
 (0)