Editing test for Match.

Change-Id: I5985503c20639746bac1d2c250b9ce56047df840
This commit is contained in:
Sarah Feng 2017-06-22 11:39:42 -07:00 committed by sarah feng
parent 363f0e80a4
commit 54647c08a1

View File

@ -43,6 +43,10 @@ public class MatchTest {
assertFalse(m3.matches(null));
assertFalse(m3.matches("bar"));
assertTrue(m3.matches("foo"));
Match<byte[]> m4 = Match.ifValue(new byte[8]);
assertTrue(m4.matches(new byte[8]));
assertFalse(m4.matches(new byte[7]));
}
@Test
@ -54,6 +58,8 @@ public class MatchTest {
assertEquals(m1, m2);
assertFalse(Objects.equal(m1, m3));
assertFalse(Objects.equal(m3, m4));
Object o = new Object();
assertFalse(Objects.equal(m1, o));
}
@Test
@ -64,4 +70,49 @@ public class MatchTest {
Match<String> m3 = m2.map(s -> "bar");
assertTrue(m3.matches("bar"));
}
@Test
public void testIfNotNull() {
Match<String> m = Match.ifNotNull();
assertFalse(m.matches(null));
assertTrue(m.matches("foo"));
}
@Test
public void testIfNotValue() {
Match<String> m1 = Match.ifNotValue(null);
Match<String> m2 = Match.ifNotValue("foo");
assertFalse(m1.matches(null));
assertFalse(m2.matches("foo"));
}
@Test
public void testToString() {
Match<String> m1 = Match.any();
Match<String> m2 = Match.any();
Match<String> m3 = Match.ifValue("foo");
Match<String> m4 = Match.ifValue("foo");
Match<String> m5 = Match.ifNotValue("foo");
String note = "Results of toString() should be consistent -- ";
assertTrue(note, m1.toString().equals(m2.toString()));
assertTrue(note, m3.toString().equals(m4.toString()));
assertFalse(note, m4.toString().equals(m5.toString()));
}
@Test
public void testHashCode() {
Match<String> m1 = Match.ifValue("foo");
Match<String> m2 = Match.ifNotValue("foo");
Match<String> m3 = Match.ifValue("foo");
Match<String> m4 = Match.ifNotNull();
Match<String> m5 = Match.ifNull();
assertTrue(m1.hashCode() == m3.hashCode());
assertFalse(m2.hashCode() == m1.hashCode());
assertFalse(m4.hashCode() == m5.hashCode());
}
}