Skip to content

Commit

Permalink
Merge pull request #1841 from pascalgrimaud/init-cucumber
Browse files Browse the repository at this point in the history
Init: use cucumber for tests
  • Loading branch information
pascalgrimaud authored May 25, 2022
2 parents 8025281 + b99dd38 commit f794b0f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 61 deletions.
38 changes: 38 additions & 0 deletions src/test/features/init.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Feature: Init

Scenario: Should init
When I init default project
Then I should have files in ""
| .gitignore |
| .gitattributes |
| .editorconfig |
| .eslintignore |
| .lintstagedrc.js |
| .prettierignore |
| .prettierrc |
| package.json |
| README.md |
And I should have files in ".husky"
| pre-commit |
And I should have files in ".git"
| config |
| HEAD |

Scenario: Should init minimal
When I init minimal default project
Then I should have files in ""
| .gitignore |
| .gitattributes |
| .editorconfig |
| .eslintignore |
| README.md |
And I should have files in ".git"
| config |
| HEAD |
And I should not have files in ""
| .lintstagedrc.js |
| .prettierignore |
| .prettierrc |
| package.json |
And I should not have files in ".husky"
| pre-commit |
19 changes: 19 additions & 0 deletions src/test/java/tech/jhipster/lite/generator/ProjectsSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ private Supplier<String> fileNotFoundMessage(Path path) {
return () -> "Can't find file " + path + " in project folder, found " + projectFiles();
}

@Then("I should not have files in {string}")
public void shouldNotHaveFiles(String basePath, List<String> files) {
CucumberAssertions.assertThatLastResponse().hasOkStatus();

SoftAssertions assertions = new SoftAssertions();

files.stream().map(file -> Paths.get(lastProjectFolder, basePath, file)).forEach(assertFileNotExist(assertions));

assertions.assertAll();
}

private Consumer<Path> assertFileNotExist(SoftAssertions assertions) {
return path -> assertions.assertThat(!Files.exists(path)).as(fileFoundMessage(path)).isTrue();
}

private Supplier<String> fileFoundMessage(Path path) {
return () -> "Can find file " + path + " in project folder, found " + projectFiles();
}

private String projectFiles() {
try {
return Files.walk(Paths.get(lastProjectFolder)).filter(Files::isRegularFile).map(Path::toString).collect(Collectors.joining(", "));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tech.jhipster.lite.generator.init.infrastructure.primary.rest;

import io.cucumber.java.en.When;
import tech.jhipster.lite.generator.ModulesSteps;

public class InitSteps extends ModulesSteps {

@When("I init default project")
public void initFull() {
applyModuleForDefaultProject("/api/inits/full");
}

@When("I init minimal default project")
public void initMinimal() {
applyModuleForDefaultProject("/api/inits/minimal");
}
}

0 comments on commit f794b0f

Please sign in to comment.