Skip to content
Snippets Groups Projects
Commit 59d3cc8d authored by OZGCloud's avatar OZGCloud
Browse files

OZG-7037 add TestFactories

parent 052471a3
No related branches found
No related tags found
No related merge requests found
package de.ozgcloud.apilib.common.command.grpc;
import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsResponse;
import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsResponse.Builder;
public class GrpcExistsPendingCommandsResponseTestFactory {
public static final boolean EXISTS_PENDING_COMMAND = true;
public static GrpcExistsPendingCommandsResponse create() {
return createBuilder().build();
}
public static Builder createBuilder() {
return GrpcExistsPendingCommandsResponse.newBuilder().setExistsPendingCommands(EXISTS_PENDING_COMMAND);
}
}
package de.ozgcloud.apilib.common.command.grpc;
import de.ozgcloud.vorgang.grpc.command.GrpcCommand;
import de.ozgcloud.vorgang.grpc.command.GrpcGetPendingCommandsResponse;
import de.ozgcloud.vorgang.grpc.command.GrpcGetPendingCommandsResponse.Builder;
public class GrpcGetPendingCommandsResponseTestFactory {
public static final GrpcCommand GRPC_COMMAND = GrpcCommandTestFactory.create();
public static GrpcGetPendingCommandsResponse create() {
return createBuilder().build();
}
public static Builder createBuilder() {
return GrpcGetPendingCommandsResponse.newBuilder().addCommand(GRPC_COMMAND);
}
}
...@@ -28,7 +28,6 @@ import de.ozgcloud.vorgang.grpc.command.GrpcCommandsResponse; ...@@ -28,7 +28,6 @@ import de.ozgcloud.vorgang.grpc.command.GrpcCommandsResponse;
import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsRequest; import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsResponse; import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsResponse;
import de.ozgcloud.vorgang.grpc.command.GrpcGetPendingCommandsRequest; import de.ozgcloud.vorgang.grpc.command.GrpcGetPendingCommandsRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcGetPendingCommandsResponse;
class GrpcOzgCloudCommandServiceTest { class GrpcOzgCloudCommandServiceTest {
...@@ -220,7 +219,7 @@ class GrpcOzgCloudCommandServiceTest { ...@@ -220,7 +219,7 @@ class GrpcOzgCloudCommandServiceTest {
void mock() { void mock() {
doReturn(serviceStubWithInterceptor).when(service).getCommandServiceStub(); doReturn(serviceStubWithInterceptor).when(service).getCommandServiceStub();
doReturn(request).when(service).buildExistsPendingCommandRequest(OzgCloudVorgangTestFactory.ID); doReturn(request).when(service).buildExistsPendingCommandRequest(OzgCloudVorgangTestFactory.ID);
var response = GrpcExistsPendingCommandsResponse.newBuilder().setExistsPendingCommands(true).build(); var response = GrpcExistsPendingCommandsResponseTestFactory.create();
when(serviceStubWithInterceptor.existsPendingCommands(any())).thenReturn(response); when(serviceStubWithInterceptor.existsPendingCommands(any())).thenReturn(response);
} }
...@@ -280,14 +279,13 @@ class GrpcOzgCloudCommandServiceTest { ...@@ -280,14 +279,13 @@ class GrpcOzgCloudCommandServiceTest {
@Mock @Mock
private CommandServiceBlockingStub serviceStubWithInterceptor; private CommandServiceBlockingStub serviceStubWithInterceptor;
private final GrpcCommand grpcCommand = GrpcCommandTestFactory.create();
private final OzgCloudCommand command = OzgCloudCommandTestFactory.create(); private final OzgCloudCommand command = OzgCloudCommandTestFactory.create();
@BeforeEach @BeforeEach
void mock() { void mock() {
doReturn(serviceStubWithInterceptor).when(service).getCommandServiceStub(); doReturn(serviceStubWithInterceptor).when(service).getCommandServiceStub();
doReturn(request).when(service).buildGetPendingCommandRequest(any()); doReturn(request).when(service).buildGetPendingCommandRequest(any());
var response = GrpcGetPendingCommandsResponse.newBuilder().addCommand(grpcCommand).build(); var response = GrpcGetPendingCommandsResponseTestFactory.create();
when(serviceStubWithInterceptor.getPendingCommands(any())).thenReturn(response); when(serviceStubWithInterceptor.getPendingCommands(any())).thenReturn(response);
} }
...@@ -316,12 +314,12 @@ class GrpcOzgCloudCommandServiceTest { ...@@ -316,12 +314,12 @@ class GrpcOzgCloudCommandServiceTest {
void shouldCallMapper() { void shouldCallMapper() {
getPendingCommands(); getPendingCommands();
verify(mapper).fromGrpc(grpcCommand); verify(mapper).fromGrpc(GrpcGetPendingCommandsResponseTestFactory.GRPC_COMMAND);
} }
@Test @Test
void shouldReturnPendingCommands() { void shouldReturnPendingCommands() {
when(mapper.fromGrpc(grpcCommand)).thenReturn(command); when(mapper.fromGrpc(GrpcGetPendingCommandsResponseTestFactory.GRPC_COMMAND)).thenReturn(command);
var result = getPendingCommands(); var result = getPendingCommands();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment