Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,34 @@ public static List<Parameter> getParameters(final MethodSignature signature, fin
}).collect(Collectors.toList());
}

@SuppressWarnings({
"CyclomaticComplexity",
"ReturnCount",
"PMD.NcssCount",
"PMD.CyclomaticComplexity"
})
public static String objectToString(final Object object) {
try {
if (Objects.nonNull(object) && (object instanceof Object[])) {
return Arrays.toString((Object[]) object);
if (Objects.nonNull(object) && object.getClass().isArray()) {
if (object instanceof Object[]) {
return Arrays.toString((Object[]) object);
} else if (object instanceof long[]) {
return Arrays.toString((long[]) object);
} else if (object instanceof short[]) {
return Arrays.toString((short[]) object);
} else if (object instanceof int[]) {
return Arrays.toString((int[]) object);
} else if (object instanceof char[]) {
return Arrays.toString((char[]) object);
} else if (object instanceof double[]) {
return Arrays.toString((double[]) object);
} else if (object instanceof float[]) {
return Arrays.toString((float[]) object);
} else if (object instanceof boolean[]) {
return Arrays.toString((boolean[]) object);
} else if (object instanceof byte[]) {
return Arrays.toString((byte[]) object);
}
}
return Objects.toString(object);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.qameta.allure.model.StatusDetails;
import io.qameta.allure.model.TestResult;
import io.qameta.allure.model.TestResultContainer;
import io.qameta.allure.util.AspectUtils;
import io.qameta.allure.util.ResultsUtils;
import org.testng.IAttributes;
import org.testng.IClass;
Expand Down Expand Up @@ -640,21 +641,14 @@ private List<Parameter> getParameters(final ITestResult testResult) {
.map(java.lang.reflect.Parameter::getName)
.toArray(String[]::new);
final String[] parameterValues = Stream.of(testResult.getParameters())
.map(this::convertParameterValueToString)
.map(AspectUtils::objectToString)
.toArray(String[]::new);
final Stream<Parameter> methodParameters = range(0, min(parameterNames.length, parameterValues.length))
.mapToObj(i -> new Parameter().setName(parameterNames[i]).setValue(parameterValues[i]));
return Stream.concat(tagsParameters, methodParameters)
.collect(Collectors.toList());
}

private String convertParameterValueToString(final Object parameter) {
if (Objects.nonNull(parameter) && parameter.getClass().isArray()) {
return Arrays.toString((Object[]) parameter);
}
return Objects.toString(parameter);
}

private String getMethodName(final ITestNGMethod method) {
return firstNonEmpty(
method.getDescription(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,38 @@ public void shouldDisplayDisabledTests() {

}

@SuppressWarnings("unchecked")
@Feature("Parameters")
@Issue("129")
@Test
public void shouldNotFailForNullParameters() {
final AllureResults results = runTestNgSuites("suites/gh-129.xml");

assertThat(results.getTestResults())
.flatExtracting(TestResult::getParameters)
.extracting(Parameter::getName, Parameter::getValue)
.containsExactly(
tuple("arg0", "null")
);
}

@SuppressWarnings("unchecked")
@Feature("Parameters")
@Issue("128")
@Test
public void shouldProcessArrayParameters() {
final AllureResults results = runTestNgSuites("suites/gh-128.xml");

assertThat(results.getTestResults())
.flatExtracting(TestResult::getParameters)
.extracting(Parameter::getName, Parameter::getValue)
.containsExactly(
tuple("arg0", "a"),
tuple("arg1", "false"),
tuple("arg2", "[1, 2, 3]")
);
}

private AllureResults runTestNgSuites(final String... suites) {
final Consumer<TestNG> emptyConfigurer = testNg -> {
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.qameta.allure.testng.samples;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

/**
* @author charlie (Dmitry Baev).
*/
public class DataProviderWithArray {

@DataProvider(name = "someProvider")
public static Object[][] someProvider() {
return new Object[][]{
new Object[]{"a", false, new int[]{1, 2, 3}}
};
}

@Test(dataProvider = "someProvider")
public void someTest(final String first, final boolean second, final int[] third) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.qameta.allure.testng.samples;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

/**
* @author charlie (Dmitry Baev).
*/
public class NullParamTest {

@DataProvider(name = "someProvider")
public static Object[][] someProvider() {
return new Object[][]{
new Object[]{null}
};
}

@Test(dataProvider = "someProvider")
public void someTest(final String param) {
}
}
10 changes: 10 additions & 0 deletions allure-testng/src/test/resources/suites/gh-128.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Github Issues">
<test name="gh-128">
<classes>
<class name="io.qameta.allure.testng.samples.DataProviderWithArray"/>
</classes>
</test>
</suite>
10 changes: 10 additions & 0 deletions allure-testng/src/test/resources/suites/gh-129.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Github Issues">
<test name="gh-129">
<classes>
<class name="io.qameta.allure.testng.samples.NullParamTest"/>
</classes>
</test>
</suite>