forked from TheHolyWaffle/TeamSpeak-3-Java-API
-
Notifications
You must be signed in to change notification settings - Fork 0
TG-5586 Add unit tests for com.github.theholywaffle.teamspeak3.commands.FileCommands #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
JohnLBergqvist
wants to merge
1
commit into
master
from
Add-unit-tests-for-com.github.theholywaffle.teamspeak3.commands.FileCommands
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
224 changes: 224 additions & 0 deletions
224
src/test/java/com/github/theholywaffle/teamspeak3/commands/FileCommandsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
package com.github.theholywaffle.teamspeak3.commands; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
public class FileCommandsTest { | ||
|
||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
@Test | ||
public void ftCreateDir_NullPathException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftCreateDir(null, 001, null); | ||
} | ||
|
||
@Test | ||
public void ftCreateDir() { | ||
final String expected = "ftcreatedir cid=1 cpw= dirname=\\/dir1"; | ||
Assert.assertEquals(expected, FileCommands.ftCreateDir("/dir1", 001, null).toString()); | ||
Assert.assertEquals(expected, FileCommands.ftCreateDir("dir1", 001, null).toString()); | ||
} | ||
|
||
@Test | ||
public void ftDeleteFile_EmptyFileArrayException() { | ||
final String[] filePaths = {}; | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftDeleteFile(001, null, filePaths); | ||
} | ||
|
||
@Test | ||
public void ftDeleteFile_NullFileArrayException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftDeleteFile(001, null, null); | ||
} | ||
|
||
@Test | ||
public void ftDeleteFile_NullFilePathException() { | ||
final String[] filePaths = {null}; | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftDeleteFile(001, null, filePaths); | ||
} | ||
|
||
@Test | ||
public void ftDeleteFile() { | ||
final String[] filePaths = {"dir1", "/dir2"}; | ||
final String expected = "ftdeletefile cid=1 cpw= name=\\/dir1|name=\\/dir2"; | ||
Assert.assertEquals(expected, FileCommands.ftDeleteFile(001, null, filePaths).toString()); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfo_EmptyFileArrayException() { | ||
final String[] filePaths = {}; | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileInfo(001, null, filePaths); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfo_NullFileArrayException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileInfo(001, null, null); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfo_NullFilePathException() { | ||
final String[] filePaths = {null}; | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileInfo(001, null, filePaths); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfo() { | ||
final String[] filePaths = {"dir1", "/dir2"}; | ||
final String expected = "ftgetfileinfo cid=1 cpw= name=dir1|cid=1 cpw= name=\\/dir2"; | ||
Assert.assertEquals(expected, FileCommands.ftGetFileInfo(001, null, filePaths).toString()); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfoArray_EmptyChannelIDArrayException() { | ||
final int[] channelIds = {}; | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileInfo(channelIds, null, null); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfoArray_NullChannelIDArrayException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileInfo(null, null, null); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfoArray_EmptyFileArrayException() { | ||
final int[] channelIds = {001}; | ||
final String[] filePaths = {}; | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileInfo(channelIds, null, filePaths); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfoArray_NullFileArrayException() { | ||
final int[] channelIds = {001}; | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileInfo(channelIds, null, null); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfoArray_ChannelIDsLengthFilePathsLengthException() { | ||
final int[] channelIds = {001}; | ||
final String[] filePaths = {"dir1", "dir2"}; | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileInfo(channelIds, null, filePaths); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfoArray_PasswordsLengthFilePathsLengthException() { | ||
final int[] channelIds = {001, 002}; | ||
final String[] channelPasswords = {null}; | ||
final String[] filePaths = {"dir1", "dir2"}; | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileInfo(channelIds, channelPasswords, filePaths); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfoArray_NullFilePathException() { | ||
final int[] channelIds = {001}; | ||
final String[] filePaths = {null}; | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileInfo(channelIds, null, filePaths); | ||
} | ||
|
||
@Test | ||
public void ftGetFileInfoArray() { | ||
final int[] channelIds = {001, 002}; | ||
final String[] channelPasswords = {null, "pass2"}; | ||
final String[] filePaths = {"dir1", "/dir2"}; | ||
final String expected = "ftgetfileinfo cid=1 cpw= name=\\/dir1|cid=2 cpw=pass2 name=\\/dir2"; | ||
Assert.assertEquals(expected, FileCommands.ftGetFileInfo(channelIds, channelPasswords, filePaths).toString()); | ||
} | ||
|
||
@Test | ||
public void ftGetFileList_NullDirectoryPathException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftGetFileList(null, 001, null); | ||
} | ||
|
||
@Test | ||
public void ftGetFileList() { | ||
final String expected = "ftgetfilelist cid=1 cpw= path=\\/dir1\\/"; | ||
Assert.assertEquals(expected, FileCommands.ftGetFileList("/dir1", 001, null).toString()); | ||
Assert.assertEquals(expected, FileCommands.ftGetFileList("dir1/", 001, null).toString()); | ||
} | ||
|
||
@Test | ||
public void ftInitDownload_NullDirectoryPathException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftInitDownload(001, null, 001, null); | ||
} | ||
|
||
@Test | ||
public void ftInitDownload() { | ||
final String expected = "ftinitdownload clientftfid=1 name=\\/dir1 cid=1 cpw= seekpos=0 proto=0"; | ||
Assert.assertEquals(expected, FileCommands.ftInitDownload(001, "/dir1", 001, null).toString()); | ||
Assert.assertEquals(expected, FileCommands.ftInitDownload(001, "dir1", 001, null).toString()); | ||
} | ||
|
||
@Test | ||
public void ftInitUpload_NullDirectoryPathException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftInitUpload(001, null, 001, null, 1024, true); | ||
} | ||
|
||
@Test | ||
public void ftInitUpload() { | ||
final String expected = "ftinitupload clientftfid=1 name=\\/dir1 cid=1 cpw= size=1024 overwrite=1 resume=0 proto=0"; | ||
Assert.assertEquals(expected, FileCommands.ftInitUpload(001, "/dir1", 001, null, 1024, true).toString()); | ||
Assert.assertEquals(expected, FileCommands.ftInitUpload(001, "dir1", 001, null, 1024, true).toString()); | ||
} | ||
|
||
@Test | ||
public void ftList() { | ||
final String expected = "ftlist"; | ||
Assert.assertEquals(expected, FileCommands.ftList().toString()); | ||
} | ||
|
||
@Test | ||
public void ftRenameFile_NullOldPathException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftRenameFile(null, "dir2", 001, null); | ||
} | ||
|
||
@Test | ||
public void ftRenameFile_NullNewPathException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftRenameFile("dir1", null, 001, null); | ||
} | ||
|
||
@Test | ||
public void ftRenameFile() { | ||
final String expected = "ftrenamefile cid=1 cpw= oldname=\\/dir1 newname=\\/dir2"; | ||
Assert.assertEquals(expected, FileCommands.ftRenameFile("/dir1", "dir2", 001, null).toString()); | ||
Assert.assertEquals(expected, FileCommands.ftRenameFile("dir1", "/dir2", 001, null).toString()); | ||
} | ||
|
||
@Test | ||
public void ftRenameFileAndChannel_NullOldPathException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftRenameFile(null, "dir2", 001, null, 002, null); | ||
} | ||
|
||
@Test | ||
public void ftRenameFileAndChannel_NullNewPathException() { | ||
thrown.expect(IllegalArgumentException.class); | ||
FileCommands.ftRenameFile("dir1", null, 001, null, 002, null); | ||
} | ||
|
||
@Test | ||
public void ftRenameFileAndChannel() { | ||
final String expected = "ftrenamefile cid=1 cpw= tcid=2 tcpw= oldname=\\/dir1 newname=\\/dir2"; | ||
Assert.assertEquals(expected, FileCommands.ftRenameFile("/dir1", "dir2", 001, null, 002, null).toString()); | ||
Assert.assertEquals(expected, FileCommands.ftRenameFile("dir1", "/dir2", 001, null, 002, null).toString()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.