-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new tests for ConsulDomainService
- Loading branch information
1 parent
2dd1ed4
commit 5c304b9
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...r/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |