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 .lang .reflect .Constructor ;
46
46
import java .util .ArrayList ;
@@ -1096,65 +1096,73 @@ private EngineExecutionResults execute(String methodName, Class<?>... methodPara
1096
1096
@ Nested
1097
1097
class RepeatableSourcesIntegrationTests {
1098
1098
1099
- @ Test
1100
- void executesWithRepeatableCsvFileSource () {
1101
- var results = execute ("testWithRepeatableCsvFileSource" , String .class , String .class );
1099
+ @ ParameterizedTest
1100
+ @ ValueSource (strings = { "testWithRepeatableCsvFileSource" , "testWithRepeatableCsvFileSourceAsMetaAnnotation" })
1101
+ void executesWithRepeatableCsvFileSource (String methodName ) {
1102
+ var results = execute (methodName , String .class , String .class );
1102
1103
results .allEvents ().assertThatEvents () //
1103
1104
.haveExactly (1 ,
1104
1105
event (test (), displayName ("[1] column1=foo, column2=1" ), finishedWithFailure (message ("foo 1" )))) //
1105
1106
.haveExactly (1 , event (test (), displayName ("[5] column1=FRUIT = apple, column2=RANK = 1" ),
1106
1107
finishedWithFailure (message ("apple 1" ))));
1107
1108
}
1108
1109
1109
- @ Test
1110
- void executesWithRepeatableCsvSource () {
1111
- var results = execute ("testWithRepeatableCsvSource" , String .class );
1110
+ @ ParameterizedTest
1111
+ @ ValueSource (strings = { "testWithRepeatableCsvSource" , "testWithRepeatableCsvSourceAsMetaAnnotation" })
1112
+ void executesWithRepeatableCsvSource (String methodName ) {
1113
+ var results = execute (methodName , String .class );
1112
1114
results .allEvents ().assertThatEvents () //
1113
1115
.haveExactly (1 , event (test (), displayName ("[1] argument=a" ), finishedWithFailure (message ("a" )))) //
1114
1116
.haveExactly (1 , event (test (), displayName ("[2] argument=b" ), finishedWithFailure (message ("b" ))));
1115
1117
}
1116
1118
1117
- @ Test
1118
- void executesWithRepeatableMethodSource () {
1119
- var results = execute ("testWithRepeatableMethodSource" , String .class );
1119
+ @ ParameterizedTest
1120
+ @ ValueSource (strings = { "testWithRepeatableMethodSource" , "testWithRepeatableMethodSourceAsMetaAnnotation" })
1121
+ void executesWithRepeatableMethodSource (String methodName ) {
1122
+ var results = execute (methodName , String .class );
1120
1123
results .allEvents ().assertThatEvents () //
1121
1124
.haveExactly (1 ,
1122
1125
event (test (), displayName ("[1] argument=some" ), finishedWithFailure (message ("some" )))) //
1123
1126
.haveExactly (1 ,
1124
1127
event (test (), displayName ("[2] argument=other" ), finishedWithFailure (message ("other" ))));
1125
1128
}
1126
1129
1127
- @ Test
1128
- void executesWithRepeatableEnumSource () {
1129
- var results = execute ("testWithRepeatableEnumSource" , Action .class );
1130
+ @ ParameterizedTest
1131
+ @ ValueSource (strings = { "testWithRepeatableEnumSource" , "testWithRepeatableEnumSourceAsMetaAnnotation" })
1132
+ void executesWithRepeatableEnumSource (String methodName ) {
1133
+ var results = execute (methodName , Action .class );
1130
1134
results .allEvents ().assertThatEvents () //
1131
1135
.haveExactly (1 , event (test (), displayName ("[1] argument=FOO" ), finishedWithFailure (message ("FOO" )))) //
1132
1136
.haveExactly (1 ,
1133
1137
event (test (), displayName ("[2] argument=BAR" ), finishedWithFailure (message ("BAR" ))));
1134
1138
}
1135
1139
1136
- @ Test
1137
- void executesWithRepeatableValueSource () {
1138
- var results = execute ("testWithRepeatableValueSource" , String .class );
1140
+ @ ParameterizedTest
1141
+ @ ValueSource (strings = { "testWithRepeatableValueSource" , "testWithRepeatableValueSourceAsMetaAnnotation" })
1142
+ void executesWithRepeatableValueSource (String methodName ) {
1143
+ var results = execute (methodName , String .class );
1139
1144
results .allEvents ().assertThatEvents () //
1140
1145
.haveExactly (1 , event (test (), displayName ("[1] argument=foo" ), finishedWithFailure (message ("foo" )))) //
1141
1146
.haveExactly (1 ,
1142
1147
event (test (), displayName ("[2] argument=bar" ), finishedWithFailure (message ("bar" ))));
1143
1148
}
1144
1149
1145
- @ Test
1146
- void executesWithRepeatableFieldSource () {
1147
- var results = execute ("testWithRepeatableFieldSource" , String .class );
1150
+ @ ParameterizedTest
1151
+ @ ValueSource (strings = { "testWithRepeatableFieldSource" , "testWithRepeatableFieldSourceAsMetaAnnotation" })
1152
+ void executesWithRepeatableFieldSource (String methodName ) {
1153
+ var results = execute (methodName , String .class );
1148
1154
results .allEvents ().assertThatEvents () //
1149
1155
.haveExactly (1 ,
1150
1156
event (test (), displayName ("[1] argument=some" ), finishedWithFailure (message ("some" )))) //
1151
1157
.haveExactly (1 ,
1152
1158
event (test (), displayName ("[2] argument=other" ), finishedWithFailure (message ("other" ))));
1153
1159
}
1154
1160
1155
- @ Test
1156
- void executesWithRepeatableArgumentsSource () {
1157
- var results = execute ("testWithRepeatableArgumentsSource" , String .class );
1161
+ @ ParameterizedTest
1162
+ @ ValueSource (strings = { "testWithRepeatableArgumentsSource" ,
1163
+ "testWithRepeatableArgumentsSourceAsMetaAnnotation" })
1164
+ void executesWithRepeatableArgumentsSource (String methodName ) {
1165
+ var results = execute (methodName , String .class );
1158
1166
results .allEvents ().assertThatEvents () //
1159
1167
.haveExactly (1 , event (test (), displayName ("[1] argument=foo" ), finishedWithFailure (message ("foo" )))) //
1160
1168
.haveExactly (1 , event (test (), displayName ("[2] argument=bar" ), finishedWithFailure (message ("bar" )))) //
@@ -1574,7 +1582,7 @@ void testWithNullAndEmptySourceForTwoDimensionalStringArray(String[][] argument)
1574
1582
static class MethodSourceTestCase {
1575
1583
1576
1584
@ Target (ElementType .METHOD )
1577
- @ Retention (RetentionPolicy . RUNTIME )
1585
+ @ Retention (RUNTIME )
1578
1586
@ ParameterizedTest (name = "{arguments}" )
1579
1587
@ MethodSource
1580
1588
@interface MethodSourceTest {
@@ -1799,7 +1807,7 @@ private static Stream<String> test() {
1799
1807
static class FieldSourceTestCase {
1800
1808
1801
1809
@ Target (ElementType .METHOD )
1802
- @ Retention (RetentionPolicy . RUNTIME )
1810
+ @ Retention (RUNTIME )
1803
1811
@ ParameterizedTest (name = "{arguments}" )
1804
1812
@ FieldSource
1805
1813
@interface FieldSourceTest {
@@ -2067,20 +2075,56 @@ void testWithRepeatableCsvFileSource(String column1, String column2) {
2067
2075
fail ("%s %s" .formatted (column1 , column2 ));
2068
2076
}
2069
2077
2078
+ @ CsvFileSource (resources = "two-column.csv" )
2079
+ @ CsvFileSource (resources = "two-column-with-headers.csv" , delimiter = '|' , useHeadersInDisplayName = true , nullValues = "NIL" )
2080
+ @ Retention (RUNTIME )
2081
+ @interface TwoCsvFileSources {
2082
+ }
2083
+
2084
+ @ ParameterizedTest
2085
+ @ TwoCsvFileSources
2086
+ void testWithRepeatableCsvFileSourceAsMetaAnnotation (String column1 , String column2 ) {
2087
+ fail ("%s %s" .formatted (column1 , column2 ));
2088
+ }
2089
+
2070
2090
@ ParameterizedTest
2071
2091
@ CsvSource ({ "a" })
2072
2092
@ CsvSource ({ "b" })
2073
2093
void testWithRepeatableCsvSource (String argument ) {
2074
2094
fail (argument );
2075
2095
}
2076
2096
2097
+ @ CsvSource ({ "a" })
2098
+ @ CsvSource ({ "b" })
2099
+ @ Retention (RUNTIME )
2100
+ @interface TwoCsvSources {
2101
+ }
2102
+
2103
+ @ ParameterizedTest
2104
+ @ TwoCsvSources
2105
+ void testWithRepeatableCsvSourceAsMetaAnnotation (String argument ) {
2106
+ fail (argument );
2107
+ }
2108
+
2077
2109
@ ParameterizedTest
2078
2110
@ EnumSource (SmartAction .class )
2079
2111
@ EnumSource (QuickAction .class )
2080
2112
void testWithRepeatableEnumSource (Action argument ) {
2081
2113
fail (argument .toString ());
2082
2114
}
2083
2115
2116
+ @ EnumSource (SmartAction .class )
2117
+ @ EnumSource (QuickAction .class )
2118
+ @ Retention (RUNTIME )
2119
+ @interface TwoEnumSources {
2120
+ }
2121
+
2122
+ @ ParameterizedTest
2123
+ @ TwoEnumSources
2124
+ void testWithRepeatableEnumSourceAsMetaAnnotation (Action argument ) {
2125
+ fail (argument .toString ());
2126
+ }
2127
+
2084
2128
interface Action {
2085
2129
}
2086
2130
@@ -2099,6 +2143,18 @@ void testWithRepeatableMethodSource(String argument) {
2099
2143
fail (argument );
2100
2144
}
2101
2145
2146
+ @ MethodSource ("someArgumentsMethodSource" )
2147
+ @ MethodSource ("otherArgumentsMethodSource" )
2148
+ @ Retention (RUNTIME )
2149
+ @interface TwoMethodSources {
2150
+ }
2151
+
2152
+ @ ParameterizedTest
2153
+ @ TwoMethodSources
2154
+ void testWithRepeatableMethodSourceAsMetaAnnotation (String argument ) {
2155
+ fail (argument );
2156
+ }
2157
+
2102
2158
public static Stream <Arguments > someArgumentsMethodSource () {
2103
2159
return Stream .of (Arguments .of ("some" ));
2104
2160
}
@@ -2114,6 +2170,18 @@ void testWithRepeatableFieldSource(String argument) {
2114
2170
fail (argument );
2115
2171
}
2116
2172
2173
+ @ FieldSource ("someArgumentsContainer" )
2174
+ @ FieldSource ("otherArgumentsContainer" )
2175
+ @ Retention (RUNTIME )
2176
+ @interface TwoFieldSources {
2177
+ }
2178
+
2179
+ @ ParameterizedTest
2180
+ @ TwoFieldSources
2181
+ void testWithRepeatableFieldSourceAsMetaAnnotation (String argument ) {
2182
+ fail (argument );
2183
+ }
2184
+
2117
2185
static List <String > someArgumentsContainer = List .of ("some" );
2118
2186
static List <String > otherArgumentsContainer = List .of ("other" );
2119
2187
@@ -2124,6 +2192,18 @@ void testWithRepeatableValueSource(String argument) {
2124
2192
fail (argument );
2125
2193
}
2126
2194
2195
+ @ ValueSource (strings = "foo" )
2196
+ @ ValueSource (strings = "bar" )
2197
+ @ Retention (RUNTIME )
2198
+ @interface TwoValueSources {
2199
+ }
2200
+
2201
+ @ ParameterizedTest
2202
+ @ TwoValueSources
2203
+ void testWithRepeatableValueSourceAsMetaAnnotation (String argument ) {
2204
+ fail (argument );
2205
+ }
2206
+
2127
2207
@ ParameterizedTest
2128
2208
@ ValueSource (strings = "foo" )
2129
2209
@ ValueSource (strings = "foo" )
@@ -2149,6 +2229,18 @@ void testWithDifferentRepeatableAnnotations(String argument) {
2149
2229
void testWithRepeatableArgumentsSource (String argument ) {
2150
2230
fail (argument );
2151
2231
}
2232
+
2233
+ @ ArgumentsSource (TwoSingleStringArgumentsProvider .class )
2234
+ @ ArgumentsSource (TwoUnusedStringArgumentsProvider .class )
2235
+ @ Retention (RUNTIME )
2236
+ @interface TwoArgumentsSources {
2237
+ }
2238
+
2239
+ @ ParameterizedTest
2240
+ @ TwoArgumentsSources
2241
+ void testWithRepeatableArgumentsSourceAsMetaAnnotation (String argument ) {
2242
+ fail (argument );
2243
+ }
2152
2244
}
2153
2245
2154
2246
static class SpiParameterInjectionTestCase {
0 commit comments