11package com .trilead .ssh2 ;
22
33import static org .mockito .Mockito .mock ;
4+ import static org .junit .jupiter .api .Assertions .assertThrows ;
45
56import java .io .IOException ;
6- import org .junit .Before ;
7- import org .junit .Test ;
7+ import org .junit .jupiter .api .BeforeEach ;
8+ import org .junit .jupiter .api .Test ;
9+ import org .junit .jupiter .api .extension .ExtendWith ;
810import org .mockito .Mock ;
911import org .mockito .MockitoAnnotations ;
12+ import org .mockito .junit .jupiter .MockitoExtension ;
1013
14+ @ ExtendWith (MockitoExtension .class )
1115public class SCPClientTest {
1216
1317@ Mock
1418private Connection mockConnection ;
1519
1620private SCPClient scpClient ;
1721
18- @ Before
22+ @ BeforeEach
1923public void setUp () {
2024 MockitoAnnotations .initMocks (this );
2125 scpClient = new SCPClient (mockConnection );
@@ -27,14 +31,18 @@ public void testSCPClientConstruction() {
2731 SCPClient client = new SCPClient (conn );
2832}
2933
30- @ Test (expected = IllegalArgumentException .class )
31- public void testSCPClientConstructionWithNullConnection () {
34+ @ Test
35+ public void testSCPClientConstructionWithNullConnection () {
36+ assertThrows (IllegalArgumentException .class , () -> {
3237 new SCPClient (null );
38+ });
3339}
3440
35- @ Test (expected = IllegalArgumentException .class )
36- public void testPutWithNullLocalFiles () throws IOException {
41+ @ Test
42+ public void testPutWithNullLocalFiles () throws IOException {
43+ assertThrows (IllegalArgumentException .class , () -> {
3744 scpClient .put ((String []) null , "/tmp" , "0644" );
45+ });
3846}
3947
4048@ Test
@@ -43,38 +51,50 @@ public void testPutWithEmptyLocalFiles() throws IOException {
4351 scpClient .put (new String [0 ], "/tmp" , "0644" );
4452}
4553
46- @ Test (expected = IllegalArgumentException .class )
47- public void testPutWithNullLocalFileInArray () throws IOException {
54+ @ Test
55+ public void testPutWithNullLocalFileInArray () throws IOException {
56+ assertThrows (IllegalArgumentException .class , () -> {
4857 scpClient .put (new String [] { "file1.txt" , null , "file2.txt" }, "/tmp" ,
4958 "0644" );
59+ });
5060}
5161
52- @ Test (expected = IllegalArgumentException .class )
53- public void testPutDataWithNullRemoteFileName () throws IOException {
62+ @ Test
63+ public void testPutDataWithNullRemoteFileName () throws IOException {
64+ assertThrows (IllegalArgumentException .class , () -> {
5465 byte [] data = "Hello World" .getBytes ();
5566 scpClient .put (data , null , "/tmp" , "0644" );
67+ });
5668}
5769
58- @ Test (expected = IllegalArgumentException .class )
59- public void testPutDataWithNullRemoteTargetDirectory () throws IOException {
70+ @ Test
71+ public void testPutDataWithNullRemoteTargetDirectory () throws IOException {
72+ assertThrows (IllegalArgumentException .class , () -> {
6073 byte [] data = "Hello World" .getBytes ();
6174 scpClient .put (data , "remote.txt" , null , "0644" );
75+ });
6276}
6377
64- @ Test (expected = IllegalArgumentException .class )
65- public void testPutDataWithNullMode () throws IOException {
78+ @ Test
79+ public void testPutDataWithNullMode () throws IOException {
80+ assertThrows (IllegalArgumentException .class , () -> {
6681 byte [] data = "Hello World" .getBytes ();
6782 scpClient .put (data , "remote.txt" , "/tmp" , null );
83+ });
6884}
6985
70- @ Test (expected = IllegalArgumentException .class )
71- public void testGetWithNullRemoteFiles () throws IOException {
86+ @ Test
87+ public void testGetWithNullRemoteFiles () throws IOException {
88+ assertThrows (IllegalArgumentException .class , () -> {
7289 scpClient .get ((String []) null , "/tmp" );
90+ });
7391}
7492
75- @ Test (expected = IllegalArgumentException .class )
76- public void testGetWithNullLocalTargetDirectory () throws IOException {
93+ @ Test
94+ public void testGetWithNullLocalTargetDirectory () throws IOException {
95+ assertThrows (IllegalArgumentException .class , () -> {
7796 scpClient .get (new String [] { "file1.txt" }, null );
97+ });
7898}
7999
80100@ Test
@@ -83,29 +103,39 @@ public void testGetWithEmptyRemoteFiles() throws IOException {
83103 scpClient .get (new String [0 ], "/tmp" );
84104}
85105
86- @ Test (expected = IllegalArgumentException .class )
87- public void testGetWithNullRemoteFileInArray () throws IOException {
106+ @ Test
107+ public void testGetWithNullRemoteFileInArray () throws IOException {
108+ assertThrows (IllegalArgumentException .class , () -> {
88109 scpClient .get (new String [] { "file1.txt" , null }, "/tmp" );
110+ });
89111}
90112
91- @ Test (expected = IllegalArgumentException .class )
92- public void testGetWithEmptyRemoteFileInArray () throws IOException {
113+ @ Test
114+ public void testGetWithEmptyRemoteFileInArray () throws IOException {
115+ assertThrows (IllegalArgumentException .class , () -> {
93116 scpClient .get (new String [] { "file1.txt" , "" }, "/tmp" );
117+ });
94118}
95119
96- @ Test (expected = IllegalArgumentException .class )
97- public void testPutWithInvalidMode () throws IOException {
120+ @ Test
121+ public void testPutWithInvalidMode () throws IOException {
122+ assertThrows (IllegalArgumentException .class , () -> {
98123 scpClient .put (new String [] { "file1.txt" }, "/tmp" , "invalid" );
124+ });
99125}
100126
101- @ Test (expected = IllegalArgumentException .class )
102- public void testPutWithShortMode () throws IOException {
127+ @ Test
128+ public void testPutWithShortMode () throws IOException {
129+ assertThrows (IllegalArgumentException .class , () -> {
103130 scpClient .put (new String [] { "file1.txt" }, "/tmp" , "644" );
131+ });
104132}
105133
106- @ Test (expected = IllegalArgumentException .class )
107- public void testPutDataWithInvalidMode () throws IOException {
134+ @ Test
135+ public void testPutDataWithInvalidMode () throws IOException {
136+ assertThrows (IllegalArgumentException .class , () -> {
108137 byte [] data = "Hello World" .getBytes ();
109138 scpClient .put (data , "remote.txt" , "/tmp" , "invalid" );
139+ });
110140}
111141}
0 commit comments