diff --git a/api-lib-core/src/main/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandService.java b/api-lib-core/src/main/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandService.java index 8e8c8c39fe4877fd722df4e50f061f4ccd59e467..4a3d26f0263a05d2d693123851831442f2793a23 100644 --- a/api-lib-core/src/main/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandService.java +++ b/api-lib-core/src/main/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandService.java @@ -50,9 +50,7 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService { } } } - if (hasErrorStatus(command)) { - throw new TechnicalException("Command (id=%s) failed: %s".formatted(command.getId(), command.getErrorMessage())); - } + verifyCommand(command); return command; } @@ -65,7 +63,9 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService { return commandServiceStub.withInterceptors(new OzgCloudCallContextAttachingInterceptor(contextProvider)); } - boolean hasErrorStatus(OzgCloudCommand command) { - return command.getStatus() == OzgCloudCommandStatus.ERROR; + void verifyCommand(OzgCloudCommand command) { + if (command.getStatus() == OzgCloudCommandStatus.ERROR) { + throw new TechnicalException("Command (id=%s) failed: %s".formatted(command.getId(), command.getErrorMessage())); + } } } diff --git a/api-lib-core/src/test/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandServiceTest.java b/api-lib-core/src/test/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandServiceTest.java index 23eac1edfe6660a17e9db81aedbb550c67594d38..f032df3ffb8ef830387313695aacbb669ecf841a 100644 --- a/api-lib-core/src/test/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandServiceTest.java +++ b/api-lib-core/src/test/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandServiceTest.java @@ -1,6 +1,7 @@ package de.ozgcloud.apilib.common.command.grpc; import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -68,10 +69,10 @@ class GrpcOzgCloudCommandServiceTest { } @Test - void shouldThrowException() { - var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.ERROR).build(); + void shouldCallVerifyCommand() { + service.waitUntilDone(command); - Assertions.assertThrows(TechnicalException.class, () -> service.waitUntilDone(command)); + verify(service).verifyCommand(command); } @Nested @@ -123,12 +124,10 @@ class GrpcOzgCloudCommandServiceTest { class TestStatus { @Test - void shouldReturnTrueByError() { + void shouldThrowException() { var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.ERROR).build(); - var result = service.hasErrorStatus(command); - - assertThat(result).isTrue(); + assertThrows(TechnicalException.class, () -> service.verifyCommand(command)); } }