SimpleDOMEntityOwnershipService implements DOMEntityOwnershipService { @Override public DOMEntityOwnershipCandidateRegistration registerCandidate(final DOMEntity entity) throws CandidateAlreadyRegisteredException { synchronized (entities) { final DOMEntity prev = entities.get(entity.getType(), entity.getIdentifier()); if (prev != null) { throw new CandidateAlreadyRegisteredException(prev); } entities.put(entity.getType(), entity.getIdentifier(), entity); LOG.debug("{}: registered candidate {}", uuid, entity); } notifyListeners(entity, LOCAL_OWNERSHIP_GRANTED); return new EntityRegistration(entity); } @VisibleForTesting  SimpleDOMEntityOwnershipService(final UUID uuid);  SimpleDOMEntityOwnershipService(); @Override DOMEntityOwnershipCandidateRegistration registerCandidate(final DOMEntity entity); @Override DOMEntityOwnershipListenerRegistration registerListener(final String entityType,
            final DOMEntityOwnershipListener listener); @Override Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity); @Override boolean isCandidateRegistered(final DOMEntity forEntity); @Override String toString();  }
@Test(expected = CandidateAlreadyRegisteredException.class) public void testDuplicateRegistration() throws CandidateAlreadyRegisteredException { final DOMEntityOwnershipCandidateRegistration reg = service.registerCandidate(FOO_FOO_ENTITY); assertNotNull(reg); service.registerCandidate(FOO_FOO_ENTITY); }