Skip to content

Commit

Permalink
Added a test for using a custom AsProvider with @as.
Browse files Browse the repository at this point in the history
relates to TNG#189
  • Loading branch information
Airblader committed Jul 11, 2016
1 parent 99fe5e9 commit ce4198e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
27 changes: 25 additions & 2 deletions jgiven-core/src/test/java/com/tngtech/jgiven/GivenTestStep.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.tngtech.jgiven;

import java.lang.reflect.Method;

import com.tngtech.jgiven.annotation.As;
import com.tngtech.jgiven.annotation.AsProvider;
import com.tngtech.jgiven.annotation.Format;
import com.tngtech.jgiven.annotation.Formatf;
import com.tngtech.jgiven.annotation.IntroWord;
Expand Down Expand Up @@ -89,15 +92,20 @@ public GivenTestStep a_step_with_a_bracket_after_a_dollar( int value ) {
return self();
}

public GivenTestStep a_step_with_a_printf_annotation_$( @Formatf( "%.2f" ) double d) {
@As( value = "output", provider = CustomAsProvider.class )
public GivenTestStep a_step_with_an_As_annotation_and_a_custom_provider() {
return self();
}

public GivenTestStep a_step_with_a_printf_annotation_$( @Formatf( "%.2f" ) double d ) {
return self();
}

public GivenTestStep a_step_with_a_$_parameter( String param ) {
return self();
}

public GivenTestStep a_step_with_a_boolean_$_parameter( @Format( value = BooleanFormatter.class, args = { "yes", "no" } ) boolean b) {
public GivenTestStep a_step_with_a_boolean_$_parameter( @Format( value = BooleanFormatter.class, args = { "yes", "no" } ) boolean b ) {
return self();
}

Expand All @@ -110,4 +118,19 @@ public GivenTestStep a_step_with_a_bracket_after_a_dollar( int value ) {
public GivenTestStep an_intro_word_with_an_as_annotation() {
return self();
}

public static class CustomAsProvider implements AsProvider {

@Override
public String as( As annotation, Method method ) {
return "Custom AsProvider " + annotation.value() + ": " + method.getName();
}

@Override
public String as( As annotation, Class<?> scenarioClass ) {
return null;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
import com.tngtech.jgiven.annotation.DoNotIntercept;
import com.tngtech.jgiven.annotation.IsTag;
import com.tngtech.jgiven.base.ScenarioTestBase;
import com.tngtech.jgiven.report.model.*;
import com.tngtech.jgiven.report.model.ReportModel;
import com.tngtech.jgiven.report.model.ScenarioCaseModel;
import com.tngtech.jgiven.report.model.ScenarioModel;
import com.tngtech.jgiven.report.model.StepModel;
import com.tngtech.jgiven.report.model.Tag;
import com.tngtech.jgiven.report.model.Word;

@RunWith( DataProviderRunner.class )
public class ScenarioModelBuilderTest extends ScenarioTestBase<GivenTestStep, WhenTestStep, ThenTestStep> {
Expand Down Expand Up @@ -309,6 +314,16 @@ public void characters_are_not_dropped_when_using_the_As_annotation() throws Thr
assertThat( step.getCompleteSentence() ).isEqualTo( "Given a step with a bracket after a dollar 42 ]" );
}

@Test
public void a_custom_AsProvider_can_be_used() throws Throwable {
startScenario( "Scenario with a @As tag" );
given().a_step_with_an_As_annotation_and_a_custom_provider();
getScenario().finished();
StepModel step = getScenario().getScenarioCaseModel().getFirstStep();
assertThat( step.getCompleteSentence() )
.isEqualTo( "Given Custom AsProvider output: a_step_with_an_As_annotation_and_a_custom_provider" );
}

@Test
public void camel_case_is_supported_in_steps() throws Throwable {
startScenario( "Scenario camel case steps" );
Expand Down

0 comments on commit ce4198e

Please sign in to comment.