@Test void updateEntityTest() { String repoFullName = "EntityRepo"; Entity entity = Mockito.mock(Entity.class); EntityListener entityListener1 = Mockito.when(Mockito.mock(EntityListener.class).getEntityId()).thenReturn(1).getMock(); EntityListener entityListener2 = Mockito.when(Mockito.mock(EntityListener.class).getEntityId()).thenReturn(1).getMock(); Mockito.when(entity.getIdValue()).thenReturn(1).getMock(); entityListenersService.register(repoFullName); entityListenersService.addEntityListener(repoFullName, entityListener1); entityListenersService.addEntityListener(repoFullName, entityListener2); entityListenersService.updateEntity(repoFullName, entity); Mockito.verify(entityListener1).postUpdate(entity); Mockito.verify(entityListener2).postUpdate(entity); entityListenersService.removeEntityListener(repoFullName, entityListener1); entityListenersService.removeEntityListener(repoFullName, entityListener2); assertTrue(entityListenersService.isEmpty(repoFullName)); }
void updateEntity(String repoFullName, Entity entity) { lock.readLock().lock(); try { verifyRepoRegistered(repoFullName); SetMultimap<Object, EntityListener> entityListeners = this.entityListenersByRepo.get(repoFullName); Set<EntityListener> entityEntityListeners = entityListeners.get(entity.getIdValue()); entityEntityListeners.forEach(entityListener -> entityListener.postUpdate(entity)); } finally { lock.readLock().unlock(); } }
EntityListenersService { void updateEntity(String repoFullName, Entity entity) { lock.readLock().lock(); try { verifyRepoRegistered(repoFullName); SetMultimap<Object, EntityListener> entityListeners = this.entityListenersByRepo.get(repoFullName); Set<EntityListener> entityEntityListeners = entityListeners.get(entity.getIdValue()); entityEntityListeners.forEach(entityListener -> entityListener.postUpdate(entity)); } finally { lock.readLock().unlock(); } } }
EntityListenersService { void updateEntity(String repoFullName, Entity entity) { lock.readLock().lock(); try { verifyRepoRegistered(repoFullName); SetMultimap<Object, EntityListener> entityListeners = this.entityListenersByRepo.get(repoFullName); Set<EntityListener> entityEntityListeners = entityListeners.get(entity.getIdValue()); entityEntityListeners.forEach(entityListener -> entityListener.postUpdate(entity)); } finally { lock.readLock().unlock(); } }  }
EntityListenersService { void updateEntity(String repoFullName, Entity entity) { lock.readLock().lock(); try { verifyRepoRegistered(repoFullName); SetMultimap<Object, EntityListener> entityListeners = this.entityListenersByRepo.get(repoFullName); Set<EntityListener> entityEntityListeners = entityListeners.get(entity.getIdValue()); entityEntityListeners.forEach(entityListener -> entityListener.postUpdate(entity)); } finally { lock.readLock().unlock(); } }  void addEntityListener(String repoFullName, EntityListener entityListener); boolean removeEntityListener(String repoFullName, EntityListener entityListener); }
EntityListenersService { void updateEntity(String repoFullName, Entity entity) { lock.readLock().lock(); try { verifyRepoRegistered(repoFullName); SetMultimap<Object, EntityListener> entityListeners = this.entityListenersByRepo.get(repoFullName); Set<EntityListener> entityEntityListeners = entityListeners.get(entity.getIdValue()); entityEntityListeners.forEach(entityListener -> entityListener.postUpdate(entity)); } finally { lock.readLock().unlock(); } }  void addEntityListener(String repoFullName, EntityListener entityListener); boolean removeEntityListener(String repoFullName, EntityListener entityListener);  }