Skip to content

Commit

Permalink
Remove code (times(1)) that is not needed in test files.
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Labordus <dennis.labordus@alliander.com>
  • Loading branch information
Dennis Labordus committed Nov 15, 2022
1 parent 9a4053f commit 3e83d94
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void list_WhenCalled_ThenItemResponseRetrieved() {
assertEquals(name, xmlPath.get("ListResponse.Item[0].Name"));
assertEquals(version, xmlPath.get("ListResponse.Item[0].Version"));
assertEquals(labels.get(0), xmlPath.get("ListResponse.Item[0].Label"));
verify(compasSclDataService, times(1)).list(type);
verify(compasSclDataService).list(type);
}

@Test
Expand All @@ -95,7 +95,7 @@ void listVersionsByUUID_WhenCalled_ThenItemResponseRetrieved() {
assertEquals(uuid.toString(), xmlPath.get("VersionsResponse.HistoryItem[0].Id"));
assertEquals(name, xmlPath.get("VersionsResponse.HistoryItem[0].Name"));
assertEquals(version, xmlPath.get("VersionsResponse.HistoryItem[0].Version"));
verify(compasSclDataService, times(1)).listVersionsByUUID(type, uuid);
verify(compasSclDataService).listVersionsByUUID(type, uuid);
}

@Test
Expand All @@ -118,7 +118,7 @@ void findByUUID_WhenCalled_ThenSCLResponseRetrieved() throws IOException {
var xmlPath = response.xmlPath()
.using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI));
assertEquals(scl, xmlPath.get("GetWsResponse.SclData"));
verify(compasSclDataService, times(1)).findByUUID(type, uuid);
verify(compasSclDataService).findByUUID(type, uuid);
}

@Test
Expand All @@ -143,7 +143,7 @@ void findByUUIDAndVersion_WhenCalled_ThenSCLResponseRetrieved() throws IOExcepti
var xmlPath = response.xmlPath()
.using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI));
assertEquals(scl, xmlPath.get("GetWsResponse.SclData"));
verify(compasSclDataService, times(1)).findByUUID(type, uuid, version);
verify(compasSclDataService).findByUUID(type, uuid, version);
}

@Test
Expand Down Expand Up @@ -171,7 +171,7 @@ void create_WhenCalled_ThenServiceCalledAndUUIDRetrieved() throws IOException {
.response();

assertEquals(scl, response.xmlPath().getString("CreateWsResponse.SclData"));
verify(compasSclDataService, times(1)).create(type, name, USERNAME, comment, scl);
verify(compasSclDataService).create(type, name, USERNAME, comment, scl);
}

@Test
Expand Down Expand Up @@ -228,7 +228,7 @@ void update_WhenCalled_ThenServiceCalledAndNewUUIDRetrieved() throws IOException
.response();

assertEquals(scl, response.xmlPath().getString("CreateWsResponse.SclData"));
verify(compasSclDataService, times(1)).update(type, uuid, changeSetType, USERNAME, comment, scl);
verify(compasSclDataService).update(type, uuid, changeSetType, USERNAME, comment, scl);
}

@Test
Expand All @@ -245,7 +245,7 @@ void deleteAll_WhenCalled_ThenServiceCalled() {
.then()
.statusCode(204);

verify(compasSclDataService, times(1)).delete(type, uuid);
verify(compasSclDataService).delete(type, uuid);
}

@Test
Expand All @@ -264,7 +264,7 @@ void deleteVersion_WhenCalled_ThenServiceCalled() {
.then()
.statusCode(204);

verify(compasSclDataService, times(1)).delete(type, uuid, version);
verify(compasSclDataService).delete(type, uuid, version);
}

private String readSCL() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void list_WhenCalled_ThenItemResponseRetrieved() {
assertEquals(name, xmlPath.get("ListResponse.Item[0].Name"));
assertEquals(version, xmlPath.get("ListResponse.Item[0].Version"));
assertEquals(labels.get(0), xmlPath.get("ListResponse.Item[0].Label"));
verify(compasSclDataService, times(1)).list(type);
verify(compasSclDataService).list(type);
}

