All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.carousell.cucumber2junit.JavaUtils Maven / Gradle / Ivy

Go to download

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();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy