1
1
package org .jenkinsci .plugins .workflow .multibranch .template .finder ;
2
2
3
- import org .junit .jupiter .api .Test ;
3
+ import org .junit .jupiter .params .ParameterizedTest ;
4
+ import org .junit .jupiter .params .provider .Arguments ;
5
+ import org .junit .jupiter .params .provider .MethodSource ;
6
+
7
+ import java .util .stream .Stream ;
4
8
5
9
import static org .junit .jupiter .api .Assertions .*;
6
10
7
11
class ConfigurationValueFinderTest {
8
12
13
+ public static final String EXPECTED_RESULT = "expectedResult" ;
14
+
9
15
/**
10
16
* Simple helper method to call ConfigurationValueFinder.findFirstConfigurationValue
11
17
* to improve test readability.
@@ -18,87 +24,39 @@ private String find(String configurationContents, String keyToFind) {
18
24
return ConfigurationValueFinder .findFirstConfigurationValue (configurationContents , keyToFind );
19
25
}
20
26
21
- @ Test
22
- void findNullKeyOutOfConfigReturnsNull () {
23
- assertNull (find ("test" , null ));
24
- }
25
-
26
- @ Test
27
- void findStringKeyOutOfNullConfigReturnsNull () {
28
- assertNull (find (null , "test1" ));
29
- }
30
-
31
- @ Test
32
- void cannotFindKeyReturnsNull () {
33
- assertNull (find ("keynotfound" , "test1" ));
34
- }
35
-
36
- @ Test
37
- void findFirstKeyWithNoNewLine () {
38
- assertEquals ("hi" ,
39
- find ("nonewline:hi" , "nonewline" ));
40
- }
41
-
42
- @ Test
43
- void foundFirstKey () {
44
- assertEquals ("hi" ,
45
- find ("bare:hi\n test1:second\n test1:third" ,
46
- "bare" ));
27
+ private static Stream <Arguments > keyNotFoundProvider () {
28
+ return Stream .of (
29
+ Arguments .of ("null key" , null , "test" ),
30
+ Arguments .of ("null config" , "someKey" , null ),
31
+ Arguments .of ("key not found" , "someKey" , "keynotfound" )
32
+ );
47
33
}
48
34
49
- @ Test
50
- void foundLastKey () {
51
- assertEquals ("third" ,
52
- find ("bare:hi\n test1:second\n last:third" ,
53
- "last" ));
35
+ @ ParameterizedTest
36
+ @ MethodSource ("keyNotFoundProvider" )
37
+ void cannotFindKey (String testCase , String keyToFind , String configurationContents ) {
38
+ assertNull (find (configurationContents , keyToFind ), "Should not have found value for " + testCase );
54
39
}
55
40
56
- @ Test
57
- void foundKeyWithQuotesAroundKey () {
58
- assertEquals ("hi" ,
59
- find ("\" quotes\" :\" hi\" \n test1:second\n test1:third" ,
60
- "quotes" ));
61
- }
62
-
63
- @ Test
64
- void foundKeyWithTicksAroundKey () {
65
- assertEquals ("hi" ,
66
- find ("'ticks':'hi'\n test1:second\n test1:third" ,
67
- "ticks" ));
68
- }
69
-
70
- @ Test
71
- void foundKeyWithTicksAroundKeyAndManySpaces () {
72
- assertEquals ("hi" ,
73
- find ("'spaces' : 'hi' \n test1:second\n test1:third" ,
74
- "spaces" ));
75
- }
76
-
77
- @ Test
78
- void foundKeyWithEquals () {
79
- assertEquals ("hi" ,
80
- find ("equals=\" hi\" \n test1=second\n test2=third" ,
81
- "equals" ));
82
- }
83
-
84
- @ Test
85
- void foundLastKeyWithEquals () {
86
- assertEquals ("third" ,
87
- find ("equals=\" hi\" \n test1=second\n last=third" ,
88
- "last" ));
89
- }
90
41
91
- @ Test
92
- void foundKeyWithSpacesAroundEquals () {
93
- assertEquals ("hi" ,
94
- find ("equals_space = \" hi\" \n test1 = second\n test2 = third" ,
95
- "equals_space" ));
42
+ private static Stream <Arguments > keysFoundProvider () {
43
+ return Stream .of (
44
+ Arguments .of ("noNewLine" , "noNewLine:" + EXPECTED_RESULT ),
45
+ Arguments .of ("firstKey" , "firstKey:" + EXPECTED_RESULT + "\n test1:second\n test1:third" ),
46
+ Arguments .of ("lastKey" , "bare:hi\n test1:second\n lastKey:" + EXPECTED_RESULT ),
47
+ Arguments .of ("keyWithQuotesAround" , "\" keyWithQuotesAround\" :\" " + EXPECTED_RESULT + "\" \n test1:second\n test1:third" ),
48
+ Arguments .of ("keyWithTicksAround" , "'keyWithTicksAround':'" + EXPECTED_RESULT + "'\n test1:second\n test1:third" ),
49
+ Arguments .of ("keyWithTicksSpaces" , "'keyWithTicksSpaces' : '" + EXPECTED_RESULT + "' \n test1:second\n test1:third" ),
50
+ Arguments .of ("keyWithEqualsDelim" , "keyWithEqualsDelim=\" " + EXPECTED_RESULT + "\" \n test1=second\n test2=third" ),
51
+ Arguments .of ("lastKeyWithEqualsDelim" , "equals=\" hi\" \n test1=second\n lastKeyWithEqualsDelim=" + EXPECTED_RESULT ),
52
+ Arguments .of ("keyWithSpaceAroundEquals" , "keyWithSpaceAroundEquals = \" " + EXPECTED_RESULT + "\" \n test1 = second\n test2 = third" ),
53
+ Arguments .of ("lastKeyWithSpaceyEquals" , "equals_space = \" hi\" \n test1 = second\n lastKeyWithSpaceyEquals = " + EXPECTED_RESULT )
54
+ );
96
55
}
97
56
98
- @ Test
99
- void foundLastKeyWithSpacesAroundEquals () {
100
- assertEquals ("third" ,
101
- find ("equals_space = \" hi\" \n test1 = second\n last = third" ,
102
- "last" ));
57
+ @ ParameterizedTest
58
+ @ MethodSource ("keysFoundProvider" )
59
+ void findKey (String keyToFind , String configurationContents ) {
60
+ assertEquals (EXPECTED_RESULT , find (configurationContents , keyToFind ), "Did not find expected value for " + keyToFind );
103
61
}
104
62
}
0 commit comments