Search in sources :

Example 1 with BytecodeReadingParanamer

use of com.thoughtworks.paranamer.BytecodeReadingParanamer in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldInvokeBeforeOrAfterStepMethodWithExpectedConvertedParametersFromMeta.

@Test
public void shouldInvokeBeforeOrAfterStepMethodWithExpectedConvertedParametersFromMeta() throws Exception {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    StepCreator stepCreator = stepCreatorUsing(stepsInstance, mock(StepMatcher.class), new ParameterControls());
    stepCreator.useParanamer(new CachingParanamer(new BytecodeReadingParanamer()));
    // When
    Date aDate = new Date();
    when(parameterConverters.convert(anyString(), eq(Date.class))).thenReturn(aDate);
    Step stepWithMeta = stepCreator.createBeforeOrAfterStep(SomeSteps.methodFor("aMethodWithDate"), new Meta());
    StepResult stepResult = stepWithMeta.perform(null);
    // Then
    assertThat(stepResult, instanceOf(Silent.class));
    assertThat((Date) stepsInstance.args, is(aDate));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) Meta(org.jbehave.core.model.Meta) CachingParanamer(com.thoughtworks.paranamer.CachingParanamer) Silent(org.jbehave.core.steps.AbstractStepResult.Silent) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) BytecodeReadingParanamer(com.thoughtworks.paranamer.BytecodeReadingParanamer) Date(java.util.Date) Test(org.junit.Test)

Example 2 with BytecodeReadingParanamer

use of com.thoughtworks.paranamer.BytecodeReadingParanamer in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldInvokeBeforeOrAfterStepMethodWithMetaUsingParanamer.

@Test
public void shouldInvokeBeforeOrAfterStepMethodWithMetaUsingParanamer() throws Exception {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    StepCreator stepCreator = stepCreatorUsing(stepsInstance, mock(StepMatcher.class), new ParameterControls());
    stepCreator.useParanamer(new CachingParanamer(new BytecodeReadingParanamer()));
    Properties properties = new Properties();
    properties.put("theme", "shopping cart");
    // When
    Step stepWithMeta = stepCreator.createBeforeOrAfterStep(SomeSteps.methodFor("aMethodWithoutNamedAnnotation"), new Meta(properties));
    StepResult stepResult = stepWithMeta.perform(null);
    // Then
    assertThat(stepResult, instanceOf(Silent.class));
    assertThat((String) stepsInstance.args, is("shopping cart"));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) Meta(org.jbehave.core.model.Meta) CachingParanamer(com.thoughtworks.paranamer.CachingParanamer) Silent(org.jbehave.core.steps.AbstractStepResult.Silent) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) Properties(java.util.Properties) BytecodeReadingParanamer(com.thoughtworks.paranamer.BytecodeReadingParanamer) Test(org.junit.Test)

Example 3 with BytecodeReadingParanamer

use of com.thoughtworks.paranamer.BytecodeReadingParanamer in project jbehave-core by jbehave.

the class CompositeStepCandidateBehaviour method shouldMatchCompositeStepsAndCreateComposedStepsUsingParanamerNamedParameters.

@Test
@Ignore("fails as perhaps Paranamer not peer of @named in respect of @composite")
public void shouldMatchCompositeStepsAndCreateComposedStepsUsingParanamerNamedParameters() {
    CompositeStepsWithoutNamedAnnotation steps = new CompositeStepsWithoutNamedAnnotation();
    List<StepCandidate> candidates = steps.listCandidates();
    StepCandidate candidate = candidates.get(0);
    candidate.useParanamer(new BytecodeReadingParanamer());
    assertThat(candidate.isComposite(), is(true));
    Map<String, String> namedParameters = new HashMap<>();
    namedParameters.put("customer", "Mr Jones");
    namedParameters.put("product", "ticket");
    List<Step> composedSteps = new ArrayList<>();
    candidate.addComposedSteps(composedSteps, "Given <customer> has previously bought a <product>", namedParameters, candidates);
    assertThat(composedSteps.size(), equalTo(2));
    for (Step step : composedSteps) {
        step.perform(null);
    }
    assertThat(steps.loggedIn, equalTo("Mr Jones"));
    assertThat(steps.added, equalTo("ticket"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StepCandidateBehaviour.candidateMatchingStep(org.jbehave.core.steps.StepCandidateBehaviour.candidateMatchingStep) BytecodeReadingParanamer(com.thoughtworks.paranamer.BytecodeReadingParanamer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

BytecodeReadingParanamer (com.thoughtworks.paranamer.BytecodeReadingParanamer)3 Test (org.junit.Test)3 CachingParanamer (com.thoughtworks.paranamer.CachingParanamer)2 Meta (org.jbehave.core.model.Meta)2 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)2 StepMatcher (org.jbehave.core.parsers.StepMatcher)2 Silent (org.jbehave.core.steps.AbstractStepResult.Silent)2 ParametrisedStep (org.jbehave.core.steps.StepCreator.ParametrisedStep)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 StepCandidateBehaviour.candidateMatchingStep (org.jbehave.core.steps.StepCandidateBehaviour.candidateMatchingStep)1 Ignore (org.junit.Ignore)1