Skip to content

Commit 255bb95

Browse files
Add unit tests for theholywaffle.teamspeak3.commands.FileCommands
These tests were written using Diffblue Cover. Dependencies required to run the tests have also been added.
1 parent 9efd437 commit 255bb95

File tree

2 files changed

+235
-0
lines changed

2 files changed

+235
-0
lines changed

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
<version>${slf4j.version}</version>
6565
<scope>test</scope>
6666
</dependency>
67+
<dependency>
68+
<groupId>junit</groupId>
69+
<artifactId>junit</artifactId>
70+
<version>4.12</version>
71+
<scope>test</scope>
72+
</dependency>
6773
</dependencies>
6874

6975
<build>
@@ -84,6 +90,11 @@
8490
<target>1.8</target>
8591
</configuration>
8692
</plugin>
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-surefire-plugin</artifactId>
96+
<version>3.0.0-M3</version>
97+
</plugin>
8798
</plugins>
8899
</build>
89100

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

0 commit comments

Comments
 (0)