Skip to content

Commit dc9dfed

Browse files
authored
fix junit5 npe (via #695)
1 parent 883e5ab commit dc9dfed

File tree

3 files changed

+131
-2
lines changed

3 files changed

+131
-2
lines changed

allure-junit5/src/main/java/io/qameta/allure/junit5/AllureJunit5.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private void sendParameterEvent(final ReflectiveInvocationContext<Method> invoca
6565

6666
final Class<?> parameterType = parameter.getType();
6767
// Skip default jupiter injectables as TestInfo, TestReporter and TempDirectory
68-
if (parameterType.getPackage().getName().startsWith("org.junit.jupiter.api")) {
68+
if (parameterType.getCanonicalName().startsWith("org.junit.jupiter.api")) {
6969
continue;
7070
}
7171
final Object value = invocationContext.getArguments().get(i);

allure-junit5/src/test/java/io/qameta/allure/junit5/AllureJunit5Test.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.qameta.allure.junit5.features.AllFixtureSupport;
2525
import io.qameta.allure.junit5.features.BeforeEachFixtureFailureSupport;
2626
import io.qameta.allure.junit5.features.EachFixtureSupport;
27+
import io.qameta.allure.junit5.features.ParameterisedPrimitivesTests;
2728
import io.qameta.allure.junit5.features.ParameterisedTests;
2829
import io.qameta.allure.junit5.features.SkipOtherInjectables;
2930
import io.qameta.allure.junitplatform.AllureJunitPlatform;
@@ -54,9 +55,41 @@
5455
* @author charlie (Dmitry Baev).
5556
*/
5657
@AllureFeatures.Fixtures
57-
@SuppressWarnings("unchecked")
5858
class AllureJunit5Test {
5959

60+
@Test
61+
void shouldSupportPrimitiveTypeParameters() {
62+
final AllureResults results = runClasses(ParameterisedPrimitivesTests.class);
63+
assertThat(results.getTestResults())
64+
.extracting(TestResult::getName, tr -> tr.getParameters().size())
65+
.containsExactlyInAnyOrder(
66+
tuple("booleansMethodSource(boolean, boolean) [1] a=true, b=true", 3),
67+
tuple("booleansMethodSource(boolean, boolean) [2] a=true, b=false", 3),
68+
tuple("booleansMethodSource(boolean, boolean) [3] a=false, b=true", 3),
69+
tuple("booleansMethodSource(boolean, boolean) [4] a=false, b=false", 3),
70+
tuple("floats(float) [1] value=0.1", 2),
71+
tuple("floats(float) [2] value=0.01", 2),
72+
tuple("shorts(int) [1] value=1", 2),
73+
tuple("shorts(int) [2] value=2", 2),
74+
tuple("shorts(int) [3] value=3", 2),
75+
tuple("ints(int) [1] value=1", 2),
76+
tuple("ints(int) [2] value=2", 2),
77+
tuple("ints(int) [3] value=3", 2),
78+
tuple("bytes(byte) [1] value=0", 2),
79+
tuple("bytes(byte) [2] value=1", 2),
80+
tuple("chars(char) [1] value=a", 2),
81+
tuple("chars(char) [2] value=b", 2),
82+
tuple("chars(char) [3] value=c", 2),
83+
tuple("longs(long) [1] value=0", 2),
84+
tuple("longs(long) [2] value=1", 2),
85+
tuple("nullMethodSource(String) [1] value=null", 2),
86+
tuple("doubles(double) [1] value=0.1", 2),
87+
tuple("doubles(double) [2] value=0.01", 2),
88+
tuple("booleans(boolean) [1] value=true", 2),
89+
tuple("booleans(boolean) [2] value=false", 2)
90+
);
91+
}
92+
6093
@Test
6194
void shouldSupportParametersForParameterisedTests() {
6295
final AllureResults results = runClasses(ParameterisedTests.class);
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright 2019 Qameta Software OÜ
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.junit5.features;
17+
18+
import org.junit.jupiter.params.ParameterizedTest;
19+
import org.junit.jupiter.params.provider.Arguments;
20+
import org.junit.jupiter.params.provider.MethodSource;
21+
import org.junit.jupiter.params.provider.ValueSource;
22+
23+
import java.util.stream.Stream;
24+
25+
/**
26+
* @author charlie (Dmitry Baev).
27+
*/
28+
public class ParameterisedPrimitivesTests {
29+
30+
@ParameterizedTest
31+
@ValueSource(bytes = {0, 1})
32+
void bytes(byte value) {
33+
}
34+
35+
@ParameterizedTest
36+
@ValueSource(shorts = {1, 2, 3})
37+
void shorts(int value) {
38+
}
39+
40+
@ParameterizedTest
41+
@ValueSource(ints = {1, 2, 3})
42+
void ints(int value) {
43+
}
44+
45+
@ParameterizedTest
46+
@ValueSource(longs = {0L, 1L})
47+
void longs(long value) {
48+
}
49+
50+
@ParameterizedTest
51+
@ValueSource(floats = {0.1f, 0.01f})
52+
void floats(float value) {
53+
}
54+
55+
@ParameterizedTest
56+
@ValueSource(doubles = {0.1d, 0.01d})
57+
void doubles(double value) {
58+
}
59+
60+
@ParameterizedTest
61+
@ValueSource(chars = {'a', 'b', 'c'})
62+
void chars(char value) {
63+
}
64+
65+
@ParameterizedTest
66+
@ValueSource(booleans = {true, false})
67+
void booleans(boolean value) {
68+
}
69+
70+
@ParameterizedTest
71+
@MethodSource("arguments")
72+
void booleansMethodSource(final boolean a, final boolean b) {
73+
}
74+
75+
@ParameterizedTest
76+
@MethodSource("nulls")
77+
void nullMethodSource(final String value) {
78+
}
79+
80+
static Stream<Arguments> arguments() {
81+
return Stream.of(
82+
Arguments.of(true, true),
83+
Arguments.of(true, false),
84+
Arguments.of(false, true),
85+
Arguments.of(false, false)
86+
);
87+
}
88+
89+
static Stream<Arguments> nulls() {
90+
return Stream.of(
91+
Arguments.of((String) null)
92+
);
93+
}
94+
95+
96+
}

0 commit comments

Comments
 (0)