4
4
import static org .hamcrest .MatcherAssert .assertThat ;
5
5
import static org .hamcrest .Matchers .is ;
6
6
import static org .hamcrest .core .IsNot .not ;
7
- import static org .junit .Assert .assertEquals ;
8
- import static org .junit .Assert .assertNotNull ;
9
- import static org .junit .Assert .assertTrue ;
7
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
8
+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
9
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
10
+ import static org .junit .jupiter .api .Assertions .fail ;
10
11
11
12
import com .cloudbees .jenkins .plugins .sshcredentials .impl .BasicSSHUserPrivateKey ;
12
13
import com .cloudbees .plugins .credentials .CredentialsProvider ;
20
21
import io .jenkins .plugins .casc .impl .configurators .DataBoundConfigurator ;
21
22
import io .jenkins .plugins .casc .misc .ConfiguredWithCode ;
22
23
import io .jenkins .plugins .casc .misc .JenkinsConfiguredWithCodeRule ;
24
+ import io .jenkins .plugins .casc .misc .junit .jupiter .WithJenkinsConfiguredWithCode ;
23
25
import io .jenkins .plugins .casc .model .CNode ;
24
26
import io .jenkins .plugins .casc .model .Mapping ;
25
27
import java .util .Collections ;
26
28
import java .util .List ;
27
29
import java .util .Set ;
28
30
import jenkins .model .Jenkins ;
29
- import org .junit .Rule ;
30
- import org .junit .Test ;
31
+ import org .junit .jupiter .api .Test ;
31
32
import org .jvnet .hudson .test .Issue ;
32
33
33
- public class CredentialsTest {
34
-
35
- @ Rule
36
- public JenkinsConfiguredWithCodeRule j = new JenkinsConfiguredWithCodeRule ();
34
+ @ WithJenkinsConfiguredWithCode
35
+ class CredentialsTest {
37
36
38
37
@ ConfiguredWithCode ("GlobalCredentials.yml" )
39
38
@ Test
40
- public void testGlobalScopedCredentials () throws Exception {
39
+ void testGlobalScopedCredentials (JenkinsConfiguredWithCodeRule j ) throws Exception {
41
40
List <StandardUsernamePasswordCredentials > creds = CredentialsProvider .lookupCredentials (
42
41
StandardUsernamePasswordCredentials .class , Jenkins .getInstanceOrNull (), null , Collections .emptyList ());
43
42
assertThat (creds .size (), is (1 ));
@@ -60,7 +59,7 @@ public void testGlobalScopedCredentials() throws Exception {
60
59
61
60
@ ConfiguredWithCode ("CredentialsWithDomain.yml" )
62
61
@ Test
63
- public void testDomainScopedCredentials () throws Exception {
62
+ void testDomainScopedCredentials (JenkinsConfiguredWithCodeRule j ) throws Exception {
64
63
List <StandardUsernamePasswordCredentials > creds = CredentialsProvider .lookupCredentials (
65
64
StandardUsernamePasswordCredentials .class , Jenkins .getInstanceOrNull (), null , Collections .emptyList ());
66
65
assertThat (creds .size (), is (1 ));
@@ -71,7 +70,7 @@ public void testDomainScopedCredentials() throws Exception {
71
70
72
71
@ Test
73
72
@ ConfiguredWithCode ("GlobalCredentials.yml" )
74
- public void testExportFileCredentials () throws Exception {
73
+ void testExportFileCredentials (JenkinsConfiguredWithCodeRule j ) throws Exception {
75
74
ConfiguratorRegistry registry = ConfiguratorRegistry .get ();
76
75
ConfigurationContext context = new ConfigurationContext (registry );
77
76
CredentialsRootConfigurator root = ExtensionList .lookupSingleton (CredentialsRootConfigurator .class );
@@ -101,7 +100,7 @@ public void testExportFileCredentials() throws Exception {
101
100
102
101
@ ConfiguredWithCode ("GlobalCredentials.yml" )
103
102
@ Test
104
- public void testExportSSHCredentials () throws Exception {
103
+ void testExportSSHCredentials (JenkinsConfiguredWithCodeRule j ) throws Exception {
105
104
ConfiguratorRegistry registry = ConfiguratorRegistry .get ();
106
105
ConfigurationContext context = new ConfigurationContext (registry );
107
106
CredentialsRootConfigurator root = ExtensionList .lookupSingleton (CredentialsRootConfigurator .class );
@@ -149,11 +148,11 @@ public void testExportSSHCredentials() throws Exception {
149
148
150
149
@ Test
151
150
@ Issue ("SECURITY-1404" )
152
- public void checkUsernamePasswordIsSecret () throws Exception {
151
+ void checkUsernamePasswordIsSecret (JenkinsConfiguredWithCodeRule j ) throws Exception {
153
152
Attribute a = getFromDatabound (UsernamePasswordCredentialsImpl .class , "password" );
154
153
assertTrue (
155
- "Attribute 'password' should be secret" ,
156
- a . isSecret ( new UsernamePasswordCredentialsImpl ( CredentialsScope . GLOBAL , "1" , "2" , "3" , "4" )) );
154
+ a . isSecret ( new UsernamePasswordCredentialsImpl ( CredentialsScope . GLOBAL , "1" , "2" , "3" , "4" )) ,
155
+ "Attribute 'password' should be secret" );
157
156
}
158
157
159
158
@ NonNull
@@ -165,6 +164,6 @@ public void checkUsernamePasswordIsSecret() throws Exception {
165
164
return a ;
166
165
}
167
166
}
168
- throw new AssertionError ("Cannot find databound attribute " + attributeName + " in " + clazz );
167
+ return fail ("Cannot find databound attribute " + attributeName + " in " + clazz );
169
168
}
170
169
}
0 commit comments