@Test public void testEquals() throws InvocationTargetException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException { SchemeValuePair.mapBehavior(AgencyId.class.getName(), SchemeValueBehavior.ALLOW_ANY); Assert.assertEquals(Version1Language.AAR, Version1Language.AAR); Assert.assertNotSame(Version1Language.AAR, Version1Language.ENG); String AGENCY_SCHEME = "http: String AGENCY_ONE_VALUE = "One"; AgencyId agencyIdOneViaCtor = new AgencyId(null, AGENCY_ONE_VALUE); AgencyId agencyIdOtherOneViaCtor = new AgencyId(null, AGENCY_ONE_VALUE); Assert.assertEquals(agencyIdOneViaCtor, agencyIdOtherOneViaCtor); Assert.assertNotSame(agencyIdOneViaCtor, agencyIdOtherOneViaCtor); AgencyId agencyIdOneWithSchemeViaCtor = new AgencyId(AGENCY_SCHEME, AGENCY_ONE_VALUE); AgencyId agencyIdOtherOneWithSchemeViaCtor = new AgencyId(AGENCY_SCHEME, AGENCY_ONE_VALUE); Assert.assertEquals(agencyIdOneWithSchemeViaCtor, agencyIdOtherOneWithSchemeViaCtor); Assert.assertNotSame(agencyIdOneWithSchemeViaCtor, agencyIdOtherOneWithSchemeViaCtor); AgencyId agencyIdWithSchemeAndValue = new AgencyId(AGENCY_SCHEME, "Test value"); AgencyId agencyIdWithSchemeButNoValue = new AgencyId(AGENCY_SCHEME, null); Assert.assertFalse( "AgencyIds shouldn't match if the first one has a value but the second one's is null," + " even if schemes are the same.", agencyIdWithSchemeAndValue.equals(agencyIdWithSchemeButNoValue)); Assert.assertFalse( "AgencyIds shouldn't match if the second one has a value but the first one's is null," + " even if schemes are the same.", agencyIdWithSchemeButNoValue.equals(agencyIdWithSchemeAndValue)); AgencyId agencyIdOtherOneWithSchemeButNoValue = new AgencyId(AGENCY_SCHEME, null); Assert.assertTrue( "AgencyIds should match if both have the same scheme and both have null values.", agencyIdWithSchemeButNoValue.equals(agencyIdOtherOneWithSchemeButNoValue)); Assert.assertFalse("Version1Language.ENG should not be equal to a String.", Version1Language.ENG.equals("asdf")); Assert.assertFalse("A String should not be equal to Version1Language.ENG.", "asdf".equals(Version1Language.ENG)); Assert.assertNotNull("It should be possible to construct an AgencyId with only a value parameter.", new AgencyId("value only")); class TestAgencyIdAlpha extends AgencyId { public TestAgencyIdAlpha(String scheme, String value) { super(scheme, value); } } TestAgencyIdAlpha testAgencyIdAlpha = new TestAgencyIdAlpha("x", "y"); AgencyId testAgencyIdNonAlpha = new AgencyId("x", "y"); Assert.assertThat("Two objects of the same immediate sub-classes of SchemeValuePair should be equal if" + " their Scheme and Value fields are identical.", testAgencyIdAlpha, equalTo(testAgencyIdNonAlpha)); class TestLanguage extends SchemeValuePair { public TestLanguage(String scheme, String value) { super(scheme, value); } } TestLanguage testLanguageUSEnglish = new TestLanguage(Version1Language.ENG.getScheme(), Version1Language.ENG.getValue()); Assert.assertFalse("Two objects of different immediate sub-classes of SchemeValuePair should not be equal even if" + " their Scheme and Value fields are identical.", testLanguageUSEnglish.equals(Version1Language.ENG)); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof SchemeValuePair)) { return false; } if (!this.isComparableSVPSubclass(o)) { return false; } SchemeValuePair svpO = (SchemeValuePair) o; return matches(svpO.getScheme(), svpO.getValue()); }
SchemeValuePair { @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof SchemeValuePair)) { return false; } if (!this.isComparableSVPSubclass(o)) { return false; } SchemeValuePair svpO = (SchemeValuePair) o; return matches(svpO.getScheme(), svpO.getValue()); } }
SchemeValuePair { @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof SchemeValuePair)) { return false; } if (!this.isComparableSVPSubclass(o)) { return false; } SchemeValuePair svpO = (SchemeValuePair) o; return matches(svpO.getScheme(), svpO.getValue()); } SchemeValuePair(String scheme, String value);  SchemeValuePair(String value); }
SchemeValuePair { @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof SchemeValuePair)) { return false; } if (!this.isComparableSVPSubclass(o)) { return false; } SchemeValuePair svpO = (SchemeValuePair) o; return matches(svpO.getScheme(), svpO.getValue()); } SchemeValuePair(String scheme, String value);  SchemeValuePair(String value); static void allowNullScheme(String... classNames); static void mapBehavior(String className, SchemeValueBehavior behavior); static void setSchemeURIAlias(String canonicalURI, String aliasURI); String getScheme(); String getValue(); @Override boolean equals(Object o); boolean isComparableSVPSubclass(Object o); boolean matches(SchemeValuePair svp); boolean matches(String scheme, String value); boolean areNullSchemesAllowed(); @Override String toString(); }
SchemeValuePair { @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof SchemeValuePair)) { return false; } if (!this.isComparableSVPSubclass(o)) { return false; } SchemeValuePair svpO = (SchemeValuePair) o; return matches(svpO.getScheme(), svpO.getValue()); } SchemeValuePair(String scheme, String value);  SchemeValuePair(String value); static void allowNullScheme(String... classNames); static void mapBehavior(String className, SchemeValueBehavior behavior); static void setSchemeURIAlias(String canonicalURI, String aliasURI); String getScheme(); String getValue(); @Override boolean equals(Object o); boolean isComparableSVPSubclass(Object o); boolean matches(SchemeValuePair svp); boolean matches(String scheme, String value); boolean areNullSchemesAllowed(); @Override String toString();  }