Skip to content

Commit

Permalink
Updated Steps to always have CRLF for inline Cucumber content (and no…
Browse files Browse the repository at this point in the history
…t otherwise).
  • Loading branch information
harmen-xb committed Feb 28, 2024
1 parent 86c5f61 commit c134710
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,38 +218,43 @@ public void iExecuteDecompose() throws Throwable {
@Then("^I expect a composed file '(.*)' with the following content:$")
public void thenIExpectComposedFileWithFollowingContent(String composedFileLocation, String expectedComposedFileContents)
throws Throwable {
thenIExpectTheFileWithFollowingContent(this._composedFolderPath.resolve(composedFileLocation).toFile(), expectedComposedFileContents);
thenIExpectTheFileWithContentFromCucumber(this._composedFolderPath.resolve(composedFileLocation).toFile(), expectedComposedFileContents);
}

@Then("^I expect a composed file with the following content:$")
public void thenIExpectComposedFileWithFollowingContent(String expectedComposedFileContents)
throws Throwable {
thenIExpectTheFileWithFollowingContent(this._composedFilePath.toFile(), expectedComposedFileContents);
thenIExpectTheFileWithContentFromCucumber(this._composedFilePath.toFile(), expectedComposedFileContents);
}

@Then("^I expect a composed file with the content equal to '(.*)'$")
public void thenIExpectComposedFileWithContentEqualToFile(String expectedComposedFileLocation)
throws Throwable {
File expectedComposedFile = this._scenarioResourcePath.resolve(expectedComposedFileLocation).toFile();
String expectedComposedFileContents = PowerDeComposerTestSteps.getFileContents(expectedComposedFile);
thenIExpectTheFileWithFollowingContent(this._composedFilePath.toFile(), expectedComposedFileContents);
thenIExpectTheFileWithContents(this._composedFilePath.toFile(), expectedComposedFileContents);
}

@Then("^I expect a decomposed file '(.*)' with the following content:$")
public void thenIExpectDecomposedFileWithFollowingContent(String decomposedFileLocation, String expectedDecomposedFileContents)
throws Throwable {
thenIExpectTheFileWithFollowingContent(this._decomposedFolderPath.resolve(decomposedFileLocation).toFile(), expectedDecomposedFileContents);
thenIExpectTheFileWithContentFromCucumber(this._decomposedFolderPath.resolve(decomposedFileLocation).toFile(), expectedDecomposedFileContents);
}

@Then("^I expect a decomposed file with the following content:$")
public void thenIExpectDecomposedFileWithFollowingContent(String expectedDecomposedFileContents)
throws Throwable {
thenIExpectTheFileWithFollowingContent(this._decomposedFilePath.toFile(), expectedDecomposedFileContents);
thenIExpectTheFileWithContentFromCucumber(this._decomposedFilePath.toFile(), expectedDecomposedFileContents);
}

// Compare the actual and expected file contents. If it differs throw an assertion error.
public void thenIExpectTheFileWithFollowingContent(File targetFile, String expectedFileContents)
public void thenIExpectTheFileWithContentFromCucumber(File targetFile, String expectedFileContents)
throws Throwable {
// If the file contents is written in Cucumber, the CR is removed, so we need to restore it here.
thenIExpectTheFileWithContents(targetFile, expectedFileContents.replaceAll("(?<!\r)\n", "\r\n"));
}

public void thenIExpectTheFileWithContents(File targetFile, String expectedFileContents) throws IOException {
// Check the file exists.
assertTrue(
targetFile.exists(),
Expand All @@ -258,10 +263,11 @@ public void thenIExpectTheFileWithFollowingContent(File targetFile, String expec

// Get the actual output file and read to string.
String actualResultContent = PowerDeComposerTestSteps.getFileContents(targetFile);

// Assert the expected and actual file contents are the same.
assertEquals(
// When comparing the decomposed results, we need to replace LF with CRLF, since Cucumber will remove the CR.
expectedFileContents.replaceAll("(?<!\r)\n", "\r\n"),
expectedFileContents,
actualResultContent,
"The expected and actual file content is different"
);
Expand Down

0 comments on commit c134710

Please sign in to comment.