io.github.carousell.cucumber2junit.JavaUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber2junit-maven-plugin Show documentation
Show all versions of cucumber2junit-maven-plugin Show documentation
Generates plain JUnit tests from Gherkin feature files. This is useful when you want to execute Cucumber tests in an environment which does not allow custom JUnit runners, e.g. the AWS Device Farm.
The newest version!
package io.github.carousell.cucumber2junit;
import org.apache.commons.lang.WordUtils;
/**
* This class contains helper methods to convert arbitrary Strings to valid Java method and class
* names which also follow the standard camel-case naming convention.
*/
public class JavaUtils {
public static String toClassName(String name) {
return JavaUtils.sanitiseForJava(WordUtils.capitalizeFully(name).replaceAll(" ", ""));
}
public static String toMethodName(String name) {
return JavaUtils.sanitiseForJava(
WordUtils.uncapitalize(WordUtils.capitalizeFully(name).replaceAll(" ", "")));
}
public static String sanitiseForJava(String javaName) {
StringBuilder stringBuilder = new StringBuilder();
for (char c : javaName.toCharArray()) {
if (Character.isJavaIdentifierPart(c)) {
stringBuilder.append(c);
}
}
return stringBuilder.toString();
}
}