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, Behavior 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();  }
@Test public void testEquals() { Assert.assertEquals(Version1Language.AAR, Version1Language.AAR); Assert.assertNotSame(Version1Language.AAR, Version1Language.ENG); String AGENCY_SCHEME = "http: String AGENCY_ONE_VALUE = "One"; String AGENCY_TWO_VALUE = "Two"; AgencyId agencyIdOne = new AgencyId(null, AGENCY_ONE_VALUE); AgencyId agencyIdOtherOne = new AgencyId(null, AGENCY_ONE_VALUE); Assert.assertEquals(agencyIdOne, agencyIdOtherOne); Assert.assertNotSame(agencyIdOne, agencyIdOtherOne); AgencyId agencyIdOneWithScheme = new AgencyId(AGENCY_SCHEME, AGENCY_ONE_VALUE); AgencyId agencyIdOtherOneWithScheme = new AgencyId(AGENCY_SCHEME, AGENCY_ONE_VALUE); Assert.assertEquals(agencyIdOneWithScheme, agencyIdOtherOneWithScheme); Assert.assertNotSame(agencyIdOneWithScheme, agencyIdOtherOneWithScheme); AgencyId agencyIdOneViaFind = null; try { agencyIdOneViaFind = AgencyId.find(null, AGENCY_ONE_VALUE); } catch (ServiceException e) { Assert.fail("AgencyId.find() method threw exception for scheme 'null' and value '" + AGENCY_ONE_VALUE + "' - was AgencyId set to allow any in configuration?"); } AgencyId agencyIdOtherOneViaFind = null; try { agencyIdOtherOneViaFind = AgencyId.find(null, AGENCY_ONE_VALUE); } catch (ServiceException e) { Assert.fail("AgencyId.find() method threw exception for scheme 'null' and value '" + AGENCY_ONE_VALUE + "' - was AgencyId set to allow any in configuration?"); } Assert.assertEquals(agencyIdOneViaFind, agencyIdOtherOneViaFind); Assert.assertSame(agencyIdOneViaFind, agencyIdOtherOneViaFind); AgencyId agencyIdOneWithSchemeViaFind = null; try { agencyIdOneWithSchemeViaFind = AgencyId.find(AGENCY_SCHEME, AGENCY_ONE_VALUE); } catch (ServiceException e) { Assert.fail("AgencyId.find() method threw exception for scheme '" + AGENCY_SCHEME + "' and value '" + AGENCY_ONE_VALUE + "' - was AgencyId set to allow any in configuration?"); } AgencyId agencyIdOtherOneWithSchemeViaFind = null; try { agencyIdOtherOneWithSchemeViaFind = AgencyId.find(AGENCY_SCHEME, AGENCY_ONE_VALUE); } catch (ServiceException e) { Assert.fail("AgencyId.find() method threw exception for scheme '" + AGENCY_SCHEME + "' and value '" + AGENCY_ONE_VALUE + "' - was AgencyId set to allow any in configuration?"); } Assert.assertEquals(agencyIdOneWithSchemeViaFind, agencyIdOtherOneWithSchemeViaFind); Assert.assertSame(agencyIdOneWithSchemeViaFind, agencyIdOtherOneWithSchemeViaFind); String GPE_ALIAS_SCHEME = "http: ProblemType genProcErrorWithAliasViaFind = null; try { genProcErrorWithAliasViaFind = Version1GeneralProcessingError.find( GPE_ALIAS_SCHEME, Version1GeneralProcessingError.AGENCY_AUTHENTICATION_FAILED.getValue()); } catch (ServiceException e) { Assert.fail("Version1GeneralProcessingError.find() method threw exception for scheme '" + GPE_ALIAS_SCHEME + "' and value '" + Version1GeneralProcessingError.AGENCY_AUTHENTICATION_FAILED + "' - is " + GPE_ALIAS_SCHEME + " set as an alias for " + Version1GeneralProcessingError.VERSION_1_GENERAL_PROCESSING_ERROR + "?"); } Assert.assertEquals(genProcErrorWithAliasViaFind, Version1GeneralProcessingError.AGENCY_AUTHENTICATION_FAILED); Assert.assertSame(genProcErrorWithAliasViaFind, Version1GeneralProcessingError.AGENCY_AUTHENTICATION_FAILED); SchemeValuePair.allowNullScheme(FiscalActionType.class.getName()); FiscalActionType fiscalActionTypeWithNullScheme = new FiscalActionType(null, Version1FiscalActionType.CANCEL.getValue()); Assert.assertTrue("Allow null for scheme doesn't work.", Version1FiscalActionType.CANCEL.matches(fiscalActionTypeWithNullScheme)); Language languageCopy = new Language(Version1Language.ZAP.getScheme(), Version1Language.ZAP.getValue()); Assert.assertEquals(Version1Language.ZAP, languageCopy); Language foundLanguage = null; try { foundLanguage = Language.find(Version1Language.ZAP.getScheme(), Version1Language.ZAP.getValue()); Assert.assertEquals(Version1Language.ZAP, foundLanguage); } catch (ServiceException e) { Assert.fail("Version1Language.ZAP not found via call to Language.find() method " + " - was Version1Language loaded in configuration?"); } String BAD_LANGUAGE_SCHEME = "junk"; String BAD_LANGUAGE_VALUE = "zippy"; String GOOD_LANGUAGE_SCHEME = Version1Language.ZAP.getScheme(); String GOOD_LANGUAGE_VALUE = Version1Language.ZAP.getValue(); try { Language unfoundSchemeLanguage = Language.find(BAD_LANGUAGE_SCHEME, GOOD_LANGUAGE_VALUE); Assert.fail("Language.find(\"" + BAD_LANGUAGE_SCHEME + "\"), \"" + GOOD_LANGUAGE_VALUE + "\") succeeded when it should fail as there's no such language Scheme URI."); } catch (ServiceException e) { Assert.assertTrue(e.getLocalizedMessage().matches("(?i).*no match found for scheme .*")); } try { Language unfoundValueLanguage = Language.find(GOOD_LANGUAGE_SCHEME, BAD_LANGUAGE_VALUE); Assert.fail("Language.find(\"" + GOOD_LANGUAGE_SCHEME + "\"), \"" + BAD_LANGUAGE_VALUE + "\") " + " succeeded when it should fail as there's no such value in the Language Scheme(s)."); } catch (ServiceException e) { Assert.assertTrue(e.getLocalizedMessage().matches("(?i).*no match found for scheme .*")); } 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)); }