public boolean isFluent() { if (description.getTestMethod() != null) { Step step = description.getTestMethod().getAnnotation(Step.class); return ((step != null) && (step.fluent())); } return false; }
public Method getTestMethod() { if (getTestClass() != null) { return methodCalled(withNoArguments(description.getName()), getTestClass()); } else { return null; } }
private void notifyOfStepFailure(final Method method, final Object[] args, final Throwable cause) throws Exception { ExecutedStepDescription description = ExecutedStepDescription.of(testStepClass, getTestNameFrom(method, args)); StepFailure failure = new StepFailure(description, cause); StepEventBus.getEventBus().stepFailed(failure); }
public String getName() { if (noClassIsDefined()) { return description.getName(); } else if (isAGroup()) { return groupName(); } else { return stepName(); } }
private void allStepDefinitionFieldsShouldBeResolvedIn(String stepDescription) { Map<String, Object> fields = description.getDisplayedFields(); for (String field : fields.keySet()) { if (stepDescription.contains(fieldNameFor(field))) { throw new AssertionError( stepDescription + " : " + field + " value could not be resolved"); } } }
@Test public void shouldIndicateWhenATestIsRunning() { StepEventBus.getEventBus().dropAllListeners(); StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle("a step")); assertThat(StepEventBus.getEventBus().areStepsRunning(), is(true)); }
@Test public void a_step_can_be_marked_pending() { StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle("a step")); StepEventBus.getEventBus().stepPending(); StepEventBus.getEventBus().testFinished(testOutcome); String expectedSteps = "TEST a_test\n" + "-a step\n" + "---> STEP PENDING\n" + "TEST DONE\n"; assertThat(consoleStepListener.toString(), is(expectedSteps)); }
@Test public void the_step_event_bus_can_be_used_to_sent_notification_events_about_steps() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testSuiteStarted(SampleTestScenario.class); StepEventBus.getEventBus().testStarted("some_test"); StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle("a step")); verify(listener).stepStarted(any(ExecutedStepDescription.class)); }
@Test public void should_clear_all_listeners_when_requested() { StepEventBus.getEventBus().dropAllListeners(); StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle("a step")); StepEventBus.getEventBus().stepPending(); StepEventBus.getEventBus().testFinished(testOutcome); assertThat(consoleStepListener.toString(), is("")); }
private String annotatedStepNameWithParameters(String annotatedStepTemplate) { String annotatedStepName = annotatedStepTemplate; Iterable<String> parameters = getParamatersFrom(description.getName()); int counter = 0; for (String parameter : parameters) { String token = "{" + counter++ + "}"; annotatedStepName = StringUtils.replace(annotatedStepName, token, parameter); } return annotatedStepName; }
private String stepName() { String annotationTitle = getAnnotatedTitle(); if (!StringUtils.isEmpty(annotationTitle)) { return annotationTitle; } Optional<String> annotatedStepName = getAnnotatedStepName(); if (getAnnotatedStepName().isPresent() && (StringUtils.isNotEmpty(annotatedStepName.get()))) { return annotatedStepNameWithParameters(annotatedStepName.get()); } return humanize(description.getName()); }
public String into(String stepDescription) { Map<String, Object> fields = description.getDisplayedFields(); for (String field : fields.keySet()) { String fieldName = fieldNameFor(field); Object value = fields.get(field); if (stepDescription.contains(fieldName) && (value != UNDEFINED)) { stepDescription = StringUtils.replace(stepDescription, fieldNameFor(field), stringValueFor(value)); } } // allStepDefinitionFieldsShouldBeResolvedIn(stepDescription); return stepDescription; }
private void notifySkippedStepStarted(final Method method, final Object[] args) { ExecutedStepDescription description = ExecutedStepDescription.of(testStepClass, getTestNameFrom(method, args)); StepEventBus.getEventBus().skippedStepStarted(description); }
private Class<?> getTestClass() { return description.getStepClass(); }
public Method getTestMethodIfPresent() { return findMethodCalled(withNoArguments(description.getName()), getTestClass()); }
private boolean noClassIsDefined() { return description.getStepClass() == null; }