1
+ package com .github .theholywaffle .teamspeak3 .commands ;
2
+
3
+ import org .junit .Assert ;
4
+ import org .junit .Rule ;
5
+ import org .junit .Test ;
6
+ import org .junit .rules .ExpectedException ;
7
+
8
+ public class FileCommandsTest {
9
+
10
+ @ Rule public ExpectedException thrown = ExpectedException .none ();
11
+ @ Test
12
+ public void ftCreateDir_NullPathException () {
13
+ thrown .expect (IllegalArgumentException .class );
14
+ FileCommands .ftCreateDir (null , 001 , null );
15
+ }
16
+
17
+ @ Test
18
+ public void ftCreateDir () {
19
+ final String expected = "ftcreatedir cid=1 cpw= dirname=\\ /dir1" ;
20
+ Assert .assertEquals (expected , FileCommands .ftCreateDir ("/dir1" , 001 , null ).toString ());
21
+ Assert .assertEquals (expected , FileCommands .ftCreateDir ("dir1" , 001 , null ).toString ());
22
+ }
23
+
24
+ @ Test
25
+ public void ftDeleteFile_EmptyFileArrayException () {
26
+ final String [] filePaths = {};
27
+ thrown .expect (IllegalArgumentException .class );
28
+ FileCommands .ftDeleteFile (001 , null , filePaths );
29
+ }
30
+
31
+ @ Test
32
+ public void ftDeleteFile_NullFileArrayException () {
33
+ thrown .expect (IllegalArgumentException .class );
34
+ FileCommands .ftDeleteFile (001 , null , null );
35
+ }
36
+
37
+ @ Test
38
+ public void ftDeleteFile_NullFilePathException () {
39
+ final String [] filePaths = {null };
40
+ thrown .expect (IllegalArgumentException .class );
41
+ FileCommands .ftDeleteFile (001 , null , filePaths );
42
+ }
43
+
44
+ @ Test
45
+ public void ftDeleteFile () {
46
+ final String [] filePaths = {"dir1" , "/dir2" };
47
+ final String expected = "ftdeletefile cid=1 cpw= name=\\ /dir1|name=\\ /dir2" ;
48
+ Assert .assertEquals (expected , FileCommands .ftDeleteFile (001 , null , filePaths ).toString ());
49
+ }
50
+
51
+ @ Test
52
+ public void ftGetFileInfo_EmptyFileArrayException () {
53
+ final String [] filePaths = {};
54
+ thrown .expect (IllegalArgumentException .class );
55
+ FileCommands .ftGetFileInfo (001 , null , filePaths );
56
+ }
57
+
58
+ @ Test
59
+ public void ftGetFileInfo_NullFileArrayException () {
60
+ thrown .expect (IllegalArgumentException .class );
61
+ FileCommands .ftGetFileInfo (001 , null , null );
62
+ }
63
+
64
+ @ Test
65
+ public void ftGetFileInfo_NullFilePathException () {
66
+ final String [] filePaths = {null };
67
+ thrown .expect (IllegalArgumentException .class );
68
+ FileCommands .ftGetFileInfo (001 , null , filePaths );
69
+ }
70
+
71
+ @ Test
72
+ public void ftGetFileInfo () {
73
+ final String [] filePaths = {"dir1" , "/dir2" };
74
+ final String expected = "ftgetfileinfo cid=1 cpw= name=dir1|cid=1 cpw= name=\\ /dir2" ;
75
+ Assert .assertEquals (expected , FileCommands .ftGetFileInfo (001 , null , filePaths ).toString ());
76
+ }
77
+
78
+ @ Test
79
+ public void ftGetFileInfoArray_EmptyChannelIDArrayException () {
80
+ final int [] channelIds = {};
81
+ thrown .expect (IllegalArgumentException .class );
82
+ FileCommands .ftGetFileInfo (channelIds , null , null );
83
+ }
84
+
85
+ @ Test
86
+ public void ftGetFileInfoArray_NullChannelIDArrayException () {
87
+ thrown .expect (IllegalArgumentException .class );
88
+ FileCommands .ftGetFileInfo (null , null , null );
89
+ }
90
+
91
+ @ Test
92
+ public void ftGetFileInfoArray_EmptyFileArrayException () {
93
+ final int [] channelIds = {001 };
94
+ final String [] filePaths = {};
95
+ thrown .expect (IllegalArgumentException .class );
96
+ FileCommands .ftGetFileInfo (channelIds , null , filePaths );
97
+ }
98
+
99
+ @ Test
100
+ public void ftGetFileInfoArray_NullFileArrayException () {
101
+ final int [] channelIds = {001 };
102
+ thrown .expect (IllegalArgumentException .class );
103
+ FileCommands .ftGetFileInfo (channelIds , null , null );
104
+ }
105
+
106
+ @ Test
107
+ public void ftGetFileInfoArray_ChannelIDsLengthFilePathsLengthException () {
108
+ final int [] channelIds = {001 };
109
+ final String [] filePaths = {"dir1" , "dir2" };
110
+ thrown .expect (IllegalArgumentException .class );
111
+ FileCommands .ftGetFileInfo (channelIds , null , filePaths );
112
+ }
113
+
114
+ @ Test
115
+ public void ftGetFileInfoArray_PasswordsLengthFilePathsLengthException () {
116
+ final int [] channelIds = {001 , 002 };
117
+ final String [] channelPasswords = {null };
118
+ final String [] filePaths = {"dir1" , "dir2" };
119
+ thrown .expect (IllegalArgumentException .class );
120
+ FileCommands .ftGetFileInfo (channelIds , channelPasswords , filePaths );
121
+ }
122
+
123
+ @ Test
124
+ public void ftGetFileInfoArray_NullFilePathException () {
125
+ final int [] channelIds = {001 };
126
+ final String [] filePaths = {null };
127
+ thrown .expect (IllegalArgumentException .class );
128
+ FileCommands .ftGetFileInfo (channelIds , null , filePaths );
129
+ }
130
+
131
+ @ Test
132
+ public void ftGetFileInfoArray () {
133
+ final int [] channelIds = {001 , 002 };
134
+ final String [] channelPasswords = {null , "pass2" };
135
+ final String [] filePaths = {"dir1" , "/dir2" };
136
+ final String expected = "ftgetfileinfo cid=1 cpw= name=\\ /dir1|cid=2 cpw=pass2 name=\\ /dir2" ;
137
+ Assert .assertEquals (expected , FileCommands .ftGetFileInfo (channelIds , channelPasswords , filePaths ).toString ());
138
+ }
139
+
140
+ @ Test
141
+ public void ftGetFileList_NullDirectoryPathException () {
142
+ thrown .expect (IllegalArgumentException .class );
143
+ FileCommands .ftGetFileList (null , 001 , null );
144
+ }
145
+
146
+ @ Test
147
+ public void ftGetFileList () {
148
+ final String expected = "ftgetfilelist cid=1 cpw= path=\\ /dir1\\ /" ;
149
+ Assert .assertEquals (expected , FileCommands .ftGetFileList ("/dir1" , 001 , null ).toString ());
150
+ Assert .assertEquals (expected , FileCommands .ftGetFileList ("dir1/" , 001 , null ).toString ());
151
+ }
152
+
153
+ @ Test
154
+ public void ftInitDownload_NullDirectoryPathException () {
155
+ thrown .expect (IllegalArgumentException .class );
156
+ FileCommands .ftInitDownload (001 , null , 001 , null );
157
+ }
158
+
159
+ @ Test
160
+ public void ftInitDownload () {
161
+ final String expected = "ftinitdownload clientftfid=1 name=\\ /dir1 cid=1 cpw= seekpos=0 proto=0" ;
162
+ Assert .assertEquals (expected , FileCommands .ftInitDownload (001 , "/dir1" , 001 , null ).toString ());
163
+ Assert .assertEquals (expected , FileCommands .ftInitDownload (001 , "dir1" , 001 , null ).toString ());
164
+ }
165
+
166
+ @ Test
167
+ public void ftInitUpload_NullDirectoryPathException () {
168
+ thrown .expect (IllegalArgumentException .class );
169
+ FileCommands .ftInitUpload (001 , null , 001 , null , 1024 , true );
170
+ }
171
+
172
+ @ Test
173
+ public void ftInitUpload () {
174
+ final String expected = "ftinitupload clientftfid=1 name=\\ /dir1 cid=1 cpw= size=1024 overwrite=1 resume=0 proto=0" ;
175
+ Assert .assertEquals (expected , FileCommands .ftInitUpload (001 , "/dir1" , 001 , null , 1024 , true ).toString ());
176
+ Assert .assertEquals (expected , FileCommands .ftInitUpload (001 , "dir1" , 001 , null , 1024 , true ).toString ());
177
+ }
178
+
179
+ @ Test
180
+ public void ftList () {
181
+ final String expected = "ftlist" ;
182
+ Assert .assertEquals (expected , FileCommands .ftList ().toString ());
183
+ }
184
+
185
+ @ Test
186
+ public void ftRenameFile_NullOldPathException () {
187
+ thrown .expect (IllegalArgumentException .class );
188
+ FileCommands .ftRenameFile (null , "dir2" , 001 , null );
189
+ }
190
+
191
+ @ Test
192
+ public void ftRenameFile_NullNewPathException () {
193
+ thrown .expect (IllegalArgumentException .class );
194
+ FileCommands .ftRenameFile ("dir1" , null , 001 , null );
195
+ }
196
+
197
+ @ Test
198
+ public void ftRenameFile () {
199
+ final String expected = "ftrenamefile cid=1 cpw= oldname=\\ /dir1 newname=\\ /dir2" ;
200
+ Assert .assertEquals (expected , FileCommands .ftRenameFile ("/dir1" , "dir2" , 001 , null ).toString ());
201
+ Assert .assertEquals (expected , FileCommands .ftRenameFile ("dir1" , "/dir2" , 001 , null ).toString ());
202
+ }
203
+
204
+ @ Test
205
+ public void ftRenameFileAndChannel_NullOldPathException () {
206
+ thrown .expect (IllegalArgumentException .class );
207
+ FileCommands .ftRenameFile (null , "dir2" , 001 , null , 002 , null );
208
+ }
209
+
210
+ @ Test
211
+ public void ftRenameFileAndChannel_NullNewPathException () {
212
+ thrown .expect (IllegalArgumentException .class );
213
+ FileCommands .ftRenameFile ("dir1" , null , 001 , null , 002 , null );
214
+ }
215
+
216
+ @ Test
217
+ public void ftRenameFileAndChannel () {
218
+ final String expected = "ftrenamefile cid=1 cpw= tcid=2 tcpw= oldname=\\ /dir1 newname=\\ /dir2" ;
219
+ Assert .assertEquals (expected , FileCommands .ftRenameFile ("/dir1" , "dir2" , 001 , null , 002 , null ).toString ());
220
+ Assert .assertEquals (expected , FileCommands .ftRenameFile ("dir1" , "/dir2" , 001 , null , 002 , null ).toString ());
221
+ }
222
+ }
0 commit comments