diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainServiceTest.java new file mode 100644 index 00000000000..51e75ec26c2 --- /dev/null +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainServiceTest.java @@ -0,0 +1,56 @@ +package tech.jhipster.lite.generator.server.springboot.springcloud.consul.domain; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; + +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.error.domain.GeneratorException; +import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; +import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; +import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectRepository; + +@UnitTest +@ExtendWith(MockitoExtension.class) +class ConsulDomainServiceTest { + + @Mock + ProjectRepository projectRepository; + + @Mock + BuildToolService buildToolService; + + @InjectMocks + ConsulDomainService consulDomainService; + + @Test + void shouldInit() { + Project project = tmpProjectWithPomXml(); + when(buildToolService.getVersion(project, "spring-cloud")).thenReturn(Optional.of("0.0.0")); + + consulDomainService.init(project); + + verify(buildToolService).addProperty(any(Project.class), anyString(), anyString()); + verify(buildToolService).addDependencyManagement(any(Project.class), any(Dependency.class)); + verify(buildToolService, times(3)).addDependency(any(Project.class), any(Dependency.class)); + + verify(projectRepository, times(3)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString(), anyString(), anyString()); + } + + @Test + void shouldNotAddDependencies() { + Project project = tmpProjectWithPomXml(); + + assertThatThrownBy(() -> consulDomainService.addDependencies(project)).isExactlyInstanceOf(GeneratorException.class); + } +}