PostGovernanceRepositoryEventListener implements GovernanceListener { @Override public final void watch(final ChangedType... changedTypes) { Collection<ChangedType> watchedChangedTypeList = Arrays.asList(changedTypes); for (String watchKey : watchKeys) { watch(watchKey, watchedChangedTypeList); } }  @Override final void watch(final ChangedType... changedTypes);  }
@Test public void assertWatch() { PostGovernanceRepositoryEventListener postEventListener = new PostGovernanceRepositoryEventListener(governanceRepository, Collections.singletonList("test")) { @Override protected Optional<GovernanceEvent> createGovernanceEvent(final DataChangedEvent event) { return Optional.of(mock(GovernanceEvent.class)); } }; doAnswer(invocationOnMock -> { DataChangedEventListener listener = (DataChangedEventListener) invocationOnMock.getArguments()[1]; listener.onChange(new DataChangedEvent("test", "value", ChangedType.UPDATED)); return mock(DataChangedEventListener.class); }).when(governanceRepository).watch(anyString(), any(DataChangedEventListener.class)); postEventListener.watch(ChangedType.UPDATED); verify(governanceRepository).watch(eq("test"), any()); }
@Test public void assertWatchMultipleKey() { PostGovernanceRepositoryEventListener postEventListener = new PostGovernanceRepositoryEventListener(governanceRepository, Arrays.asList("test", "dev")) { @Override protected Optional<GovernanceEvent> createGovernanceEvent(final DataChangedEvent event) { return Optional.of(mock(GovernanceEvent.class)); } }; doAnswer(invocationOnMock -> { DataChangedEventListener listener = (DataChangedEventListener) invocationOnMock.getArguments()[1]; listener.onChange(new DataChangedEvent("test", "value", ChangedType.UPDATED)); return mock(DataChangedEventListener.class); }).when(governanceRepository).watch(anyString(), any(DataChangedEventListener.class)); postEventListener.watch(ChangedType.UPDATED, ChangedType.DELETED); verify(governanceRepository).watch(eq("test"), any()); verify(governanceRepository).watch(eq("dev"), any()); }