@Test void registerTest() { String repoFullName = "EntityRepo"; entityListenersService.register(repoFullName); EntityListener entityListener1 = Mockito.when(Mockito.mock(EntityListener.class).getEntityId()).thenReturn(1).getMock(); EntityListener entityListener2 = Mockito.when(Mockito.mock(EntityListener.class).getEntityId()).thenReturn(2).getMock(); entityListenersService.addEntityListener(repoFullName, entityListener1); entityListenersService.addEntityListener(repoFullName, entityListener2); assertFalse(entityListenersService.isEmpty(repoFullName)); entityListenersService.register(repoFullName); assertFalse(entityListenersService.isEmpty(repoFullName)); entityListenersService.removeEntityListener(repoFullName, entityListener1); entityListenersService.removeEntityListener(repoFullName, entityListener2); assertTrue(entityListenersService.isEmpty(repoFullName)); }
void register(String repoFullName) { lock.writeLock().lock(); try { if (!entityListenersByRepo.containsKey(requireNonNull(repoFullName))) { entityListenersByRepo.put(repoFullName, HashMultimap.create()); } } finally { lock.writeLock().unlock(); } }
EntityListenersService { void register(String repoFullName) { lock.writeLock().lock(); try { if (!entityListenersByRepo.containsKey(requireNonNull(repoFullName))) { entityListenersByRepo.put(repoFullName, HashMultimap.create()); } } finally { lock.writeLock().unlock(); } } }
EntityListenersService { void register(String repoFullName) { lock.writeLock().lock(); try { if (!entityListenersByRepo.containsKey(requireNonNull(repoFullName))) { entityListenersByRepo.put(repoFullName, HashMultimap.create()); } } finally { lock.writeLock().unlock(); } }  }
EntityListenersService { void register(String repoFullName) { lock.writeLock().lock(); try { if (!entityListenersByRepo.containsKey(requireNonNull(repoFullName))) { entityListenersByRepo.put(repoFullName, HashMultimap.create()); } } finally { lock.writeLock().unlock(); } }  void addEntityListener(String repoFullName, EntityListener entityListener); boolean removeEntityListener(String repoFullName, EntityListener entityListener); }
EntityListenersService { void register(String repoFullName) { lock.writeLock().lock(); try { if (!entityListenersByRepo.containsKey(requireNonNull(repoFullName))) { entityListenersByRepo.put(repoFullName, HashMultimap.create()); } } finally { lock.writeLock().unlock(); } }  void addEntityListener(String repoFullName, EntityListener entityListener); boolean removeEntityListener(String repoFullName, EntityListener entityListener);  }