public void testHashCodeAndEquals() { int num = atLeast(100); for (int i = 0; i < num; i++) { String field1 = "field" + i; String field2 = "field" + i + num; String value1 = TestUtil.randomRealisticUnicodeString(random()); String value2 = value1 + "x"; // this must be not equal to value1 TermFilter filter1 = termFilter(field1, value1); TermFilter filter2 = termFilter(field1, value2); TermFilter filter3 = termFilter(field2, value1); TermFilter filter4 = termFilter(field2, value2); TermFilter[] filters = new TermFilter[] {filter1, filter2, filter3, filter4}; for (int j = 0; j < filters.length; j++) { TermFilter termFilter = filters[j]; for (int k = 0; k < filters.length; k++) { TermFilter otherTermFilter = filters[k]; if (j == k) { assertEquals(termFilter, otherTermFilter); assertEquals(termFilter.hashCode(), otherTermFilter.hashCode()); assertTrue(termFilter.equals(otherTermFilter)); } else { assertFalse(termFilter.equals(otherTermFilter)); } } } TermFilter filter5 = termFilter(field2, value2); assertEquals(filter5, filter4); assertEquals(filter5.hashCode(), filter4.hashCode()); assertTrue(filter5.equals(filter4)); assertEquals(filter5, filter4); assertTrue(filter5.equals(filter4)); } }
public void testToString() { TermFilter termsFilter = new TermFilter(new Term("field1", "a")); assertEquals("field1:a", termsFilter.toString()); }