Skip to content

Commit 93fb841

Browse files
author
bert.degeyter
committed
More tests
1 parent 0d0b212 commit 93fb841

17 files changed

+4034
-0
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
package com.github.theholywaffle.teamspeak3.commands;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
public class BanCommandsTest {
8+
9+
@Test
10+
public void banAdd_WithIP() {
11+
String expected = "banadd ip=192.168.1.100";
12+
assertEquals(expected, BanCommands.banAdd("192.168.1.100", null, null, null, 0, null).toString());
13+
}
14+
15+
@Test
16+
public void banAdd_WithName() {
17+
String expected = "banadd name=BadUser";
18+
assertEquals(expected, BanCommands.banAdd(null, "BadUser", null, null, 0, null).toString());
19+
}
20+
21+
@Test
22+
public void banAdd_WithUID() {
23+
String expected = "banadd uid=unique123";
24+
assertEquals(expected, BanCommands.banAdd(null, null, "unique123", null, 0, null).toString());
25+
}
26+
27+
@Test
28+
public void banAdd_WithAllParameters() {
29+
String expected = "banadd ip=192.168.1.100 name=BadUser uid=unique123 mytsid=myts123 time=3600 banreason=Spamming";
30+
assertEquals(expected, BanCommands.banAdd("192.168.1.100", "BadUser", "unique123", "myts123", 3600, "Spamming").toString());
31+
}
32+
33+
@Test
34+
public void banAdd_WithTimeAndReason() {
35+
String expected = "banadd ip=192.168.1.100 time=7200 banreason=Inappropriate\\sbehavior";
36+
assertEquals(expected, BanCommands.banAdd("192.168.1.100", null, null, null, 7200, "Inappropriate behavior").toString());
37+
}
38+
39+
@Test
40+
public void banAdd_WithZeroTime() {
41+
// Zero time should not be included in the command
42+
String expected = "banadd ip=192.168.1.100";
43+
assertEquals(expected, BanCommands.banAdd("192.168.1.100", null, null, null, 0, null).toString());
44+
}
45+
46+
@Test
47+
public void banAdd_WithNegativeTime() {
48+
// Negative time should not be included in the command
49+
String expected = "banadd ip=192.168.1.100";
50+
assertEquals(expected, BanCommands.banAdd("192.168.1.100", null, null, null, -1, null).toString());
51+
}
52+
53+
@Test
54+
public void banAdd_AllNullParametersException() {
55+
assertThrows(IllegalArgumentException.class, () -> BanCommands.banAdd(null, null, null, null, 0, null));
56+
}
57+
58+
@Test
59+
public void banAdd_EmptyStringParameters() {
60+
// Empty strings should still be included as they are not null
61+
String expected = "banadd ip= name= uid= mytsid= banreason=";
62+
assertEquals(expected, BanCommands.banAdd("", "", "", "", 0, "").toString());
63+
}
64+
65+
@Test
66+
public void banClient_SingleClient() {
67+
int[] clientIds = {5};
68+
String expected = "banclient clid=5";
69+
assertEquals(expected, BanCommands.banClient(clientIds, 0, null, false).toString());
70+
}
71+
72+
@Test
73+
public void banClient_MultipleClients() {
74+
int[] clientIds = {5, 10, 15};
75+
String expected = "banclient clid=5|clid=10|clid=15";
76+
assertEquals(expected, BanCommands.banClient(clientIds, 0, null, false).toString());
77+
}
78+
79+
@Test
80+
public void banClient_WithTime() {
81+
int[] clientIds = {5};
82+
String expected = "banclient time=3600 clid=5";
83+
assertEquals(expected, BanCommands.banClient(clientIds, 3600, null, false).toString());
84+
}
85+
86+
@Test
87+
public void banClient_WithReason() {
88+
int[] clientIds = {5};
89+
String expected = "banclient banreason=Violation\\sof\\srules clid=5";
90+
assertEquals(expected, BanCommands.banClient(clientIds, 0, "Violation of rules", false).toString());
91+
}
92+
93+
@Test
94+
public void banClient_WithContinueOnError() {
95+
int[] clientIds = {5};
96+
String expected = "banclient -continueonerror clid=5";
97+
assertEquals(expected, BanCommands.banClient(clientIds, 0, null, true).toString());
98+
}
99+
100+
@Test
101+
public void banClient_WithAllParameters() {
102+
int[] clientIds = {5, 10};
103+
String expected = "banclient time=7200 banreason=Multiple\\sviolations -continueonerror clid=5|clid=10";
104+
assertEquals(expected, BanCommands.banClient(clientIds, 7200, "Multiple violations", true).toString());
105+
}
106+
107+
@Test
108+
public void banClient_WithZeroTime() {
109+
// Zero time should not be included
110+
int[] clientIds = {5};
111+
String expected = "banclient clid=5";
112+
assertEquals(expected, BanCommands.banClient(clientIds, 0, null, false).toString());
113+
}
114+
115+
@Test
116+
public void banClient_WithNegativeTime() {
117+
// Negative time should not be included
118+
int[] clientIds = {5};
119+
String expected = "banclient clid=5";
120+
assertEquals(expected, BanCommands.banClient(clientIds, -1, null, false).toString());
121+
}
122+
123+
@Test
124+
public void banClient_EmptyReason() {
125+
int[] clientIds = {5};
126+
String expected = "banclient banreason= clid=5";
127+
assertEquals(expected, BanCommands.banClient(clientIds, 0, "", false).toString());
128+
}
129+
130+
@Test
131+
public void banDel_ValidBanId() {
132+
String expected = "bandel banid=123";
133+
assertEquals(expected, BanCommands.banDel(123).toString());
134+
}
135+
136+
@Test
137+
public void banDel_ZeroBanId() {
138+
String expected = "bandel banid=0";
139+
assertEquals(expected, BanCommands.banDel(0).toString());
140+
}
141+
142+
@Test
143+
public void banDel_NegativeBanId() {
144+
String expected = "bandel banid=-1";
145+
assertEquals(expected, BanCommands.banDel(-1).toString());
146+
}
147+
148+
@Test
149+
public void banDelAll() {
150+
String expected = "bandelall";
151+
assertEquals(expected, BanCommands.banDelAll().toString());
152+
}
153+
154+
@Test
155+
public void banList() {
156+
String expected = "banlist";
157+
assertEquals(expected, BanCommands.banList().toString());
158+
}
159+
160+
@Test
161+
public void banAdd_SpecialCharactersInReason() {
162+
String expected = "banadd ip=192.168.1.100 banreason=User\\swas\\s\"very\"\\sbad";
163+
assertEquals(expected, BanCommands.banAdd("192.168.1.100", null, null, null, 0, "User was \"very\" bad").toString());
164+
}
165+
166+
@Test
167+
public void banAdd_SpecialCharactersInName() {
168+
String expected = "banadd name=Bad\\sUser\\s[Admin]";
169+
assertEquals(expected, BanCommands.banAdd(null, "Bad User [Admin]", null, null, 0, null).toString());
170+
}
171+
172+
@Test
173+
public void banClient_LargeClientArray() {
174+
int[] clientIds = new int[10];
175+
for (int i = 0; i < 10; i++) {
176+
clientIds[i] = i + 1;
177+
}
178+
String expected = "banclient clid=1|clid=2|clid=3|clid=4|clid=5|clid=6|clid=7|clid=8|clid=9|clid=10";
179+
assertEquals(expected, BanCommands.banClient(clientIds, 0, null, false).toString());
180+
}
181+
182+
@Test
183+
public void banAdd_MaxTimeValue() {
184+
String expected = "banadd ip=192.168.1.100 time=" + Long.MAX_VALUE;
185+
assertEquals(expected, BanCommands.banAdd("192.168.1.100", null, null, null, Long.MAX_VALUE, null).toString());
186+
}
187+
188+
@Test
189+
public void banClient_MaxTimeValue() {
190+
int[] clientIds = {5};
191+
String expected = "banclient time=" + Long.MAX_VALUE + " clid=5";
192+
assertEquals(expected, BanCommands.banClient(clientIds, Long.MAX_VALUE, null, false).toString());
193+
}
194+
}

0 commit comments

Comments
 (0)