Skip to content

Commit

Permalink
Add new tests for ConsulDomainService
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielFran committed Feb 3, 2022
1 parent 2dd1ed4 commit 5c304b9
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 5c304b9

Please sign in to comment.