Skip to content

Commit c33bf73

Browse files
Migrate tests to JUnit5 (cli) (#10559)
Co-authored-by: Mark Waite <mark.earl.waite@gmail.com>
1 parent 622dab2 commit c33bf73

File tree

5 files changed

+49
-48
lines changed

5 files changed

+49
-48
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package hudson.cli;
22

3-
import org.junit.jupiter.api.Assertions;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
45
import org.junit.jupiter.api.BeforeEach;
56
import org.junit.jupiter.api.Test;
67

78
class CLIConnectionFactoryTest {
89

9-
CLIConnectionFactory cliFactory;
10+
private CLIConnectionFactory cliFactory;
1011

1112
@BeforeEach
1213
void setUp() {
@@ -15,11 +16,11 @@ void setUp() {
1516

1617
@Test
1718
void testBearerFromToken() {
18-
Assertions.assertEquals("Bearer some-token", cliFactory.bearerAuth("some-token").authorization);
19+
assertEquals("Bearer some-token", cliFactory.bearerAuth("some-token").authorization);
1920
}
2021

2122
@Test
2223
void testBasicFromUserAndPass() {
23-
Assertions.assertEquals("Basic c29tZTpwYXNz", cliFactory.basicAuth("some:pass").authorization);
24+
assertEquals("Basic c29tZTpwYXNz", cliFactory.basicAuth("some:pass").authorization);
2425
}
2526
}

cli/src/test/java/hudson/cli/HexDumpTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,40 @@
1212
import org.junit.jupiter.params.provider.MethodSource;
1313

1414
@Execution(ExecutionMode.CONCURRENT)
15-
public class HexDumpTest {
15+
class HexDumpTest {
1616

17-
@DisplayName("Test HexDump.toHex(byte[] buf)")
18-
@ParameterizedTest(name = "{index} => expected: {0}, buf: {1}")
19-
@MethodSource("testToHex1Sources")
20-
public void testToHex1(String expected, byte[] buf) {
21-
assertEquals(expected, HexDump.toHex(buf));
22-
}
17+
@DisplayName("Test HexDump.toHex(byte[] buf)")
18+
@ParameterizedTest(name = "{index} => expected: {0}, buf: {1}")
19+
@MethodSource("testToHex1Sources")
20+
void testToHex1(String expected, byte[] buf) {
21+
assertEquals(expected, HexDump.toHex(buf));
22+
}
2323

24-
static Stream<Arguments> testToHex1Sources() {
25-
return Stream.of(
24+
static Stream<Arguments> testToHex1Sources() {
25+
return Stream.of(
2626
arguments("'fooBar'", new byte[] {'f', 'o', 'o', 'B', 'a', 'r'}),
2727
arguments("0xc3", new byte[] {(byte) 'Ã'}),
2828
arguments("0xac '100'", new byte[] {(byte) '€', '1', '0', '0'}),
2929
arguments("'1' 0xf7 '2'", new byte[] {'1', (byte) '÷', '2'}),
3030
arguments("'foo' 0x0a\n'Bar'", new byte[] {'f', 'o', 'o', '\n', 'B', 'a', 'r'})
31-
);
32-
}
31+
);
32+
}
3333

34-
@DisplayName("Test HexDump.toHex(byte[] buf, int start, int len)")
35-
@ParameterizedTest(name = "{index} => expected: {0}, buf: {1}, start: {2}, len: {3}")
36-
@MethodSource("testToHex2Sources")
37-
public void testToHex2(String expected, byte[] buf, int start, int len) {
38-
assertEquals(expected, HexDump.toHex(buf, start, len));
39-
}
34+
@DisplayName("Test HexDump.toHex(byte[] buf, int start, int len)")
35+
@ParameterizedTest(name = "{index} => expected: {0}, buf: {1}, start: {2}, len: {3}")
36+
@MethodSource("testToHex2Sources")
37+
void testToHex2(String expected, byte[] buf, int start, int len) {
38+
assertEquals(expected, HexDump.toHex(buf, start, len));
39+
}
4040

41-
static Stream<Arguments> testToHex2Sources() {
42-
return Stream.of(
41+
static Stream<Arguments> testToHex2Sources() {
42+
return Stream.of(
4343
arguments("'ooBa'", new byte[] {'f', 'o', 'o', 'B', 'a', 'r'}, 1, 4),
4444
arguments("0xc3", new byte[] {(byte) 'Ã'}, 0, 1),
4545
arguments("0xac '10'", new byte[] {(byte) '€', '1', '0', '0'}, 0, 3),
4646
arguments("0xf7 '2'", new byte[] {'1', (byte) '÷', '2'}, 1, 2),
4747
arguments("'Bar'", new byte[] {'f', 'o', 'o', '\n', 'B', 'a', 'r'}, 4, 3),
4848
arguments("", new byte[] {'f', 'o', 'o', 'B', 'a', 'r'}, 0, 0)
49-
);
50-
}
49+
);
50+
}
5151
}

cli/src/test/java/hudson/cli/PlainCLIProtocolTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@
3434
import java.nio.charset.Charset;
3535
import org.junit.jupiter.api.Test;
3636

37-
public class PlainCLIProtocolTest {
37+
class PlainCLIProtocolTest {
3838

3939
@Test
40-
public void ignoreUnknownOperations() throws Exception {
40+
void ignoreUnknownOperations() throws Exception {
4141
final PipedOutputStream upload = new PipedOutputStream();
4242
final PipedOutputStream download = new PipedOutputStream();
4343
class Client extends PlainCLIProtocol.ClientSide {
4444
int code = -1;
4545
final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
4646

47-
Client() throws IOException {
47+
Client() {
4848
super(new PlainCLIProtocol.FramedOutput(upload));
4949
}
5050

cli/src/test/java/hudson/cli/PrivateKeyProviderTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
keys were generated with ssh-keygen from OpenSSH_7.9p1, LibreSSL 2.7.3
1919
*/
2020
@Execution(ExecutionMode.CONCURRENT)
21-
public class PrivateKeyProviderTest {
21+
class PrivateKeyProviderTest {
2222

2323
/**
2424
key command: ssh-keygen -f dsa -t dsa -b 1024 -m PEM
2525
*/
2626
@Test
27-
public void loadKeyDSA() throws IOException, GeneralSecurityException {
27+
void loadKeyDSA() throws IOException, GeneralSecurityException {
2828
File file = new File(this.getClass().getResource("dsa").getFile());
2929
assertKeyPairNotNull(file, null);
3030
}
@@ -45,7 +45,7 @@ private void assertKeyPairNotNull(File file, String password) throws IOException
4545
key command: ssh-keygen -f dsa-password -t dsa -b 1024 -m PEM -P password
4646
*/
4747
@Test
48-
public void loadKeyDSAPassword() throws IOException, GeneralSecurityException {
48+
void loadKeyDSAPassword() throws IOException, GeneralSecurityException {
4949
File file = new File(this.getClass().getResource("dsa-password").getFile());
5050
String password = "password";
5151
assertKeyPairNotNull(file, password);
@@ -55,7 +55,7 @@ public void loadKeyDSAPassword() throws IOException, GeneralSecurityException {
5555
key command: ssh-keygen -f rsa -t rsa -b 1024 -m PEM
5656
*/
5757
@Test
58-
public void loadKeyRSA() throws IOException, GeneralSecurityException {
58+
void loadKeyRSA() throws IOException, GeneralSecurityException {
5959
File file = new File(this.getClass().getResource("rsa").getFile());
6060
assertKeyPairNotNull(file, null);
6161
}
@@ -64,7 +64,7 @@ public void loadKeyRSA() throws IOException, GeneralSecurityException {
6464
key command: ssh-keygen -f rsa-password -t rsa -b 1024 -m PEM -P password
6565
*/
6666
@Test
67-
public void loadKeyRSAPassword() throws IOException, GeneralSecurityException {
67+
void loadKeyRSAPassword() throws IOException, GeneralSecurityException {
6868
File file = new File(this.getClass().getResource("rsa-password").getFile());
6969
String password = "password";
7070
assertKeyPairNotNull(file, password);
@@ -74,7 +74,7 @@ public void loadKeyRSAPassword() throws IOException, GeneralSecurityException {
7474
key command: ssh-keygen -f openssh -t rsa -b 1024
7575
*/
7676
@Test
77-
public void loadKeyOpenSSH() throws IOException, GeneralSecurityException {
77+
void loadKeyOpenSSH() throws IOException, GeneralSecurityException {
7878
File file = new File(this.getClass().getResource("openssh").getFile());
7979
assertKeyPairNotNull(file, null);
8080
}
@@ -83,7 +83,7 @@ public void loadKeyOpenSSH() throws IOException, GeneralSecurityException {
8383
key command: ssh-keygen -f openssh-unsupported -t rsa -b 1024 -m PKCS8 -P password
8484
*/
8585
@Test
86-
public void loadKeyOpenSSHPKCS8() throws IOException, GeneralSecurityException {
86+
void loadKeyOpenSSHPKCS8() throws IOException, GeneralSecurityException {
8787
File file = new File(this.getClass().getResource("openssh-pkcs8").getFile());
8888
String password = "password";
8989
assertKeyPairNotNull(file, password);
@@ -93,7 +93,7 @@ public void loadKeyOpenSSHPKCS8() throws IOException, GeneralSecurityException {
9393
key command: ssh-keygen -f openssh-unsupported -t rsa -b 1024 -m RFC4716 -p password
9494
*/
9595
@Test
96-
public void loadKeyOpenSSHRFC4716() throws IOException, GeneralSecurityException {
96+
void loadKeyOpenSSHRFC4716() throws IOException, GeneralSecurityException {
9797
File file = new File(this.getClass().getResource("openssh-rfc4716").getFile());
9898
String password = "password";
9999
assertKeyPairNotNull(file, password);
@@ -104,7 +104,7 @@ public void loadKeyOpenSSHRFC4716() throws IOException, GeneralSecurityException
104104
Copy pasted the same key twice
105105
*/
106106
@Test
107-
public void loadKeyOpenSSHMultipleKeys() throws IOException, GeneralSecurityException {
107+
void loadKeyOpenSSHMultipleKeys() {
108108
File file = new File(this.getClass().getResource("openssh-multiple-keys").getFile());
109109
String password = "password";
110110
assertThrows(InvalidKeySpecException.class, () -> PrivateKeyProvider.loadKey(file, password));
@@ -114,7 +114,7 @@ public void loadKeyOpenSSHMultipleKeys() throws IOException, GeneralSecurityExce
114114
* Uses a blank file
115115
*/
116116
@Test
117-
public void loadBlankKey() throws IOException, GeneralSecurityException {
117+
void loadBlankKey() {
118118
File file = new File(this.getClass().getResource("blank").getFile());
119119
String password = "password";
120120
assertThrows(InvalidKeyException.class, () -> PrivateKeyProvider.loadKey(file, password));
@@ -125,7 +125,7 @@ public void loadBlankKey() throws IOException, GeneralSecurityException {
125125
in this key we remove some lines to break the key.
126126
*/
127127
@Test
128-
public void loadKeyBroken() throws IOException, GeneralSecurityException {
128+
void loadKeyBroken() {
129129
File file = new File(this.getClass().getResource("openssh-broken").getFile());
130130
String password = "password";
131131
assertThrows(IllegalArgumentException.class, () -> PrivateKeyProvider.loadKey(file, password));

cli/src/test/java/hudson/util/QuotedStringTokenizerTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,53 @@
3434
/**
3535
* @author Kohsuke Kawaguchi
3636
*/
37-
public class QuotedStringTokenizerTest {
37+
class QuotedStringTokenizerTest {
3838

3939
@Test
40-
public void test1() {
40+
void test1() {
4141
check("foo bar",
4242
"foo", "bar");
4343
}
4444

4545
@Test
46-
public void test2() {
46+
void test2() {
4747
check("foo \"bar zot\"",
4848
"foo", "bar zot");
4949
}
5050

5151
@Test
52-
public void test3() {
52+
void test3() {
5353
check("foo bar=\"quote zot\"",
5454
"foo", "bar=quote zot");
5555
}
5656

5757
@Test
58-
public void test4() {
58+
void test4() {
5959
check("foo\\\"",
6060
"foo\"");
6161
}
6262

6363
@Test
64-
public void test5() {
64+
void test5() {
6565
check("foo\\ bar",
6666
"foo bar");
6767
}
6868

6969
@Test
70-
public void test6() {
70+
void test6() {
7171
check("foo\\\\ bar",
7272
"foo\\", "bar");
7373
}
7474

7575
// see http://www.nabble.com/Error-parsing-%22-in-msbuild-task-to20535754.html
7676
@Test
77-
public void test7() {
77+
void test7() {
7878
check("foo=\"bar\\zot\"",
7979
"foo=bar\\zot");
8080
}
8181

8282
@Test
83-
public void testHasMoreToken() {
83+
void testHasMoreToken() {
8484
QuotedStringTokenizer tokenizer = new QuotedStringTokenizer("");
8585
assertFalse(tokenizer.hasMoreTokens());
8686
tokenizer = new QuotedStringTokenizer("one");

0 commit comments

Comments
 (0)