Skip to content

Commit d1f87e4

Browse files
author
bert.degeyter
committed
Add unit tests for Version and VirtualServer classes
- Implement comprehensive tests for the Version class, covering various scenarios including valid, empty, and special version formats. - Add tests for the VirtualServer class, validating properties such as ID, port, status, client counts, and unique identifiers. - Ensure edge cases and real-world scenarios are accounted for in both test classes. - Validate inherited methods from the Wrapper class in both Version and VirtualServer tests.
1 parent 93fb841 commit d1f87e4

18 files changed

+7187
-0
lines changed

src/test/java/com/github/theholywaffle/teamspeak3/api/wrapper/BanTest.java

Lines changed: 403 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package com.github.theholywaffle.teamspeak3.api.wrapper;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
public class BindingTest {
11+
12+
@Test
13+
public void constructor_ValidMap() {
14+
Map<String, String> map = new HashMap<>();
15+
map.put("ip", "192.168.1.1");
16+
17+
Binding binding = new Binding(map);
18+
assertNotNull(binding);
19+
assertEquals("192.168.1.1", binding.getIp());
20+
}
21+
22+
@Test
23+
public void getIp_ValidIp() {
24+
Map<String, String> map = new HashMap<>();
25+
map.put("ip", "10.0.0.1");
26+
27+
Binding binding = new Binding(map);
28+
assertEquals("10.0.0.1", binding.getIp());
29+
}
30+
31+
@Test
32+
public void getIp_IPv6Address() {
33+
Map<String, String> map = new HashMap<>();
34+
map.put("ip", "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
35+
36+
Binding binding = new Binding(map);
37+
assertEquals("2001:0db8:85a3:0000:0000:8a2e:0370:7334", binding.getIp());
38+
}
39+
40+
@Test
41+
public void getIp_LocalhostIp() {
42+
Map<String, String> map = new HashMap<>();
43+
map.put("ip", "127.0.0.1");
44+
45+
Binding binding = new Binding(map);
46+
assertEquals("127.0.0.1", binding.getIp());
47+
}
48+
49+
@Test
50+
public void getIp_WildcardIp() {
51+
Map<String, String> map = new HashMap<>();
52+
map.put("ip", "0.0.0.0");
53+
54+
Binding binding = new Binding(map);
55+
assertEquals("0.0.0.0", binding.getIp());
56+
}
57+
58+
@Test
59+
public void getIp_EmptyIp() {
60+
Map<String, String> map = new HashMap<>();
61+
map.put("ip", "");
62+
63+
Binding binding = new Binding(map);
64+
assertEquals("", binding.getIp());
65+
}
66+
67+
@Test
68+
public void getIp_NullIp() {
69+
Map<String, String> map = new HashMap<>();
70+
// ip key not present
71+
72+
Binding binding = new Binding(map);
73+
assertEquals("", binding.getIp());
74+
}
75+
76+
@Test
77+
public void getIp_InvalidIpFormat() {
78+
Map<String, String> map = new HashMap<>();
79+
map.put("ip", "invalid.ip.address");
80+
81+
Binding binding = new Binding(map);
82+
assertEquals("invalid.ip.address", binding.getIp());
83+
}
84+
85+
@Test
86+
public void getIp_IpWithPort() {
87+
Map<String, String> map = new HashMap<>();
88+
map.put("ip", "192.168.1.1:9987");
89+
90+
Binding binding = new Binding(map);
91+
assertEquals("192.168.1.1:9987", binding.getIp());
92+
}
93+
94+
@Test
95+
public void binding_EmptyMap() {
96+
Map<String, String> map = new HashMap<>();
97+
98+
Binding binding = new Binding(map);
99+
assertEquals("", binding.getIp());
100+
}
101+
102+
@Test
103+
public void binding_NullMap() {
104+
// Test that constructor accepts null map (inherited from Wrapper)
105+
Binding binding = new Binding(null);
106+
assertNotNull(binding);
107+
// Note: calling getIp() would throw NPE, but constructor doesn't
108+
}
109+
110+
@Test
111+
public void binding_MultipleEntries() {
112+
Map<String, String> map = new HashMap<>();
113+
map.put("ip", "192.168.1.100");
114+
map.put("other_field", "other_value");
115+
116+
Binding binding = new Binding(map);
117+
assertEquals("192.168.1.100", binding.getIp());
118+
// Verify that other fields don't interfere
119+
assertEquals("other_value", binding.get("other_field"));
120+
}
121+
122+
@Test
123+
public void binding_SpecialCharactersInIp() {
124+
Map<String, String> map = new HashMap<>();
125+
map.put("ip", "192.168.1.1/24");
126+
127+
Binding binding = new Binding(map);
128+
assertEquals("192.168.1.1/24", binding.getIp());
129+
}
130+
131+
@Test
132+
public void binding_WhitespaceInIp() {
133+
Map<String, String> map = new HashMap<>();
134+
map.put("ip", " 192.168.1.1 ");
135+
136+
Binding binding = new Binding(map);
137+
assertEquals(" 192.168.1.1 ", binding.getIp());
138+
}
139+
140+
@Test
141+
public void binding_VeryLongIp() {
142+
Map<String, String> map = new HashMap<>();
143+
String longIp = "192.168.1.1".repeat(10);
144+
map.put("ip", longIp);
145+
146+
Binding binding = new Binding(map);
147+
assertEquals(longIp, binding.getIp());
148+
}
149+
150+
@Test
151+
public void binding_NumericStringIp() {
152+
Map<String, String> map = new HashMap<>();
153+
map.put("ip", "123456789");
154+
155+
Binding binding = new Binding(map);
156+
assertEquals("123456789", binding.getIp());
157+
}
158+
159+
@Test
160+
public void binding_InheritedWrapperMethods() {
161+
Map<String, String> map = new HashMap<>();
162+
map.put("ip", "192.168.1.1");
163+
map.put("test_int", "42");
164+
map.put("test_boolean", "1");
165+
166+
Binding binding = new Binding(map);
167+
168+
// Test inherited methods from Wrapper
169+
assertEquals("192.168.1.1", binding.get("ip"));
170+
assertEquals(42, binding.getInt("test_int"));
171+
assertTrue(binding.getBoolean("test_boolean"));
172+
}
173+
}

0 commit comments

Comments
 (0)