From db97dc38915cf365c84beee9ff8087b3aef96117 Mon Sep 17 00:00:00 2001 From: tillias Date: Sat, 16 Jan 2021 08:14:23 +0100 Subject: [PATCH] API Tests fix #124 --- .../service/custom/ImportServiceBorderTest.java | 8 +++++--- .../microcatalog/service/custom/ImportServiceTest.java | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/github/microcatalog/service/custom/ImportServiceBorderTest.java b/src/test/java/com/github/microcatalog/service/custom/ImportServiceBorderTest.java index 2770ff6..926bd50 100644 --- a/src/test/java/com/github/microcatalog/service/custom/ImportServiceBorderTest.java +++ b/src/test/java/com/github/microcatalog/service/custom/ImportServiceBorderTest.java @@ -2,6 +2,7 @@ import com.github.microcatalog.domain.Microservice; import com.github.microcatalog.repository.MicroserviceRepository; +import com.github.microcatalog.service.custom.exceptions.ImportException; import com.github.microcatalog.service.dto.custom.FullMicroserviceDto; import com.github.microcatalog.service.dto.custom.MicroserviceImportDescriptorDto; import org.junit.jupiter.api.Test; @@ -12,6 +13,7 @@ import java.util.Optional; import static com.github.microcatalog.service.dto.custom.builder.MicroserviceImportDescriptorDtoBuilder.aMicroserviceImportDescriptorDto; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.BDDMockito.given; @@ -39,8 +41,8 @@ void importFromDescriptor_microserviceWithNameAlreadyExists_NoException() { .withName(name) .build(); - final Optional maybeDto = sut.importFromDescriptor(descriptorDto); - assertFalse(maybeDto.isPresent()); + assertThatThrownBy(() -> sut.importFromDescriptor(descriptorDto)) + .isInstanceOf(ImportException.class) + .hasMessageStartingWith(String.format("Microservice with name (%s) already exists. Stopping import", name)); } - } diff --git a/src/test/java/com/github/microcatalog/service/custom/ImportServiceTest.java b/src/test/java/com/github/microcatalog/service/custom/ImportServiceTest.java index 07a6a01..2c1aacd 100644 --- a/src/test/java/com/github/microcatalog/service/custom/ImportServiceTest.java +++ b/src/test/java/com/github/microcatalog/service/custom/ImportServiceTest.java @@ -47,7 +47,8 @@ void importFromDescriptor_missingName_Exception() { .withName(null) .build(); - assertThatThrownBy(() -> sut.importFromDescriptor(descriptorDto)).isInstanceOf(ImportException.class) + assertThatThrownBy(() -> sut.importFromDescriptor(descriptorDto)) + .isInstanceOf(ImportException.class) .hasMessageStartingWith("Microservice name can't be null"); }