XmlExternalIdValidator { public synchronized void validateExternalId(ExternalId externalSystemId, String tradeId) { if (_existingMappings.containsKey(externalSystemId)) { String previousTradeId = _existingMappings.get(externalSystemId); if (!previousTradeId.equals(tradeId)) { String message = MessageFormatter.arrayFormat( "External id '{}' already allocated to a different trade when processing this file. Previous trade id: '{}', this trade id: '{}'", new Object[] {externalSystemId, previousTradeId, tradeId }).getMessage(); throw new OpenGammaRuntimeException(message); } } _existingMappings.put(externalSystemId, tradeId); }  synchronized void validateExternalId(ExternalId externalSystemId, String tradeId);  }
@Test(expectedExceptions = OpenGammaRuntimeException.class) public void testInvalidId() { _validator.validateExternalId(ExternalId.of("scheme1", "id1"), "id1"); _validator.validateExternalId(ExternalId.of("scheme1", "id1"), "id2"); }