Adds tests for the equals/hashCode functions.
@@ -78,6 +78,93 @@ public class AsciiStringTest {
}
}
+ @Test
+ public void testEquals_withSelf() {
+ Assert.assertEquals(string, string);
+ }
+
+ @Test
+ public void testEquals_withEqualStrings() {
+ final AsciiString stringA = new AsciiString(testString);
+ stringA.setBackgroundAndForegroundColor(Color.BLACK, Color.WHITE);
+
+ final AsciiString stringB = new AsciiString(testString);
+ stringB.setBackgroundAndForegroundColor(Color.BLACK, Color.WHITE);
+
+ Assert.assertEquals(stringA, stringB);
+ }
+
+ @Test
+ public void testEquals_withNonEqualStrings() {
+ final AsciiString stringA = new AsciiString(testString);
+ stringA.setBackgroundAndForegroundColor(Color.BLACK, Color.WHITE);
+
+ final AsciiString stringB = new AsciiString("Xfgcgfytf");
+ stringB.setBackgroundAndForegroundColor(Color.BLACK, Color.WHITE);
+
+ Assert.assertNotEquals(stringA, stringB);
+ }
+
+ @Test
+ public void testEquals_withNonAsciiStringObject() {
+ final AsciiString stringA = new AsciiString(testString);
+ stringA.setBackgroundAndForegroundColor(Color.BLACK, Color.WHITE);
+
+ final Integer integer = 666;
+
+ Assert.assertNotEquals(stringA, integer);
+ }
+
+ @Test
+ public void testEquals_withNonEqualBackgroundColors() {
+ final AsciiString stringA = new AsciiString(testString);
+ stringA.setBackgroundAndForegroundColor(Color.BLACK, Color.WHITE);
+
+ final AsciiString stringB = new AsciiString(testString);
+ stringB.setBackgroundAndForegroundColor(Color.BLACK, Color.RED);
+
+ Assert.assertNotEquals(stringA, stringB);
+ }
+
+ @Test
+ public void testEquals_withNonEqualForegroundColors() {
+ final AsciiString stringA = new AsciiString(testString);
+ stringA.setBackgroundAndForegroundColor(Color.BLACK, Color.WHITE);
+
+ final AsciiString stringB = new AsciiString(testString);
+ stringB.setBackgroundAndForegroundColor(Color.RED, Color.WHITE);
+
+ Assert.assertNotEquals(stringA, stringB);
+ }
+
+ // todo Fix issue with the equals function.
+ /*
+ @Test
+ public void testHashCode_withEqualStrings() {
+ final AsciiString stringA = new AsciiString("A");
+ stringA.setBackgroundAndForegroundColor(Color.BLACK, Color.WHITE);
+
+ final AsciiString stringB = new AsciiString("A");
+ stringB.setBackgroundAndForegroundColor(Color.BLACK, Color.WHITE);
+
+
+ System.out.println(stringA.detailedToString());
+ System.out.println(stringB.detailedToString());
+ Assert.assertEquals(stringA.hashCode(), stringB.hashCode());
+ }
+ */
+
+ @Test
+ public void testHashCode_withNonEqualStrings() {
+ final AsciiString stringA = new AsciiString(testString);
+ stringA.setBackgroundAndForegroundColor(Color.BLACK, Color.WHITE);
+
+ final AsciiString stringB = new AsciiString(testString);
+ stringB.setBackgroundAndForegroundColor(Color.RED, Color.WHITE);
+
+ Assert.assertNotEquals(stringA.hashCode(), stringB.hashCode());
+ }
+
@Test
public void testConstructor_stringConstructor_withEmptyString() {
final AsciiString string = new AsciiString("");
