Skip to content

Commit

Permalink
filter out duplicate parameter replacements (fixes #32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Sep 28, 2014
1 parent c79a18b commit 840a5e4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,17 @@ private void reduceMatrix( ScenarioModel scenarioModel, List<CaseArguments> argu
}

for( ParameterReplacement replacement : parameterReplacements ) {
scenarioModel.addDerivedParameter( replacement.replacementName );
boolean duplicate = scenarioModel.getDerivedParameters().contains( replacement.replacementName );
if( !duplicate ) {
scenarioModel.addDerivedParameter( replacement.replacementName );
}
for( int i = 0; i < replacement.arguments.size(); i++ ) {
Word word = replacement.arguments.get( i );
word.getArgumentInfo().setParameterName( replacement.replacementName );
word.getArgumentInfo().setDerivedParameter( replacement.isStepParameterName );
scenarioModel.getCase( i ).addDerivedArguments( word.getFormattedValue() );
if( !duplicate ) {
scenarioModel.getCase( i ).addDerivedArguments( word.getFormattedValue() );
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.tngtech.jgiven.report.analysis;

import org.junit.Test;

import com.tngtech.jgiven.JGivenScenarioTest;
import com.tngtech.jgiven.report.model.GivenReportModel;
import com.tngtech.jgiven.report.model.ThenReportModel;
import com.tngtech.jgiven.tags.Issue;

public class ArgumentAnalyzerTest extends JGivenScenarioTest<GivenReportModel<?>, WhenAnalyzer<?>, ThenReportModel<?>> {

@Test
@Issue( "#32" )
public void multiple_parameter_usages_lead_to_one_parameter() {
given().an_unanalyzed_report_model_with_one_scenario()
.with().parameters( "param1" )
.and().the_scenario_has_$_cases( 2 )
.and().case_$_has_arguments( 1, "foo" )
.and().case_$_has_a_step_$_with_argument( 1, "some step", "foo" )
.and().case_$_has_a_step_$_with_argument( 1, "another step", "foo" )
.and().case_$_has_arguments( 2, "bar" )
.and().case_$_has_a_step_$_with_argument( 2, "some step", "bar" )
.and().case_$_has_a_step_$_with_argument( 2, "another step", "bar" );
when().the_argument_analyzer_is_executed();
then().the_scenario_has_derived_parameters( "param1" )
.and().case_$_has_derived_arguments( 1, "foo" )
.and().case_$_has_derived_arguments( 2, "bar" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public class WhenAnalyzer<SELF extends WhenAnalyzer<?>> extends Stage<SELF> {
@ScenarioState
protected ReportModel reportModel;

public SELF the_argument_analyzer_is_executed() {
new CaseArgumentAnalyser().analyze( reportModel.getLastScenarioModel() );
return self();
}

public SELF the_difference_analyzer_is_executed() {
new CaseDifferenceAnalyzer().analyze( reportModel.getLastScenarioModel() );
return self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.tngtech.jgiven.Stage;
import com.tngtech.jgiven.annotation.AfterStage;
import com.tngtech.jgiven.annotation.ExtendedDescription;
import com.tngtech.jgiven.annotation.ProvidedScenarioState;
import com.tngtech.jgiven.report.analysis.CaseArgumentAnalyser;

Expand All @@ -16,6 +17,7 @@ public class GivenReportModel<SELF extends GivenReportModel<?>> extends Stage<SE

private boolean analyze = true;

@ExtendedDescription( "A report model where the analysers have not been executed on" )
public SELF an_unanalyzed_report_model_with_one_scenario() {
analyze = false;
return a_report_model_with_one_scenario();
Expand Down Expand Up @@ -82,6 +84,10 @@ public ReportModel getReportModel() {
return reportModel;
}

public SELF parameters( String... params ) {
return the_scenario_has_parameters( params );
}

public SELF the_scenario_has_parameters( String... params ) {
reportModel.getLastScenarioModel().addParameterNames( params );
return self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,14 @@ private Word getWord( int caseNr, int stepNr, int wordNr ) {
return reportModel.getLastScenarioModel().getCase( caseNr - 1 ).getStep( stepNr - 1 ).getWord( wordNr - 1 );
}

public SELF case_$_has_derived_arguments( int caseNr, String... arguments ) {
assertThat( reportModel.getLastScenarioModel().getCase( caseNr - 1 ).getDerivedArguments() ).containsExactly( arguments );
return self();
}

public SELF the_scenario_has_derived_parameters( String... parameters ) {
assertThat( reportModel.getLastScenarioModel().getDerivedParameters() ).containsExactly( parameters );
return self();
}

}

0 comments on commit 840a5e4

Please sign in to comment.