@Test
Expand All @@ -87,7 +87,7 @@ void listVersionsByUUID_WhenCalled_ThenItemResponseRetrieved() {
assertEquals(uuid.toString(), xmlPath.get("VersionsResponse.HistoryItem[0].Id"));
assertEquals(name, xmlPath.get("VersionsResponse.HistoryItem[0].Name"));
assertEquals(version, xmlPath.get("VersionsResponse.HistoryItem[0].Version"));
verify(compasSclDataService, times(1)).listVersionsByUUID(type, uuid);
verify(compasSclDataService).listVersionsByUUID(type, uuid);
}

@Test
Expand All @@ -110,7 +110,7 @@ void findByUUID_WhenCalled_ThenSCLResponseRetrieved() throws IOException {
var xmlPath = response.xmlPath()
.using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI));
assertEquals(scl, xmlPath.get("GetWsResponse.SclData"));
verify(compasSclDataService, times(1)).findByUUID(type, uuid);
verify(compasSclDataService).findByUUID(type, uuid);
}

@Test
Expand All @@ -135,7 +135,7 @@ void findByUUIDAndVersion_WhenCalled_ThenSCLResponseRetrieved() throws IOExcepti
var xmlPath = response.xmlPath()
.using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI));
assertEquals(scl, xmlPath.get("GetWsResponse.SclData"));
verify(compasSclDataService, times(1)).findByUUID(type, uuid, version);
verify(compasSclDataService).findByUUID(type, uuid, version);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_GENERAL_ERROR_CODE;
import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.DUPLICATE_SCL_NAME_ERROR_CODE;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class CompasSclDataEventHandlerTest {
Expand All @@ -57,7 +58,7 @@ void createWebsocketsEvent_WhenCalled_ThenCreateResponseReturned() {

var response = verifyResponse(session, CreateWsResponse.class);
assertEquals(sclData, response.getSclData());
verify(service, times(1)).create(type, name, who, comment, sclData);
verify(service).create(type, name, who, comment, sclData);
}

@Test
Expand All @@ -77,7 +78,7 @@ void createWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenError
eventHandler.createWebsocketsEvent(request);

verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage);
verify(service, times(1)).create(type, name, who, comment, sclData);
verify(service).create(type, name, who, comment, sclData);
}

@Test
Expand All @@ -96,7 +97,7 @@ void createWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErro
eventHandler.createWebsocketsEvent(request);

verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage);
verify(service, times(1)).create(type, name, who, comment, sclData);
verify(service).create(type, name, who, comment, sclData);
}

@Test
Expand All @@ -113,7 +114,7 @@ void getWebsocketsEvent_WhenCalled_ThenGetResponseReturned() {

var response = verifyResponse(session, GetWsResponse.class);
assertEquals(sclData, response.getSclData());
verify(service, times(1)).findByUUID(type, id);
verify(service).findByUUID(type, id);
}

@Test
Expand All @@ -130,7 +131,7 @@ void getWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenErrorRes
eventHandler.getWebsocketsEvent(request);

verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage);
verify(service, times(1)).findByUUID(type, id);
verify(service).findByUUID(type, id);
}

@Test
Expand All @@ -146,7 +147,7 @@ void getWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErrorRe
eventHandler.getWebsocketsEvent(request);

verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage);
verify(service, times(1)).findByUUID(type, id);
verify(service).findByUUID(type, id);
}

@Test
Expand All @@ -164,7 +165,7 @@ void getVersionWebsocketsEvent_WhenCalled_ThenGetResponseReturned() {

var response = verifyResponse(session, GetWsResponse.class);
assertEquals(sclData, response.getSclData());
verify(service, times(1)).findByUUID(type, id, version);
verify(service).findByUUID(type, id, version);
}

@Test
Expand All @@ -182,7 +183,7 @@ void getVersionWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenE
eventHandler.getVersionWebsocketsEvent(request);

verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage);
verify(service, times(1)).findByUUID(type, id, version);
verify(service).findByUUID(type, id, version);
}

@Test
Expand All @@ -199,7 +200,7 @@ void getVersionWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_Then
eventHandler.getVersionWebsocketsEvent(request);

verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage);
verify(service, times(1)).findByUUID(type, id, version);
verify(service).findByUUID(type, id, version);
}

@Test
Expand All @@ -219,7 +220,7 @@ void updateWebsocketsEvent_WhenCalled_ThenUpdateResponseReturned() {

var response = verifyResponse(session, UpdateWsResponse.class);
assertEquals(sclData, response.getSclData());
verify(service, times(1)).update(type, id, cst, who, comment, sclData);
verify(service).update(type, id, cst, who, comment, sclData);
}

