Search in sources :

Example 1 with LenientComparable

use of org.apache.sis.util.LenientComparable in project sis by apache.

the class NilReasonTest method testNilObjectComparison.

/**
 * Tests the comparison of {@link NilObject} instances.
 */
@Test
public void testNilObjectComparison() {
    final Citation e1 = NilReason.TEMPLATE.createNilObject(Citation.class);
    final Citation e2 = NilReason.MISSING.createNilObject(Citation.class);
    final Citation e3 = NilReason.TEMPLATE.createNilObject(Citation.class);
    assertEquals("NilObject.hashCode()", e1.hashCode(), e3.hashCode());
    assertFalse("NilObject.hashCode()", e1.hashCode() == e2.hashCode());
    assertEquals("NilObject.equals(Object)", e1, e3);
    assertFalse("NilObject.equals(Object)", e1.equals(e2));
    assertInstanceOf("e1", LenientComparable.class, e1);
    final LenientComparable c = (LenientComparable) e1;
    assertTrue(c.equals(e3, ComparisonMode.STRICT));
    assertFalse(c.equals(e2, ComparisonMode.STRICT));
    assertFalse(c.equals(e2, ComparisonMode.BY_CONTRACT));
    assertTrue(c.equals(e2, ComparisonMode.IGNORE_METADATA));
    assertTrue(c.equals(e2, ComparisonMode.APPROXIMATIVE));
    assertTrue(c.equals(e2, ComparisonMode.DEBUG));
    // Following object should alway be different because it does not implement the same interface.
    final ResponsibleParty r1 = NilReason.TEMPLATE.createNilObject(ResponsibleParty.class);
    assertFalse(c.equals(r1, ComparisonMode.STRICT));
    assertFalse(c.equals(r1, ComparisonMode.BY_CONTRACT));
    assertFalse(c.equals(r1, ComparisonMode.IGNORE_METADATA));
    assertFalse(c.equals(r1, ComparisonMode.APPROXIMATIVE));
    assertFalse(c.equals(r1, ComparisonMode.DEBUG));
}
Also used : Citation(org.opengis.metadata.citation.Citation) LenientComparable(org.apache.sis.util.LenientComparable) ResponsibleParty(org.opengis.metadata.citation.ResponsibleParty) Test(org.junit.Test)

Aggregations

LenientComparable (org.apache.sis.util.LenientComparable)1 Test (org.junit.Test)1 Citation (org.opengis.metadata.citation.Citation)1 ResponsibleParty (org.opengis.metadata.citation.ResponsibleParty)1