diff --git a/src/org/apollo/security/IsaacRandomPair.java b/util/src/main/org/apollo/util/security/IsaacRandomPair.java
similarity index 94%
rename from src/org/apollo/security/IsaacRandomPair.java
rename to util/src/main/org/apollo/util/security/IsaacRandomPair.java
index a9c96d05..fa3c6dce 100644
--- a/src/org/apollo/security/IsaacRandomPair.java
+++ b/util/src/main/org/apollo/util/security/IsaacRandomPair.java
@@ -1,6 +1,5 @@
-package org.apollo.security;
+package org.apollo.util.security;
-import net.burtleburtle.bob.rand.IsaacRandom;
/**
* A pair of two {@link IsaacRandom} random number generators used as a stream cipher. One takes the role of an encoder
diff --git a/src/org/apollo/security/PlayerCredentials.java b/util/src/main/org/apollo/util/security/PlayerCredentials.java
similarity index 98%
rename from src/org/apollo/security/PlayerCredentials.java
rename to util/src/main/org/apollo/util/security/PlayerCredentials.java
index f2cc07f4..7bfc466f 100644
--- a/src/org/apollo/security/PlayerCredentials.java
+++ b/util/src/main/org/apollo/util/security/PlayerCredentials.java
@@ -1,4 +1,4 @@
-package org.apollo.security;
+package org.apollo.util.security;
import org.apollo.util.NameUtil;
diff --git a/src/org/apollo/security/package-info.java b/util/src/main/org/apollo/util/security/package-info.java
similarity index 66%
rename from src/org/apollo/security/package-info.java
rename to util/src/main/org/apollo/util/security/package-info.java
index 81b6dadd..184fa6a6 100644
--- a/src/org/apollo/security/package-info.java
+++ b/util/src/main/org/apollo/util/security/package-info.java
@@ -1,4 +1,4 @@
/**
* Contains classes related to security and cryptography.
*/
-package org.apollo.security;
\ No newline at end of file
+package org.apollo.util.security;
\ No newline at end of file
diff --git a/src/org/apollo/tools/EquipmentConstants.java b/util/src/main/org/apollo/util/tools/EquipmentConstants.java
similarity index 98%
rename from src/org/apollo/tools/EquipmentConstants.java
rename to util/src/main/org/apollo/util/tools/EquipmentConstants.java
index cdd2cf52..b20b23cb 100644
--- a/src/org/apollo/tools/EquipmentConstants.java
+++ b/util/src/main/org/apollo/util/tools/EquipmentConstants.java
@@ -1,4 +1,4 @@
-package org.apollo.tools;
+package org.apollo.util.tools;
/**
* Contains equipment name constants.
diff --git a/src/org/apollo/tools/RsaKeyGenerator.java b/util/src/main/org/apollo/util/tools/RsaKeyGenerator.java
similarity index 97%
rename from src/org/apollo/tools/RsaKeyGenerator.java
rename to util/src/main/org/apollo/util/tools/RsaKeyGenerator.java
index d66157e7..0f0285f2 100644
--- a/src/org/apollo/tools/RsaKeyGenerator.java
+++ b/util/src/main/org/apollo/util/tools/RsaKeyGenerator.java
@@ -1,4 +1,4 @@
-package org.apollo.tools;
+package org.apollo.util.tools;
import java.math.BigInteger;
import java.security.SecureRandom;
diff --git a/src/org/apollo/tools/package-info.java b/util/src/main/org/apollo/util/tools/package-info.java
similarity index 62%
rename from src/org/apollo/tools/package-info.java
rename to util/src/main/org/apollo/util/tools/package-info.java
index c9cd0f7f..c33b70fc 100644
--- a/src/org/apollo/tools/package-info.java
+++ b/util/src/main/org/apollo/util/tools/package-info.java
@@ -1,4 +1,4 @@
/**
* Contains several stand-alone utilities.
*/
-package org.apollo.tools;
\ No newline at end of file
+package org.apollo.util.tools;
\ No newline at end of file
diff --git a/src/org/apollo/util/xml/XmlNode.java b/util/src/main/org/apollo/util/xml/XmlNode.java
similarity index 100%
rename from src/org/apollo/util/xml/XmlNode.java
rename to util/src/main/org/apollo/util/xml/XmlNode.java
diff --git a/src/org/apollo/util/xml/XmlParser.java b/util/src/main/org/apollo/util/xml/XmlParser.java
similarity index 100%
rename from src/org/apollo/util/xml/XmlParser.java
rename to util/src/main/org/apollo/util/xml/XmlParser.java
diff --git a/src/org/apollo/util/xml/package-info.java b/util/src/main/org/apollo/util/xml/package-info.java
similarity index 100%
rename from src/org/apollo/util/xml/package-info.java
rename to util/src/main/org/apollo/util/xml/package-info.java
diff --git a/util/src/test/org/apollo/util/TestBufferUtil.java b/util/src/test/org/apollo/util/TestBufferUtil.java
new file mode 100644
index 00000000..ffbe5491
--- /dev/null
+++ b/util/src/test/org/apollo/util/TestBufferUtil.java
@@ -0,0 +1,49 @@
+package org.apollo.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+
+import org.junit.Test;
+
+/**
+ * Contains tests for {@link BufferUtil}.
+ *
+ * @author Graham
+ */
+public class TestBufferUtil {
+
+ /**
+ * Tests the {@link BufferUtil#readUnsignedMedium} method.
+ */
+ @Test
+ public void testReadUnsignedTriByte() {
+ ByteBuffer buf = ByteBuffer.allocate(3);
+ buf.put((byte) 123);
+ buf.put((byte) 45);
+ buf.put((byte) 67);
+ buf.flip();
+
+ assertEquals(8072515, BufferUtil.readUnsignedMedium(buf));
+ }
+
+ /**
+ * Tests the {@link BufferUtil#readString(ByteBuffer)} method.
+ */
+ @Test
+ public void testReadString() {
+ ByteBuffer buf = ByteBuffer.allocate(8);
+ buf.put((byte) 'h');
+ buf.put((byte) 'e');
+ buf.put((byte) 'l');
+ buf.put((byte) 'l');
+ buf.put((byte) 'o');
+ buf.put((byte) BufferUtil.STRING_TERMINATOR);
+ buf.put((byte) 66);
+ buf.put((byte) 6);
+ buf.flip();
+
+ assertEquals("hello", BufferUtil.readString(buf));
+ }
+
+}
\ No newline at end of file
diff --git a/util/src/test/org/apollo/util/TestByteBufUtil.java b/util/src/test/org/apollo/util/TestByteBufUtil.java
new file mode 100644
index 00000000..675ece76
--- /dev/null
+++ b/util/src/test/org/apollo/util/TestByteBufUtil.java
@@ -0,0 +1,43 @@
+package org.apollo.util;
+
+import static org.junit.Assert.assertEquals;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+import org.junit.Test;
+
+/**
+ * Contains tests for {@link ByteBuf} methods in {@link BufferUtil}.
+ *
+ * @author Graham
+ */
+public final class TestByteBufUtil {
+
+ /**
+ * Test the {@link BufferUtil#readString(ByteBuf)} method.
+ */
+ @Test
+ public void testReadString() {
+ ByteBuf buf = Unpooled.buffer(6);
+ buf.writeBytes(new byte[] { 'H', 'e', 'l', 'l', 'o', 10 });
+ String str = BufferUtil.readString(buf);
+ assertEquals("Hello", str);
+
+ buf = Unpooled.buffer(5);
+ buf.writeBytes(new byte[] { 'W', 'o', 'r', 'l', 'd' });
+ str = BufferUtil.readString(buf);
+ assertEquals("World", str);
+
+ buf = Unpooled.buffer(3);
+ buf.writeByte('!');
+ buf.writeByte(10);
+ buf.writeByte('.');
+
+ str = BufferUtil.readString(buf);
+ assertEquals("!", str);
+
+ str = BufferUtil.readString(buf);
+ assertEquals(".", str);
+ }
+
+}
\ No newline at end of file
diff --git a/util/src/test/org/apollo/util/TestCompressionUtil.java b/util/src/test/org/apollo/util/TestCompressionUtil.java
new file mode 100644
index 00000000..a164cd20
--- /dev/null
+++ b/util/src/test/org/apollo/util/TestCompressionUtil.java
@@ -0,0 +1,44 @@
+package org.apollo.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+/**
+ * Contains tests for {@link CompressionUtil}.
+ *
+ * @author Graham
+ */
+public class TestCompressionUtil {
+
+ /**
+ * Tests the {@link CompressionUtil#bzip2(byte[])} and {@link CompressionUtil#debzip2} methods.
+ *
+ * @throws IOException If an I/O error occurs.
+ */
+ @Test
+ public void testBzip2() throws IOException {
+ String str = "Hello, World!";
+ byte[] data = str.getBytes();
+ byte[] compressed = CompressionUtil.bzip2(data);
+ CompressionUtil.debzip2(compressed, data);
+ assertEquals(str, new String(data));
+ }
+
+ /**
+ * Tests the {@link CompressionUtil#gzip(byte[])} and {@link CompressionUtil#degzip} methods.
+ *
+ * @throws IOException If an I/O error occurs.
+ */
+ @Test
+ public void testGzip() throws IOException {
+ String str = "Hello, World!";
+ byte[] data = str.getBytes();
+ byte[] compressed = CompressionUtil.gzip(data);
+ CompressionUtil.degzip(compressed, data);
+ assertEquals(str, new String(data));
+ }
+
+}
\ No newline at end of file
diff --git a/util/src/test/org/apollo/util/TestLanguageUtil.java b/util/src/test/org/apollo/util/TestLanguageUtil.java
new file mode 100644
index 00000000..6a5f2b80
--- /dev/null
+++ b/util/src/test/org/apollo/util/TestLanguageUtil.java
@@ -0,0 +1,25 @@
+package org.apollo.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Contains tests for {@link LanguageUtil}.
+ *
+ * @author Graham
+ */
+public class TestLanguageUtil {
+
+ /**
+ * Tests the {@link LanguageUtil#getIndefiniteArticle} method.
+ */
+ @Test
+ public void testIndefiniteArticle() {
+ assertEquals("an", LanguageUtil.getIndefiniteArticle("apple"));
+ assertEquals("an", LanguageUtil.getIndefiniteArticle("urn"));
+ assertEquals("a", LanguageUtil.getIndefiniteArticle("nose"));
+ assertEquals("a", LanguageUtil.getIndefiniteArticle("foot"));
+ }
+
+}
diff --git a/util/src/test/org/apollo/util/TestTextUtil.java b/util/src/test/org/apollo/util/TestTextUtil.java
new file mode 100644
index 00000000..f55ec998
--- /dev/null
+++ b/util/src/test/org/apollo/util/TestTextUtil.java
@@ -0,0 +1,48 @@
+package org.apollo.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * A test for the {@link TextUtil} class.
+ *
+ * @author Graham
+ */
+public class TestTextUtil {
+
+ /**
+ * Tests the {@link TextUtil#capitalize} method.
+ */
+ @Test
+ public void testCapitalize() {
+ String str = "tHiS is BAD capitAliZation. do You AGreE? YES!";
+ String capitalized = "This is bad capitalization. Do you agree? Yes!";
+ assertEquals(capitalized, TextUtil.capitalize(str));
+ }
+
+ /**
+ * Tests the {@link TextUtil#compress} and {@link TextUtil#decompress} methods.
+ */
+ @Test
+ public void testCompression() {
+ String str = "hello, world!";
+
+ byte[] compressed = new byte[128];
+ int len = TextUtil.compress(str, compressed);
+ String uncompressed = TextUtil.decompress(compressed, len);
+
+ assertEquals(str, uncompressed);
+ }
+
+ /**
+ * Tests the {@link TextUtil#filterInvalidCharacters(String)} method.
+ */
+ @Test
+ public void testFilter() {
+ String str = "this contains <<< invalid characters";
+ String filtered = "this contains invalid characters";
+ assertEquals(filtered, TextUtil.filterInvalidCharacters(str));
+ }
+
+}
\ No newline at end of file
diff --git a/util/src/test/org/apollo/util/xml/TestXmlParser.java b/util/src/test/org/apollo/util/xml/TestXmlParser.java
new file mode 100644
index 00000000..0d9bc370
--- /dev/null
+++ b/util/src/test/org/apollo/util/xml/TestXmlParser.java
@@ -0,0 +1,105 @@
+package org.apollo.util.xml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Set;
+
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+/**
+ * A test for the {@link XmlParser} class.
+ *
+ * @author Graham
+ */
+public final class TestXmlParser {
+
+ /**
+ * A test for the {@link XmlParser#parse} method.
+ *
+ * @throws SAXException If a SAX error occurs.
+ * @throws IOException If an I/O error occurs.
+ */
+ @Test
+ public void testParseInputStream() throws SAXException, IOException {
+ XmlParser parser = new XmlParser();
+ InputStream input = new ByteArrayInputStream("