Skip to content

Commit 2b81cae

Browse files
committed
Call logic fix: Fix tests
1 parent 743ea58 commit 2b81cae

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.junit.jupiter.api.Test;
2929
import org.mockito.ArgumentCaptor;
3030

31+
import java.util.Arrays;
3132
import java.util.Collection;
3233
import java.util.Collections;
3334
import java.util.List;
@@ -44,33 +45,36 @@
4445
public class CallWithParametersHookTest {
4546
private static final String TEST_FEATURE = "classpath:feature/call.feature";
4647
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 + "|\u00A0vara\u00A0|\u00A0result\u00A0|\n" + MarkdownUtils.TABLE_INDENT
49+
+ "|------|--------|\n" + MarkdownUtils.TABLE_INDENT
50+
+ "|\u00A0\u00A02\u00A0\u00A0\u00A0|\u00A0\u00A0\u00A04\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))
6668
).collect(Collectors.toList());
69+
6770
private final ReportPortalClient client = mock(ReportPortalClient.class);
6871
private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor());
6972

7073
@BeforeEach
7174
public void setupMock() {
7275
mockLaunch(client, null);
7376
mockFeatures(client, features);
77+
mockNestedSteps(client, nestedSteps);
7478
mockBatchLogging(client);
7579
}
7680

@@ -80,15 +84,17 @@ public void test_call_feature_with_parameters_hook_reporting() {
8084
assertThat(results.getFailCount(), equalTo(0));
8185

8286
ArgumentCaptor<StartTestItemRQ> featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
83-
verify(client, times(2)).startTestItem(featureCaptor.capture());
87+
verify(client, times(1)).startTestItem(featureCaptor.capture());
8488
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());
8790
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());
9096

91-
StartTestItemRQ calledFeature = featureCaptor.getAllValues()
97+
StartTestItemRQ calledFeature = stepCaptor.getAllValues()
9298
.stream()
9399
.filter(rq -> "a feature which is called with parameters".equals(rq.getName()))
94100
.findAny()

0 commit comments

Comments
 (0)