28
28
import org .junit .jupiter .api .Test ;
29
29
import org .mockito .ArgumentCaptor ;
30
30
31
+ import java .util .Arrays ;
31
32
import java .util .Collection ;
32
33
import java .util .Collections ;
33
34
import java .util .List ;
44
45
public class CallWithParametersHookTest {
45
46
private static final String TEST_FEATURE = "classpath:feature/call.feature" ;
46
47
private static final String PARAMETERS_DESCRIPTION_PATTERN =
47
- "Parameters:\n \n " + MarkdownUtils .TABLE_INDENT + "| vara | result |\n " + MarkdownUtils .TABLE_INDENT + "|------|--------|\n "
48
- + MarkdownUtils .TABLE_INDENT + "| 2 | 4 |\n \n " + MarkdownUtils .TABLE_ROW_SEPARATOR ;
49
- private final List <String > featureIds = Stream .generate (() -> CommonUtils .namedId ("feature_" )).limit (2 ).collect (Collectors .toList ());
50
- private final List <String > scenarioIds = Stream .generate (() -> CommonUtils .namedId ("scenario_" )).limit (2 ).collect (Collectors .toList ());
51
- private final List <String > stepIds = Stream .generate (() -> CommonUtils .namedId ("step_" )).limit (4 ).collect (Collectors .toList ());
52
- private final List <Pair <String , Collection <Pair <String , List <String >>>>> features = Stream .of (
53
- Pair .of (featureIds .get (0 ),
54
- (Collection <Pair <String , List <String >>>) Collections .singletonList (Pair .of (
55
- scenarioIds .get (0 ),
56
- Collections .singletonList (stepIds .get (0 ))
57
- ))
58
- ),
59
- Pair .of (
60
- featureIds .get (1 ),
61
- (Collection <Pair <String , List <String >>>) Collections .singletonList (Pair .of (
62
- scenarioIds .get (1 ),
63
- stepIds .subList (1 , stepIds .size ())
64
- ))
65
- )
48
+ "Parameters:\n \n " + MarkdownUtils .TABLE_INDENT + "|\u00A0 vara\u00A0 |\u00A0 result\u00A0 |\n " + MarkdownUtils .TABLE_INDENT
49
+ + "|------|--------|\n " + MarkdownUtils .TABLE_INDENT
50
+ + "|\u00A0 \u00A0 2\u00A0 \u00A0 \u00A0 |\u00A0 \u00A0 \u00A0 4\u00A0 \u00A0 \u00A0 \u00A0 |\n \n "
51
+ + MarkdownUtils .TABLE_ROW_SEPARATOR ;
52
+ private final String featureId = CommonUtils .namedId ("feature_" );
53
+ private final String scenarioId = CommonUtils .namedId ("scenario_" );
54
+ private final String innerFeatureId = CommonUtils .namedId ("feature_step_" );
55
+ private final List <String > stepIds = Arrays .asList (CommonUtils .namedId ("step_" ), innerFeatureId );
56
+ private final String innerScenarioId = CommonUtils .namedId ("scenario_step_" );
57
+ private final List <String > innerStepIds = Stream .generate (() -> CommonUtils .namedId ("inner_step_" ))
58
+ .limit (3 )
59
+ .collect (Collectors .toList ());
60
+
61
+ private final List <Pair <String , Collection <Pair <String , List <String >>>>> features = Stream .of (Pair .of (featureId ,
62
+ (Collection <Pair <String , List <String >>>) Collections .singletonList (Pair .of (scenarioId , stepIds ))
63
+ ))
64
+ .collect (Collectors .toList ());
65
+ private final List <Pair <String , String >> nestedSteps = Stream .concat (
66
+ Stream .of (Pair .of (innerFeatureId , innerScenarioId )),
67
+ innerStepIds .stream ().map (id -> Pair .of (innerScenarioId , id ))
66
68
).collect (Collectors .toList ());
69
+
67
70
private final ReportPortalClient client = mock (ReportPortalClient .class );
68
71
private final ReportPortal rp = ReportPortal .create (client , standardParameters (), testExecutor ());
69
72
70
73
@ BeforeEach
71
74
public void setupMock () {
72
75
mockLaunch (client , null );
73
76
mockFeatures (client , features );
77
+ mockNestedSteps (client , nestedSteps );
74
78
mockBatchLogging (client );
75
79
}
76
80
@@ -80,15 +84,17 @@ public void test_call_feature_with_parameters_hook_reporting() {
80
84
assertThat (results .getFailCount (), equalTo (0 ));
81
85
82
86
ArgumentCaptor <StartTestItemRQ > featureCaptor = ArgumentCaptor .forClass (StartTestItemRQ .class );
83
- verify (client , times (2 )).startTestItem (featureCaptor .capture ());
87
+ verify (client , times (1 )).startTestItem (featureCaptor .capture ());
84
88
ArgumentCaptor <StartTestItemRQ > scenarioCaptor = ArgumentCaptor .forClass (StartTestItemRQ .class );
85
- verify (client ).startTestItem (same (featureIds .get (0 )), scenarioCaptor .capture ());
86
- verify (client ).startTestItem (same (featureIds .get (1 )), scenarioCaptor .capture ());
89
+ verify (client ).startTestItem (same (featureId ), scenarioCaptor .capture ());
87
90
ArgumentCaptor <StartTestItemRQ > stepCaptor = ArgumentCaptor .forClass (StartTestItemRQ .class );
88
- verify (client ).startTestItem (same (scenarioIds .get (0 )), stepCaptor .capture ());
89
- verify (client , times (3 )).startTestItem (same (scenarioIds .get (1 )), stepCaptor .capture ());
91
+ verify (client , times (2 )).startTestItem (same (scenarioId ), stepCaptor .capture ());
92
+ ArgumentCaptor <StartTestItemRQ > innerScenarioCaptor = ArgumentCaptor .forClass (StartTestItemRQ .class );
93
+ verify (client ).startTestItem (same (innerFeatureId ), innerScenarioCaptor .capture ());
94
+ ArgumentCaptor <StartTestItemRQ > innerStepCaptor = ArgumentCaptor .forClass (StartTestItemRQ .class );
95
+ verify (client , times (3 )).startTestItem (same (innerScenarioId ), innerStepCaptor .capture ());
90
96
91
- StartTestItemRQ calledFeature = featureCaptor .getAllValues ()
97
+ StartTestItemRQ calledFeature = stepCaptor .getAllValues ()
92
98
.stream ()
93
99
.filter (rq -> "a feature which is called with parameters" .equals (rq .getName ()))
94
100
.findAny ()
0 commit comments