Skip to content

Commit

Permalink
Fix build scan table tests (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino committed Nov 10, 2022
1 parent 1863811 commit 9d4dccd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class BuildInfoScanTableHelperTest {
private static final String SCAN_RESULT_PATH = "/buildScanTable/scanResult.json";
private static final String EMPTY_RESULT_PATH = "/buildScanTable/emptyResult.json";
private static final String INVALID_RESULT_PATH = "/buildScanTable/invalidResult.json";
private final BuildScanTableHelper tableHelper = new BuildScanTableHelper();

@Test
Expand Down Expand Up @@ -69,10 +69,14 @@ public void testPrintTableWithNoViolations() throws IOException, URISyntaxExcept
}

@Test
public void testPrintTableWithInvalidType() throws IOException, URISyntaxException {
public void testPrintTableWithUnexpectedType() throws IOException, URISyntaxException {
TestsAggregationLog log = new TestsAggregationLog();
ArtifactoryXrayResponse result = getXrayInvalidResultResource();
Assert.assertThrows(IllegalArgumentException.class, () -> tableHelper.printTable(result, log));
ArtifactoryXrayResponse result = getXrayResultResource();

// Set type to an unknown one to make sure no exception is thrown.
result.getAlerts().get(0).getIssues().get(0).setType("UNKNOWN_TYPE");

tableHelper.printTable(result, log);
}

private ArtifactoryXrayResponse getXrayResultResource() throws URISyntaxException, IOException {
Expand All @@ -83,12 +87,8 @@ private ArtifactoryXrayResponse getXrayEmptyResultResource() throws URISyntaxExc
return getResource(EMPTY_RESULT_PATH);
}

private ArtifactoryXrayResponse getXrayInvalidResultResource() throws URISyntaxException, IOException {
return getResource(INVALID_RESULT_PATH);
}

private ArtifactoryXrayResponse getResource(String path) throws URISyntaxException, IOException {
File testResourcesPath = new File(this.getClass().getResource(path).toURI()).getCanonicalFile();
File testResourcesPath = new File(Objects.requireNonNull(this.getClass().getResource(path)).toURI()).getCanonicalFile();
ObjectMapper mapper = new ObjectMapper(new JsonFactory());
return mapper.readValue(testResourcesPath, ArtifactoryXrayResponse.class);
}
Expand Down

This file was deleted.

0 comments on commit 9d4dccd

Please sign in to comment.