1
1
package hudson .plugins .locale ;
2
2
3
- import static org .junit .Assert .assertEquals ;
4
- import static org .junit .Assert .assertNull ;
3
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+ import static org .junit .jupiter .api .Assertions .assertNull ;
5
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
5
6
6
7
import hudson .util .ListBoxModel ;
7
8
import java .util .Arrays ;
8
9
import java .util .HashSet ;
9
10
import java .util .Locale ;
10
11
import java .util .Set ;
11
12
import jenkins .model .Jenkins ;
12
- import org .junit .Before ;
13
- import org .junit .Rule ;
14
- import org .junit .Test ;
13
+ import org .junit .jupiter .api .BeforeEach ;
14
+ import org .junit .jupiter .api .Test ;
15
15
import org .jvnet .hudson .test .JenkinsRule ;
16
+ import org .jvnet .hudson .test .junit .jupiter .WithJenkins ;
16
17
17
- public class PluginImplTest {
18
-
19
- @ Rule
20
- public JenkinsRule j = new JenkinsRule ();
18
+ @ WithJenkins
19
+ class PluginImplTest {
21
20
22
21
private PluginImpl plugin ;
23
22
24
- @ Before
25
- public void setUp () {
23
+ @ BeforeEach
24
+ void setUp (JenkinsRule j ) {
26
25
plugin = Jenkins .get ().getExtensionList (PluginImpl .class ).get (0 );
27
26
}
28
27
@@ -33,26 +32,26 @@ public void setUp() {
33
32
"zh_TW" ));
34
33
35
34
@ Test
36
- public void testDoFillSystemLocaleItems () {
35
+ void testDoFillSystemLocaleItems () {
37
36
// Invoke the method
38
37
ListBoxModel model = plugin .doFillSystemLocaleItems ();
39
38
40
39
// Expected size of the ListBoxModel
41
40
int expectedSize = ALLOWED_LOCALES .size () + 1 ; // +1 for the "Use Default Locale" option
42
41
43
42
// Verify the returned ListBoxModel size
44
- assertEquals ("The returned ListBoxModel size is not as expected" , expectedSize , model . size () );
43
+ assertEquals (expectedSize , model . size (), "The returned ListBoxModel size is not as expected" );
45
44
46
45
// Verify that the first option is "Use Default Locale"
47
46
String expectedFirstOption = String .format (
48
47
"Use Default Locale - %s (%s)" ,
49
48
Locale .getDefault ().getDisplayName (), Locale .getDefault ().toString ());
50
- assertEquals ("The first option should be 'Use Default Locale'" , expectedFirstOption , model . get ( 0 ). name );
49
+ assertEquals (expectedFirstOption , model . get ( 0 ). name , "The first option should be 'Use Default Locale'" );
51
50
52
51
// Verify that the allowed locales are correctly added to the ListBoxModel, excluding the first option
53
52
for (String localeStr : ALLOWED_LOCALES ) {
54
53
Locale locale = Locale .forLanguageTag (localeStr .replace ('_' , '-' ));
55
- String expectedOption = String .format ("%s - %s" , locale .getDisplayName (), locale . toString () );
54
+ String expectedOption = String .format ("%s - %s" , locale .getDisplayName (), locale );
56
55
57
56
boolean found = false ;
58
57
for (int i = 1 ; i < model .size (); i ++) { // Start from 1 to skip the "Use Default Locale" option
@@ -61,37 +60,37 @@ public void testDoFillSystemLocaleItems() {
61
60
break ;
62
61
}
63
62
}
64
- assertEquals ( "The ListBoxModel does not contain the expected locale: " + locale , true , found );
63
+ assertTrue ( found , "The ListBoxModel does not contain the expected locale: " + locale );
65
64
}
66
65
}
67
66
68
67
@ Test
69
- public void testSetSystemLocale () {
68
+ void testSetSystemLocale () {
70
69
// Test setting systemLocale
71
70
String systemLocale = "en_US" ;
72
71
plugin .setSystemLocale (systemLocale );
73
72
assertEquals (systemLocale , plugin .getSystemLocale ());
74
73
}
75
74
76
75
@ Test
77
- public void testSetIgnoreAcceptLanguage () {
76
+ void testSetIgnoreAcceptLanguage () {
78
77
// Test setting ignoreAcceptLanguage
79
78
boolean ignoreAcceptLanguage = true ;
80
79
plugin .setIgnoreAcceptLanguage (ignoreAcceptLanguage );
81
80
assertEquals (ignoreAcceptLanguage , plugin .isIgnoreAcceptLanguage ());
82
81
}
83
82
84
83
@ Test
85
- public void testNullSystemLocale () {
84
+ void testNullSystemLocale () {
86
85
// Test setting systemLocale to null
87
86
plugin .setSystemLocale (null );
88
- assertNull ("System locale should be null" , plugin . getSystemLocale () );
87
+ assertNull (plugin . getSystemLocale (), "System locale should be null" );
89
88
}
90
89
91
90
@ Test
92
- public void testEmptySystemLocale () {
91
+ void testEmptySystemLocale () {
93
92
// Test setting systemLocale to empty string
94
93
plugin .setSystemLocale ("" );
95
- assertNull ("System locale should be empty" , plugin . getSystemLocale () );
94
+ assertNull (plugin . getSystemLocale (), "System locale should be empty" );
96
95
}
97
96
}
0 commit comments