Skip to content

Commit

Permalink
[TestNG] Warn about usage of io.cucumber.junit.CucumberOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkorstanje committed Jun 11, 2020
1 parent 0195d66 commit 8e56ceb
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package io.cucumber.testng;

import io.cucumber.core.backend.ObjectFactory;
import io.cucumber.core.logging.Logger;
import io.cucumber.core.logging.LoggerFactory;
import io.cucumber.core.options.CucumberOptionsAnnotationParser;
import io.cucumber.core.snippets.SnippetType;

import java.lang.annotation.Annotation;

final class TestNGCucumberOptionsProvider implements CucumberOptionsAnnotationParser.OptionsProvider {

private static final Logger log = LoggerFactory.getLogger(TestNGCucumberOptionsProvider.class);

@Override
public CucumberOptionsAnnotationParser.CucumberOptions getOptions(Class<?> clazz) {
CucumberOptions annotation = clazz.getAnnotation(CucumberOptions.class);
if (annotation == null) {
return null;
if (annotation != null) {
return new TestNGCucumberOptions(annotation);
}
warnWhenJUnitCucumberOptionsAreUsed(clazz);
return null;
}

private static void warnWhenJUnitCucumberOptionsAreUsed(Class<?> clazz) {
for (Annotation clazzAnnotation : clazz.getAnnotations()) {
String name = clazzAnnotation.annotationType().getName();
if ("io.cucumber.junit.CucumberOptions".equals(name)) {
log.warn(() -> "Ignoring options provided by " + name + " on " + clazz.getName() + ". " +
"It is recommend to use separate runner classes for JUnit and TestNG."
);
}
}
return new TestNGCucumberOptions(annotation);
}

private static class TestNGCucumberOptions implements CucumberOptionsAnnotationParser.CucumberOptions {
Expand Down

0 comments on commit 8e56ceb

Please sign in to comment.