Skip to content

Commit 8e56ceb

Browse files
committed
[TestNG] Warn about usage of io.cucumber.junit.CucumberOptions
1 parent 0195d66 commit 8e56ceb

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

testng/src/main/java/io/cucumber/testng/TestNGCucumberOptionsProvider.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
package io.cucumber.testng;
22

33
import io.cucumber.core.backend.ObjectFactory;
4+
import io.cucumber.core.logging.Logger;
5+
import io.cucumber.core.logging.LoggerFactory;
46
import io.cucumber.core.options.CucumberOptionsAnnotationParser;
57
import io.cucumber.core.snippets.SnippetType;
68

9+
import java.lang.annotation.Annotation;
10+
711
final class TestNGCucumberOptionsProvider implements CucumberOptionsAnnotationParser.OptionsProvider {
812

13+
private static final Logger log = LoggerFactory.getLogger(TestNGCucumberOptionsProvider.class);
14+
915
@Override
1016
public CucumberOptionsAnnotationParser.CucumberOptions getOptions(Class<?> clazz) {
1117
CucumberOptions annotation = clazz.getAnnotation(CucumberOptions.class);
12-
if (annotation == null) {
13-
return null;
18+
if (annotation != null) {
19+
return new TestNGCucumberOptions(annotation);
20+
}
21+
warnWhenJUnitCucumberOptionsAreUsed(clazz);
22+
return null;
23+
}
24+
25+
private static void warnWhenJUnitCucumberOptionsAreUsed(Class<?> clazz) {
26+
for (Annotation clazzAnnotation : clazz.getAnnotations()) {
27+
String name = clazzAnnotation.annotationType().getName();
28+
if ("io.cucumber.junit.CucumberOptions".equals(name)) {
29+
log.warn(() -> "Ignoring options provided by " + name + " on " + clazz.getName() + ". " +
30+
"It is recommend to use separate runner classes for JUnit and TestNG."
31+
);
32+
}
1433
}
15-
return new TestNGCucumberOptions(annotation);
1634
}
1735

1836
private static class TestNGCucumberOptions implements CucumberOptionsAnnotationParser.CucumberOptions {

0 commit comments

Comments
 (0)