Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Jan 19, 2024
1 parent 3469a6e commit f9bb7fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected TestCaseIdEntry getTestCaseId(@Nonnull TestStep testStep, @Nullable St
List<cucumber.api.Argument> arguments = ((PickleStepTestStep) testStep).getDefinitionArgument();
if (definitionMatch != null) {
try {
Method method = retrieveMethod((StepDefinitionMatch) definitionMatch);
Method method = retrieveMethod(definitionMatch);
return TestCaseIdUtils.getTestCaseId(method.getAnnotation(TestCaseId.class),
method,
codeRef,
Expand Down Expand Up @@ -332,7 +332,7 @@ protected void afterScenario(TestCaseFinished event) {
currentScenarioContextMap.remove(Pair.of(context.getLine(), featureUri));
Date endTime = finishTestItem(context.getId(), event.result.getStatus());
featureEndTime.put(featureUri, endTime);
currentScenarioContext.set(null);
currentScenarioContext.remove();
removeFromTree(currentFeatureContextMap.get(context.getFeatureUri()), context);
}

Expand All @@ -342,7 +342,7 @@ protected void afterScenario(TestCaseFinished event) {
protected void startLaunch() {
launch = new MemoizingSupplier<>(new Supplier<Launch>() {

/* should no be lazy */
/* should not be lazy */
private final Date startTime = Calendar.getInstance().getTime();

@Override
Expand Down Expand Up @@ -912,7 +912,7 @@ protected Set<ItemAttributesRQ> getAttributes(@Nonnull TestStep testStep) {
Object definitionMatch = getDefinitionMatch(testStep);
if (definitionMatch != null) {
try {
Method method = retrieveMethod((StepDefinitionMatch) definitionMatch);
Method method = retrieveMethod(definitionMatch);
Attributes attributesAnnotation = method.getAnnotation(Attributes.class);
if (attributesAnnotation != null) {
return AttributeParser.retrieveAttributes(attributesAnnotation);
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/epam/reportportal/cucumber/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import com.epam.reportportal.utils.reflect.Accessible;
import cucumber.api.Result;
import cucumber.api.TestStep;
import cucumber.runtime.StepDefinitionMatch;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -82,13 +80,13 @@ public static String buildName(String prefix, String infix, String argument) {
return (prefix == null ? EMPTY : prefix) + infix + argument;
}

public static Method retrieveMethod(StepDefinitionMatch stepDefinitionMatch) throws IllegalAccessException, NoSuchFieldException {
Field stepDefinitionField = stepDefinitionMatch.getClass().getDeclaredField(STEP_DEFINITION_FIELD_NAME);
stepDefinitionField.setAccessible(true);
Object javaStepDefinition = stepDefinitionField.get(stepDefinitionMatch);
Field methodField = javaStepDefinition.getClass().getDeclaredField(METHOD_FIELD_NAME);
methodField.setAccessible(true);
return (Method) methodField.get(javaStepDefinition);
public static Method retrieveMethod(Object stepDefinitionMatch) throws IllegalAccessException, NoSuchFieldException {
Object javaStepDefinition = Accessible.on(stepDefinitionMatch).field(STEP_DEFINITION_FIELD_NAME).getValue();
Method method = null;
if (javaStepDefinition != null) {
method = (Method) Accessible.on(javaStepDefinition).field(METHOD_FIELD_NAME).getValue();
}
return method;
}

public static final java.util.function.Function<List<cucumber.api.Argument>, List<?>> ARGUMENTS_TRANSFORM = arguments -> ofNullable(
Expand Down

0 comments on commit f9bb7fa

Please sign in to comment.