-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-69384 - SerenityJsonSummaryFile: Add support for missing work…
…space (#171) * SerenityJsonSummaryFile: Check for missing workspace (#163) * add tests for SerenityJsonSummaryFile * when called outside of a workspace, workspace is null -> added check for that edge case to avoid passing in null to Paths.get(), which avoids NPE on Java 17 * Remove null check for serenityjsonfile (#163) serenityjsonfile is never null, so reduce unnecessary clutter.
- Loading branch information
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
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
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
54 changes: 54 additions & 0 deletions
54
...test/java/jenkinsci/plugins/influxdb/generators/serenity/SerenityJsonSummaryFileTest.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,54 @@ | ||
package jenkinsci.plugins.influxdb.generators.serenity; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class SerenityJsonSummaryFileTest { | ||
@Rule | ||
public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void testAvailableSummary() throws Exception { | ||
writeToTemporaryPath("target/site/serenity/serenity-summary.json", "expected summary content"); | ||
|
||
SerenityJsonSummaryFile serenityJsonSummaryFile = new SerenityJsonSummaryFile(pathOfTemporaryFolder()); | ||
|
||
assertTrue(serenityJsonSummaryFile.exists()); | ||
assertEquals("expected summary content", serenityJsonSummaryFile.getContents()); | ||
} | ||
|
||
@Test | ||
public void testUnavailableSummary() throws Exception { | ||
SerenityJsonSummaryFile serenityJsonSummaryFile = new SerenityJsonSummaryFile(pathOfTemporaryFolder()); | ||
|
||
assertFalse(serenityJsonSummaryFile.exists()); | ||
} | ||
|
||
@Test | ||
public void testUnavailableWorkspace() throws Exception { | ||
SerenityJsonSummaryFile serenityJsonSummaryFile = new SerenityJsonSummaryFile(null); | ||
|
||
assertFalse(serenityJsonSummaryFile.exists()); | ||
} | ||
|
||
private void writeToTemporaryPath(String path, String content) throws IOException { | ||
Path temporaryPath = temporaryFolder.getRoot().toPath(); | ||
Path summaryJson = temporaryPath.resolve(path); | ||
Files.createDirectories(summaryJson.getParent()); | ||
Files.writeString(summaryJson, content, StandardCharsets.UTF_8); | ||
} | ||
|
||
private String pathOfTemporaryFolder() { | ||
return temporaryFolder.getRoot().getAbsolutePath(); | ||
} | ||
} |