10
10
11
11
package org .junit .jupiter .params ;
12
12
13
+ import static java .lang .annotation .RetentionPolicy .RUNTIME ;
13
14
import static org .assertj .core .api .Assertions .assertThat ;
14
15
import static org .assertj .core .api .Assertions .within ;
15
16
import static org .junit .jupiter .api .Assertions .assertEquals ;
40
41
41
42
import java .lang .annotation .ElementType ;
42
43
import java .lang .annotation .Retention ;
43
- import java .lang .annotation .RetentionPolicy ;
44
44
import java .lang .annotation .Target ;
45
45
import java .util .ArrayList ;
46
46
import java .util .Arrays ;
@@ -1093,65 +1093,73 @@ private EngineExecutionResults execute(String methodName, Class<?>... methodPara
1093
1093
@ Nested
1094
1094
class RepeatableSourcesIntegrationTests {
1095
1095
1096
- @ Test
1097
- void executesWithRepeatableCsvFileSource () {
1098
- var results = execute ("testWithRepeatableCsvFileSource" , String .class , String .class );
1096
+ @ ParameterizedTest
1097
+ @ ValueSource (strings = { "testWithRepeatableCsvFileSource" , "testWithRepeatableCsvFileSourceAsMetaAnnotation" })
1098
+ void executesWithRepeatableCsvFileSource (String methodName ) {
1099
+ var results = execute (methodName , String .class , String .class );
1099
1100
results .allEvents ().assertThatEvents () //
1100
1101
.haveExactly (1 ,
1101
1102
event (test (), displayName ("[1] column1=foo, column2=1" ), finishedWithFailure (message ("foo 1" )))) //
1102
1103
.haveExactly (1 , event (test (), displayName ("[5] column1=FRUIT = apple, column2=RANK = 1" ),
1103
1104
finishedWithFailure (message ("apple 1" ))));
1104
1105
}
1105
1106
1106
- @ Test
1107
- void executesWithRepeatableCsvSource () {
1108
- var results = execute ("testWithRepeatableCsvSource" , String .class );
1107
+ @ ParameterizedTest
1108
+ @ ValueSource (strings = { "testWithRepeatableCsvSource" , "testWithRepeatableCsvSourceAsMetaAnnotation" })
1109
+ void executesWithRepeatableCsvSource (String methodName ) {
1110
+ var results = execute (methodName , String .class );
1109
1111
results .allEvents ().assertThatEvents () //
1110
1112
.haveExactly (1 , event (test (), displayName ("[1] argument=a" ), finishedWithFailure (message ("a" )))) //
1111
1113
.haveExactly (1 , event (test (), displayName ("[2] argument=b" ), finishedWithFailure (message ("b" ))));
1112
1114
}
1113
1115
1114
- @ Test
1115
- void executesWithRepeatableMethodSource () {
1116
- var results = execute ("testWithRepeatableMethodSource" , String .class );
1116
+ @ ParameterizedTest
1117
+ @ ValueSource (strings = { "testWithRepeatableMethodSource" , "testWithRepeatableMethodSourceAsMetaAnnotation" })
1118
+ void executesWithRepeatableMethodSource (String methodName ) {
1119
+ var results = execute (methodName , String .class );
1117
1120
results .allEvents ().assertThatEvents () //
1118
1121
.haveExactly (1 ,
1119
1122
event (test (), displayName ("[1] argument=some" ), finishedWithFailure (message ("some" )))) //
1120
1123
.haveExactly (1 ,
1121
1124
event (test (), displayName ("[2] argument=other" ), finishedWithFailure (message ("other" ))));
1122
1125
}
1123
1126
1124
- @ Test
1125
- void executesWithRepeatableEnumSource () {
1126
- var results = execute ("testWithRepeatableEnumSource" , Action .class );
1127
+ @ ParameterizedTest
1128
+ @ ValueSource (strings = { "testWithRepeatableEnumSource" , "testWithRepeatableEnumSourceAsMetaAnnotation" })
1129
+ void executesWithRepeatableEnumSource (String methodName ) {
1130
+ var results = execute (methodName , Action .class );
1127
1131
results .allEvents ().assertThatEvents () //
1128
1132
.haveExactly (1 , event (test (), displayName ("[1] argument=FOO" ), finishedWithFailure (message ("FOO" )))) //
1129
1133
.haveExactly (1 ,
1130
1134
event (test (), displayName ("[2] argument=BAR" ), finishedWithFailure (message ("BAR" ))));
1131
1135
}
1132
1136
1133
- @ Test
1134
- void executesWithRepeatableValueSource () {
1135
- var results = execute ("testWithRepeatableValueSource" , String .class );
1137
+ @ ParameterizedTest
1138
+ @ ValueSource (strings = { "testWithRepeatableValueSource" , "testWithRepeatableValueSourceAsMetaAnnotation" })
1139
+ void executesWithRepeatableValueSource (String methodName ) {
1140
+ var results = execute (methodName , String .class );
1136
1141
results .allEvents ().assertThatEvents () //
1137
1142
.haveExactly (1 , event (test (), displayName ("[1] argument=foo" ), finishedWithFailure (message ("foo" )))) //
1138
1143
.haveExactly (1 ,
1139
1144
event (test (), displayName ("[2] argument=bar" ), finishedWithFailure (message ("bar" ))));
1140
1145
}
1141
1146
1142
- @ Test
1143
- void executesWithRepeatableFieldSource () {
1144
- var results = execute ("testWithRepeatableFieldSource" , String .class );
1147
+ @ ParameterizedTest
1148
+ @ ValueSource (strings = { "testWithRepeatableFieldSource" , "testWithRepeatableFieldSourceAsMetaAnnotation" })
1149
+ void executesWithRepeatableFieldSource (String methodName ) {
1150
+ var results = execute (methodName , String .class );
1145
1151
results .allEvents ().assertThatEvents () //
1146
1152
.haveExactly (1 ,
1147
1153
event (test (), displayName ("[1] argument=some" ), finishedWithFailure (message ("some" )))) //
1148
1154
.haveExactly (1 ,
1149
1155
event (test (), displayName ("[2] argument=other" ), finishedWithFailure (message ("other" ))));
1150
1156
}
1151
1157
1152
- @ Test
1153
- void executesWithRepeatableArgumentsSource () {
1154
- var results = execute ("testWithRepeatableArgumentsSource" , String .class );
1158
+ @ ParameterizedTest
1159
+ @ ValueSource (strings = { "testWithRepeatableArgumentsSource" ,
1160
+ "testWithRepeatableArgumentsSourceAsMetaAnnotation" })
1161
+ void executesWithRepeatableArgumentsSource (String methodName ) {
1162
+ var results = execute (methodName , String .class );
1155
1163
results .allEvents ().assertThatEvents () //
1156
1164
.haveExactly (1 , event (test (), displayName ("[1] argument=foo" ), finishedWithFailure (message ("foo" )))) //
1157
1165
.haveExactly (1 , event (test (), displayName ("[2] argument=bar" ), finishedWithFailure (message ("bar" )))) //
@@ -1542,7 +1550,7 @@ void testWithNullAndEmptySourceForTwoDimensionalStringArray(String[][] argument)
1542
1550
static class MethodSourceTestCase {
1543
1551
1544
1552
@ Target (ElementType .METHOD )
1545
- @ Retention (RetentionPolicy . RUNTIME )
1553
+ @ Retention (RUNTIME )
1546
1554
@ ParameterizedTest (name = "{arguments}" )
1547
1555
@ MethodSource
1548
1556
@interface MethodSourceTest {
@@ -1767,7 +1775,7 @@ private static Stream<String> test() {
1767
1775
static class FieldSourceTestCase {
1768
1776
1769
1777
@ Target (ElementType .METHOD )
1770
- @ Retention (RetentionPolicy . RUNTIME )
1778
+ @ Retention (RUNTIME )
1771
1779
@ ParameterizedTest (name = "{arguments}" )
1772
1780
@ FieldSource
1773
1781
@interface FieldSourceTest {
@@ -2035,20 +2043,56 @@ void testWithRepeatableCsvFileSource(String column1, String column2) {
2035
2043
fail ("%s %s" .formatted (column1 , column2 ));
2036
2044
}
2037
2045
2046
+ @ CsvFileSource (resources = "two-column.csv" )
2047
+ @ CsvFileSource (resources = "two-column-with-headers.csv" , delimiter = '|' , useHeadersInDisplayName = true , nullValues = "NIL" )
2048
+ @ Retention (RUNTIME )
2049
+ @interface TwoCsvFileSources {
2050
+ }
2051
+
2052
+ @ ParameterizedTest
2053
+ @ TwoCsvFileSources
2054
+ void testWithRepeatableCsvFileSourceAsMetaAnnotation (String column1 , String column2 ) {
2055
+ fail ("%s %s" .formatted (column1 , column2 ));
2056
+ }
2057
+
2038
2058
@ ParameterizedTest
2039
2059
@ CsvSource ({ "a" })
2040
2060
@ CsvSource ({ "b" })
2041
2061
void testWithRepeatableCsvSource (String argument ) {
2042
2062
fail (argument );
2043
2063
}
2044
2064
2065
+ @ CsvSource ({ "a" })
2066
+ @ CsvSource ({ "b" })
2067
+ @ Retention (RUNTIME )
2068
+ @interface TwoCsvSources {
2069
+ }
2070
+
2071
+ @ ParameterizedTest
2072
+ @ TwoCsvSources
2073
+ void testWithRepeatableCsvSourceAsMetaAnnotation (String argument ) {
2074
+ fail (argument );
2075
+ }
2076
+
2045
2077
@ ParameterizedTest
2046
2078
@ EnumSource (SmartAction .class )
2047
2079
@ EnumSource (QuickAction .class )
2048
2080
void testWithRepeatableEnumSource (Action argument ) {
2049
2081
fail (argument .toString ());
2050
2082
}
2051
2083
2084
+ @ EnumSource (SmartAction .class )
2085
+ @ EnumSource (QuickAction .class )
2086
+ @ Retention (RUNTIME )
2087
+ @interface TwoEnumSources {
2088
+ }
2089
+
2090
+ @ ParameterizedTest
2091
+ @ TwoEnumSources
2092
+ void testWithRepeatableEnumSourceAsMetaAnnotation (Action argument ) {
2093
+ fail (argument .toString ());
2094
+ }
2095
+
2052
2096
interface Action {
2053
2097
}
2054
2098
@@ -2067,6 +2111,18 @@ void testWithRepeatableMethodSource(String argument) {
2067
2111
fail (argument );
2068
2112
}
2069
2113
2114
+ @ MethodSource ("someArgumentsMethodSource" )
2115
+ @ MethodSource ("otherArgumentsMethodSource" )
2116
+ @ Retention (RUNTIME )
2117
+ @interface TwoMethodSources {
2118
+ }
2119
+
2120
+ @ ParameterizedTest
2121
+ @ TwoMethodSources
2122
+ void testWithRepeatableMethodSourceAsMetaAnnotation (String argument ) {
2123
+ fail (argument );
2124
+ }
2125
+
2070
2126
public static Stream <Arguments > someArgumentsMethodSource () {
2071
2127
return Stream .of (Arguments .of ("some" ));
2072
2128
}
@@ -2082,6 +2138,18 @@ void testWithRepeatableFieldSource(String argument) {
2082
2138
fail (argument );
2083
2139
}
2084
2140
2141
+ @ FieldSource ("someArgumentsContainer" )
2142
+ @ FieldSource ("otherArgumentsContainer" )
2143
+ @ Retention (RUNTIME )
2144
+ @interface TwoFieldSources {
2145
+ }
2146
+
2147
+ @ ParameterizedTest
2148
+ @ TwoFieldSources
2149
+ void testWithRepeatableFieldSourceAsMetaAnnotation (String argument ) {
2150
+ fail (argument );
2151
+ }
2152
+
2085
2153
static List <String > someArgumentsContainer = List .of ("some" );
2086
2154
static List <String > otherArgumentsContainer = List .of ("other" );
2087
2155
@@ -2092,6 +2160,18 @@ void testWithRepeatableValueSource(String argument) {
2092
2160
fail (argument );
2093
2161
}
2094
2162
2163
+ @ ValueSource (strings = "foo" )
2164
+ @ ValueSource (strings = "bar" )
2165
+ @ Retention (RUNTIME )
2166
+ @interface TwoValueSources {
2167
+ }
2168
+
2169
+ @ ParameterizedTest
2170
+ @ TwoValueSources
2171
+ void testWithRepeatableValueSourceAsMetaAnnotation (String argument ) {
2172
+ fail (argument );
2173
+ }
2174
+
2095
2175
@ ParameterizedTest
2096
2176
@ ValueSource (strings = "foo" )
2097
2177
@ ValueSource (strings = "foo" )
@@ -2117,6 +2197,18 @@ void testWithDifferentRepeatableAnnotations(String argument) {
2117
2197
void testWithRepeatableArgumentsSource (String argument ) {
2118
2198
fail (argument );
2119
2199
}
2200
+
2201
+ @ ArgumentsSource (TwoSingleStringArgumentsProvider .class )
2202
+ @ ArgumentsSource (TwoUnusedStringArgumentsProvider .class )
2203
+ @ Retention (RUNTIME )
2204
+ @interface TwoArgumentsSources {
2205
+ }
2206
+
2207
+ @ ParameterizedTest
2208
+ @ TwoArgumentsSources
2209
+ void testWithRepeatableArgumentsSourceAsMetaAnnotation (String argument ) {
2210
+ fail (argument );
2211
+ }
2120
2212
}
2121
2213
2122
2214
private static class TwoSingleStringArgumentsProvider implements ArgumentsProvider {
0 commit comments