summaryrefslogtreecommitdiff
path: root/src/tests/org/noreply/fancydress/directory/ServerDescriptorTest.java
blob: adbe46e046645736829f039816acafd70ffc097d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.io.*;
import java.util.*;
import junit.framework.*;
import org.noreply.fancydress.misc.Util;
import org.noreply.fancydress.directory.ServerDescriptor;

public class ServerDescriptorTest extends TestCase {

	public ServerDescriptorTest(String name) {
		super(name);
	}

	private boolean equals(String[] s1, String[] s2) {
		boolean equals = s1.length == s2.length;
		if (equals)
			for (int i=0; i<s1.length; i++) {
				equals = equals && s1[i].equals(s2[i]);
			}
		return equals;
	}

	public void testParsePacketVersions() {
		String versions = "0.1 , 0.3, 0.6";
		String[] expected = {"0.1", "0.3", "0.6"};
		String[] parsed = ServerDescriptor.parsePacketVersions(versions, false);
		String[] expected2 = {"0.3"};
		String[] parsed2 = ServerDescriptor.parsePacketVersions(versions);
		String[] parsed2_1 = ServerDescriptor.parsePacketVersions("0.3");

		assertTrue(equals(expected, parsed));
		assertTrue(equals(expected2, parsed2));
		assertTrue(equals(expected2, parsed2_1));
	};

	public static Test suite() {
		TestSuite suite= new TestSuite();
		suite.addTest(new ServerDescriptorTest("testParsePacketVersions"));
		return suite;
	}

	public static void main(String args[]) {
		junit.textui.TestRunner.run(suite());
	}
}