@Test
Expand All @@ -240,7 +241,7 @@ void updateWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenError
eventHandler.updateWebsocketsEvent(request);

verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage);
verify(service, times(1)).update(type, id, cst, who, comment, sclData);
verify(service).update(type, id, cst, who, comment, sclData);
}

@Test
Expand All @@ -260,7 +261,7 @@ void updateWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErro
eventHandler.updateWebsocketsEvent(request);

verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage);
verify(service, times(1)).update(type, id, cst, who, comment, sclData);
verify(service).update(type, id, cst, who, comment, sclData);
}

private Session mockSession() {
Expand All @@ -271,16 +272,16 @@ private Session mockSession() {
}

private <T> T verifyResponse(Session session, Class<T> responseClass) {
verify(session, times(1)).getAsyncRemote();
verify(session).getAsyncRemote();
ArgumentCaptor<T> captor = ArgumentCaptor.forClass(responseClass);
verify(session.getAsyncRemote(), times(1)).sendObject(captor.capture());
verify(session.getAsyncRemote()).sendObject(captor.capture());
return captor.getValue();
}

private void verifyErrorResponse(Session session, String errorCode, String errorMessage) {
verify(session, times(1)).getAsyncRemote();
verify(session).getAsyncRemote();
ArgumentCaptor<ErrorResponse> captor = ArgumentCaptor.forClass(ErrorResponse.class);
verify(session.getAsyncRemote(), times(1)).sendObject(captor.capture());
verify(session.getAsyncRemote()).sendObject(captor.capture());
var response = captor.getValue();
assertEquals(1, response.getErrorMessages().size());
var message = response.getErrorMessages().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import javax.websocket.Session;
import java.net.URI;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@QuarkusTest
class CompasSclCreateServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport {
Expand Down Expand Up @@ -50,7 +51,7 @@ void createSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception {
session.getAsyncRemote().sendText(encoder.encode(request));

assertSclData(sclData);
verify(service, times(1)).create(sclFileTye, name, USERNAME, comment, sclData);
verify(service).create(sclFileTye, name, USERNAME, comment, sclData);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.net.URI;
import java.util.UUID;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@QuarkusTest
class CompasSclGetServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport {
Expand All @@ -47,7 +48,7 @@ void getSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception {
session.getAsyncRemote().sendText(encoder.encode(request));

assertSclData(sclData);
verify(service, times(1)).findByUUID(sclFileTye, id);
verify(service).findByUUID(sclFileTye, id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.net.URI;
import java.util.UUID;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@QuarkusTest
class CompasSclGetServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTestSupport {
Expand All @@ -47,7 +48,7 @@ void getSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception {
session.getAsyncRemote().sendText(encoder.encode(request));

assertSclData(sclData);
verify(service, times(1)).findByUUID(sclFileTye, id);
verify(service).findByUUID(sclFileTye, id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.net.URI;
import java.util.UUID;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@QuarkusTest
class CompasSclGetVersionServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport {
Expand Down Expand Up @@ -50,7 +51,7 @@ void getVersionSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception
session.getAsyncRemote().sendText(encoder.encode(request));

assertSclData(sclData);
verify(service, times(1)).findByUUID(sclFileTye, id, version);
verify(service).findByUUID(sclFileTye, id, version);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.net.URI;
import java.util.UUID;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@QuarkusTest
class CompasSclGetVersionServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTestSupport {
Expand Down Expand Up @@ -50,7 +51,7 @@ void getVersionSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception
session.getAsyncRemote().sendText(encoder.encode(request));

assertSclData(sclData);
verify(service, times(1)).findByUUID(sclFileTye, id, version);
verify(service).findByUUID(sclFileTye, id, version);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.net.URI;
import java.util.UUID;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@QuarkusTest
class CompasSclUpdateServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport {
Expand Down Expand Up @@ -54,7 +55,7 @@ void updateSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception {
session.getAsyncRemote().sendText(encoder.encode(request));

assertSclData(sclData);
verify(service, times(1)).update(sclFileTye, id, cst, USERNAME, comment, sclData);
verify(service).update(sclFileTye, id, cst, USERNAME, comment, sclData);
}
}

Expand Down
Loading

0 comments on commit 3e83d94

Please sign in to comment.