diff --git a/src/test/java/com/ribose/jenkins/plugin/awscodecommittrigger/threading/SQSQueueMonitorSchedulerImplTest.java b/src/test/java/com/ribose/jenkins/plugin/awscodecommittrigger/threading/SQSQueueMonitorSchedulerImplTest.java index d15ff46..e514c4e 100644 --- a/src/test/java/com/ribose/jenkins/plugin/awscodecommittrigger/threading/SQSQueueMonitorSchedulerImplTest.java +++ b/src/test/java/com/ribose/jenkins/plugin/awscodecommittrigger/threading/SQSQueueMonitorSchedulerImplTest.java @@ -77,7 +77,7 @@ public void init() { Mockito.when(this.queueB.getMaxNumberOfMessages()).thenReturn(20); Mockito.when(this.queueB.getWaitTimeSeconds()).thenReturn(10); - Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); + Mockito.when(this.provider.getSqsQueue(UUID_B)).thenReturn(this.queueB); this.scheduler = new SQSQueueMonitorSchedulerImpl(this.executor, this.provider, this.factory); @@ -85,11 +85,13 @@ public void init() { @Test public void shouldNotThrowIfUnregisterNullListener() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); assertThat(this.scheduler.unregister(null)).isFalse(); } @Test public void shouldNotThrowIfUnregisterUnknownListener() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); final SQSQueueListener listener = Mockito.mock(SQSQueueListener.class); Mockito.when(listener.getQueueUuid()).thenReturn("unknown"); @@ -100,6 +102,7 @@ public void shouldNotThrowIfUnregisterUnknownListener() { @Test public void shouldStartMonitorForFirstListener() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); final boolean result = this.scheduler.register(this.listenerA1); assertThat(result).isTrue(); @@ -110,6 +113,7 @@ public void shouldStartMonitorForFirstListener() { @Test public void shouldUseSingleMonitorInstancePerQueue() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); this.scheduler.register(this.listenerA1); Mockito.verify(this.provider, times(1)).getSqsQueue(UUID_A); Mockito.verify(this.factory).createMonitor(this.executor, this.queueA); @@ -125,6 +129,7 @@ public void shouldUseSingleMonitorInstancePerQueue() { @Test public void shouldUseSeparateMonitorInstanceForEachQueue() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); this.scheduler.register(this.listenerA1); Mockito.verify(this.provider, times(1)).getSqsQueue(UUID_A); Mockito.verify(this.factory).createMonitor(this.executor, this.queueA); @@ -141,6 +146,7 @@ public void shouldUseSeparateMonitorInstanceForEachQueue() { @Test public void shouldReuseMonitorInstaceForListenerOfSameQueue() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); this.scheduler.register(this.listenerA1); this.scheduler.register(this.listenerB1); Mockito.verify(this.provider, times(1)).getSqsQueue(UUID_A); @@ -162,6 +168,7 @@ public void shouldReuseMonitorInstaceForListenerOfSameQueue() { @Test public void shouldNotCreateMonitorForUnknownQueue() { + Mockito.when(this.provider.getSqsQueue("unknown")).thenReturn(null); final SQSQueueListener listener = Mockito.mock(SQSQueueListener.class); Mockito.when(listener.getQueueUuid()).thenReturn("unknown"); @@ -174,6 +181,7 @@ public void shouldNotCreateMonitorForUnknownQueue() { @Test public void shouldCreateNewMonitorAfterUnregisterLast() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); this.scheduler.register(this.listenerA1); this.scheduler.unregister(this.listenerA1); Mockito.verify(this.provider, times(1)).getSqsQueue(UUID_A); @@ -191,6 +199,7 @@ public void shouldCreateNewMonitorAfterUnregisterLast() { @Test public void shouldNotCreateNewMonitorIfMoreListenersOnUnregister() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); this.scheduler.register(this.listenerA1); this.scheduler.register(this.listenerA2); this.scheduler.unregister(this.listenerA1); @@ -208,6 +217,7 @@ public void shouldNotCreateNewMonitorIfMoreListenersOnUnregister() { @Test public void shouldDoNothingOnConfigurationChangedIfUnchanged() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); this.scheduler.register(this.listenerA1); this.scheduler.register(this.listenerB1); Mockito.verify(this.factory).createMonitor(this.executor, this.queueA); @@ -228,6 +238,7 @@ public void shouldDoNothingOnConfigurationChangedIfUnchanged() { @Test public void shouldStartNewMonitorOnConfigurationChangedIfChanged() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); final SQSQueue queueA_ = Mockito.mock(SQSQueue.class); final SQSQueueMonitor monitorA_ = Mockito.mock(SQSQueueMonitor.class); this.scheduler.register(this.listenerA1); @@ -251,6 +262,7 @@ public void shouldStartNewMonitorOnConfigurationChangedIfChanged() { @Test public void shouldDoNothingOnConfigurationChangedIfPropertiesEqual() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); final SQSQueue queueA_ = Mockito.mock(SQSQueue.class); final SQSQueueMonitor monitorA_ = Mockito.mock(SQSQueueMonitor.class); this.scheduler.register(this.listenerA1); @@ -276,6 +288,7 @@ public void shouldDoNothingOnConfigurationChangedIfPropertiesEqual() { @Test public void shouldStopMonitorOnConfigurationChangedIfQueueRemoved() { + Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA); this.scheduler.register(this.listenerA1); this.scheduler.register(this.listenerB1); Mockito.verify(this.factory).createMonitor(this.executor, this.queueA);