Skip to content

Commit

Permalink
fix: replaced deprecated method
Browse files Browse the repository at this point in the history
  • Loading branch information
daho4b committed Sep 10, 2021
1 parent 425fa4e commit b994f78
Showing 1 changed file with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package de.caritas.cob.messageservice.api.service;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.powermock.reflect.Whitebox.setInternalState;

Expand All @@ -26,17 +25,13 @@
@RunWith(MockitoJUnitRunner.class)
public class LiveEventNotificationServiceTest {

@InjectMocks
private LiveEventNotificationService liveEventNotificationService;
@InjectMocks private LiveEventNotificationService liveEventNotificationService;

@Mock
private LiveproxyControllerApi liveproxyControllerApi;
@Mock private LiveproxyControllerApi liveproxyControllerApi;

@Mock
private ServiceHelper serviceHelper;
@Mock private ServiceHelper serviceHelper;

@Mock
private Logger logger;
@Mock private Logger logger;

@Before
public void setup() {
Expand All @@ -47,16 +42,16 @@ public void setup() {
public void sendLiveEvent_Should_notTriggerLiveEvent_When_rcGroupIdIsNull() {
this.liveEventNotificationService.sendLiveEvent(null);

verifyZeroInteractions(this.liveproxyControllerApi);
verifyZeroInteractions(this.serviceHelper);
verifyNoMoreInteractions(this.liveproxyControllerApi);
verifyNoMoreInteractions(this.serviceHelper);
}

@Test
public void sendLiveEvent_Should_notTriggerLiveEvent_When_rcGroupIdIsEmpty() {
this.liveEventNotificationService.sendLiveEvent("");

verifyZeroInteractions(this.liveproxyControllerApi);
verifyZeroInteractions(this.serviceHelper);
verifyNoMoreInteractions(this.liveproxyControllerApi);
verifyNoMoreInteractions(this.serviceHelper);
}

@Test
Expand All @@ -70,14 +65,15 @@ public void sendLiveEvent_Should_triggerLiveEventWithHeaders_When_rcGroupIdIsVal

this.liveEventNotificationService.sendLiveEvent("valid");

verify(this.liveproxyControllerApi, times(1)).sendLiveEvent(eq("valid"));
verify(this.liveproxyControllerApi, times(1)).sendLiveEvent("valid");
verify(this.serviceHelper, times(1)).getKeycloakAndCsrfHttpHeaders();
verify(apiClient, times(2)).addDefaultHeader(anyString(), anyString());
}

@Test
public void sendLiveEvent_Should_logError_When_apiClientThrowsRestClientException() {
doThrow(new RestClientException("")).when(this.liveproxyControllerApi)
doThrow(new RestClientException(""))
.when(this.liveproxyControllerApi)
.sendLiveEvent(anyString());
when(this.liveproxyControllerApi.getApiClient()).thenReturn(mock(ApiClient.class));
when(this.serviceHelper.getKeycloakAndCsrfHttpHeaders()).thenReturn(new HttpHeaders());
Expand All @@ -86,5 +82,4 @@ public void sendLiveEvent_Should_logError_When_apiClientThrowsRestClientExceptio

verify(this.logger, times(1)).error(anyString(), anyString(), anyString());
}

}

0 comments on commit b994f78

Please sign in to comment.