private CucumberException registerTypeInConfiguration(String expressionString, UndefinedParameterTypeException e) { return new CucumberException(String.format("" + "Could not create a cucumber expression for '%s'.\n" + "It appears you did not register parameter type. The details are in the stacktrace below.\n" + "You can find the documentation here: https://docs.cucumber.io/cucumber/cucumber-expressions/", expressionString ), e); }
private URL toUrl(String fileName) { try { return new URL(htmlReportDir, fileName); } catch (IOException e) { throw new CucumberException(e); } }
@SuppressWarnings("unchecked") private static Class<? extends Plugin> loadClass(String className) { try { Class<?> aClass = Thread.currentThread().getContextClassLoader().loadClass(className); if (Plugin.class.isAssignableFrom(aClass)) { return (Class<? extends Plugin>) aClass; } throw new CucumberException("Couldn't load plugin class: " + className + ". It does not implement " + Plugin.class.getName()); } catch (ClassNotFoundException e) { throw new CucumberException("Couldn't load plugin class: " + className, e); } }
static String filePath(URL fileUrl) { if (!"file".equals(fileUrl.getProtocol())) { throw new CucumberException("Expected a file URL:" + fileUrl.toExternalForm()); } try { return fileUrl.toURI().getSchemeSpecificPart(); } catch (URISyntaxException e) { throw new CucumberException(e); } }
public static SnippetType fromString(String name) { for (SnippetType snippetType : SnippetType.values()) { if (name.equalsIgnoreCase(snippetType.name)) { return snippetType; } } throw new CucumberException(String.format("Unrecognized SnippetType %s", name)); }
private void notifyContextManagerAboutTestClassStarted() { if (testContextManager != null) { try { testContextManager.beforeTestClass(); } catch (Exception e) { throw new CucumberException(e.getMessage(), e); } } }
private void notifyContextManagerAboutTestClassFinished() { if (testContextManager != null) { try { testContextManager.afterTestClass(); } catch (Exception e) { throw new CucumberException(e.getMessage(), e); } } }
@Override public Collection<? extends Backend> get() { Collection<? extends Backend> backends = loadBackends(); if (backends.isEmpty()) { throw new CucumberException("No backends were found. Please make sure you have a backend module on your CLASSPATH."); } return backends; }
private static OutputStream createReportFileOutputStream(URL url) { try { return new URLOutputStream(url); } catch (IOException e) { throw new CucumberException(e); } }
private static void checkNoComponentAnnotations(Class<?> type) { for (Annotation annotation : type.getAnnotations()) { if (hasComponentAnnotation(annotation)) { throw new CucumberException(String.format("" + "Glue class %1$s was annotated with @%2$s; marking it as a candidate for auto-detection by " + "Spring. Glue classes are detected and registered by Cucumber. Auto-detection of glue classes by " + "spring may lead to duplicate bean definitions. Please remove the @%2$s annotation", type.getName(), annotation.annotationType().getSimpleName())); } } }
private static NiceAppendable createJsOut(URL htmlReportDir) { try { return new NiceAppendable(new OutputStreamWriter(createReportFileOutputStream(new URL(htmlReportDir, JS_REPORT_FILENAME)), "UTF-8")); } catch (IOException e) { throw new CucumberException(e); } }
private void copyReportFiles() { if (htmlReportDir == null) { return; } for (String textAsset : TEXT_ASSETS) { InputStream textAssetStream = getClass().getResourceAsStream(textAsset); if (textAssetStream == null) { throw new CucumberException("Couldn't find " + textAsset + ". Is cucumber-html on your classpath? Make sure you have the right version."); } String fileName = new File(textAsset).getName(); writeStreamToURL(textAssetStream, toUrl(fileName)); } }
private static void writeBytesToURL(byte[] buf, URL url) throws CucumberException { OutputStream out = createReportFileOutputStream(url); try { out.write(buf); } catch (IOException e) { throw new CucumberException("Unable to write to report file item: ", e); } finally { closeQuietly(out); } }
private CucumberException registerTypeInConfiguration(Exception e) { return new CucumberException(String.format("" + "Could not convert arguments for step [%s] defined at '%s'.\n" + "It appears you did not register a data table type. The details are in the stacktrace below.", //TODO: Add doc URL stepDefinition.getPattern(), stepDefinition.getLocation(true) ), e); }
private CucumberException couldNotConvertArguments(Exception e) { return new CucumberException(String.format( "Could not convert arguments for step [%s] defined at '%s'.\n" + "The details are in the stacktrace below.", stepDefinition.getPattern(), stepDefinition.getLocation(true) ), e); }
@Override public <T> T getInstance(final Class<T> type) { try { return beanFactory.getBean(type); } catch (BeansException e) { throw new CucumberException(e.getMessage(), e); } }
private static String read(Resource resource) { try { return Encoding.readFile(resource); } catch (IOException e) { throw new CucumberException("Failed to read resource:" + resource.getPath(), e); } }
private static String read(Resource resource) { try { return Encoding.readFile(resource); } catch (IOException e) { throw new CucumberException("Failed to read resource:" + resource.getPath(), e); } }
private CucumberException arityMismatch(int parameterCount) { List<String> arguments = createArgumentsForErrorMessage(); return new CucumberException(String.format( "Step [%s] is defined with %s parameters at '%s'.\n" + "However, the gherkin step has %s arguments%sStep text: %s", stepDefinition.getPattern(), parameterCount, stepDefinition.getLocation(true), arguments.size(), formatArguments(arguments), step.getText() )); }
public void addPluginName(String name, boolean isAddPlugin) { if (PluginFactory.isStepDefinitionReporterName(name)) { stepDefinitionReporterNames.addName(name, isAddPlugin); } else if (PluginFactory.isSummaryPrinterName(name)) { summaryPrinterNames.addName(name, isAddPlugin); } else if (PluginFactory.isFormatterName(name)) { formatterNames.addName(name, isAddPlugin); } else { throw new CucumberException("Unrecognized plugin: " + name); } }