Skip to content

Commit

Permalink
Fix for allure-framework#893 - param annotation name not coming up in…
Browse files Browse the repository at this point in the history
… report
  • Loading branch information
mr-possible committed Sep 22, 2024
1 parent 3d361dd commit faf1d12
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.qameta.allure.Muted;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Param;
import io.qameta.allure.model.FixtureResult;
import io.qameta.allure.model.Label;
import io.qameta.allure.model.Link;
Expand Down Expand Up @@ -74,6 +75,7 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static io.qameta.allure.util.ResultsUtils.ALLURE_ID_LABEL_NAME;
Expand Down Expand Up @@ -779,9 +781,23 @@ private List<Parameter> getParameters(final ITestContext context,
.map(Parameters::value)
.orElse(new String[]{});

final String[] reflectionNames = Stream.of(m.getParameters())
.map(java.lang.reflect.Parameter::getName)
.toArray(String[]::new);
final List<Parameter> reflectionNames = IntStream
.range(0, parameters.length)
.mapToObj(index -> {
final Parameter parameter = createParameter(m.getParameters()[index].getName(), parameters[index]);
Stream.of(m.getParameters()[index].getAnnotationsByType(Param.class))
.findFirst()
.ifPresent(param -> {
Stream.of(param.name().trim())
.map(String::trim)
.filter(name -> !name.isEmpty())
.findFirst()
.ifPresent(parameter::setName);
parameter.setMode(param.mode());
parameter.setExcluded(param.excluded());
});
return parameter;
}).collect(Collectors.toList());

int skippedCount = 0;
for (int i = 0; i < parameterTypes.length; i++) {
Expand All @@ -797,8 +813,8 @@ private List<Parameter> getParameters(final ITestContext context,
continue;
}

if (i < reflectionNames.length) {
result.put(reflectionNames[i], ObjectUtils.toString(parameters[i]));
if (i < reflectionNames.size()) {
result.put(reflectionNames.get(i).getName(), ObjectUtils.toString(parameters[i]));
}
}

Expand Down

0 comments on commit faf1d12

Please sign in to comment.