Skip to content

Commit

Permalink
style: Fix some low-severity Sonar issues in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck committed Feb 6, 2025
1 parent 8242004 commit 676fcd3
Show file tree
Hide file tree
Showing 61 changed files with 219 additions and 226 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
4 changes: 2 additions & 2 deletions cli/src/test/java/org/jboss/sbomer/cli/test/integ/CliIT.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down Expand Up @@ -32,7 +32,7 @@ class CliIT {
@Test
@DisplayName("Should run the command without any options and print help")
@Launch(exitCode = 2)
void shouldPrintUsageOnWrongCommand(LaunchResult result) throws Exception {
void shouldPrintUsageOnWrongCommand(LaunchResult result) {
assertThat(result.getErrorOutput(), containsString("Usage: sbomerctl [-hvV] [COMMAND]"));
assertThat(result.getErrorOutput(), containsString(" sbom, s SBOM generation"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down Expand Up @@ -59,7 +59,7 @@ void shouldReturnCorrectImplementationType() {
assertEquals(ProcessorType.REDHAT_PRODUCT, command.getImplementationType());
}

// TODO: This deosn't make sense after refactoring, but maybe it could be a base for some other test, leaving for
// TODO: This doesn't make sense after refactoring, but maybe it could be a base for some other test, leaving for
// now
// @Test
// void shouldStopProcessingIfTheBuildIsNotFound() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.net.MalformedURLException;
import java.util.List;

import org.cyclonedx.model.Bom;
Expand All @@ -22,8 +21,6 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import com.fasterxml.jackson.core.JsonProcessingException;

import io.quarkus.test.common.WithTestResource;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
Expand All @@ -38,12 +35,12 @@ class DefaultProcessorIT {
PncService pncService;

@BeforeEach
void init() throws MalformedURLException {
void init() {
this.defaultProcessor = new DefaultProcessor(pncService, Mockito.mock(KojiService.class));
}

@Test
void testProcessing() throws JsonProcessingException {
void testProcessing() {
// Prepare BOM!
Bom bom = new Bom();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void testAddMissingNpmDependencies() throws IOException {

// With
Bom bom = SbomUtils.fromString(TestResources.asString("boms/pnc-build.json"));
assertNotNull(bom);
Optional<Component> missingComponent = getComponent(bom, "pkg:npm/[email protected]");
Optional<Dependency> missingDependency = getDependency("pkg:npm/[email protected]", bom.getDependencies());

Expand Down Expand Up @@ -244,6 +245,7 @@ void baseTest() throws IOException {

DefaultProcessor defaultProcessor = new DefaultProcessor(pncServiceMock, kojiServiceMock);

assertNotNull(bom);
assertEquals(459, bom.getComponents().size());
assertEquals(459, bom.getDependencies().size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless ruired by applicable law or agreed to in writing, software
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void shouldAddSerialNumber() {
@Test
void parseBrewRpmsBom() throws IOException {
Bom bom = SbomUtils.fromPath(Paths.get("src", "test", "resources", "boms/brew_rpm.json"));
assertNotNull(bom);
assertEquals(1, bom.getDependencies().size());
assertEquals(8, bom.getDependencies().get(0).getProvides().size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
Expand Down Expand Up @@ -169,6 +170,7 @@ void depdsShouldPointToComponents() throws Exception {

this.bom = SbomUtils.fromString(TestResources.asString("boms/shaded.json"));

assertNotNull(bom);
assertEquals(459, bom.getComponents().size());
assertEquals(294, bom.getDependencies().size());
assertEquals(0, SbomUtils.validate(SbomUtils.toJsonNode(bom)).size());
Expand Down Expand Up @@ -282,7 +284,7 @@ void shouldAdjustVendorAndPublisher() {
.stream()
.filter(property -> "sbomer:image:labels:vendor".equals(property.getName()))
.findFirst();
assertTrue(bogusVendor.isPresent());
assertTrue(goodVendor.isPresent());
assertEquals("Red Hat", goodVendor.get().getValue());

Optional<Component> goodComponent = adjusted.getComponents()
Expand All @@ -308,6 +310,7 @@ void shouldSanitizeBogusPurls() {
new PackageURL(bogusPurl);
fail("Should fail the parsing to PURL of " + bogusPurl);
} catch (MalformedPackageURLException e) {
// Expected
}

String sanitizedPurl = PurlSanitizer.sanitizePurl(bogusPurl);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jboss.sbomer.cli.test.unit.feature.sbom.catalog;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -36,6 +37,10 @@ void createImageIndex() throws IOException, GeneratorException {
Bom arm64 = SbomUtils.fromString(TestResources.asString("boms/catalog/arm64.json"));
Bom ppc64le = SbomUtils.fromString(TestResources.asString("boms/catalog/ppc64le.json"));
Bom s390x = SbomUtils.fromString(TestResources.asString("boms/catalog/s390x.json"));
assertNotNull(amd64);
assertNotNull(arm64);
assertNotNull(ppc64le);
assertNotNull(s390x);
List<Bom> boms = List.of(amd64, arm64, ppc64le, s390x);

String imageName = "rh-osbs/ubi9-ubi-micro";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand All @@ -18,6 +18,7 @@
package org.jboss.sbomer.cli.test.unit.generate;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -27,7 +28,6 @@
import org.jboss.sbomer.cli.feature.sbom.generate.MavenDominoGenerator;
import org.jboss.sbomer.cli.feature.sbom.generate.ProcessRunner;
import org.jboss.sbomer.core.errors.ValidationException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;
Expand All @@ -42,7 +42,7 @@ class MavenDominoGeneratorTest {

@Test
void testFailedWhenNoDominoDirProvided(@TempDir Path projectDir) {
ValidationException thrown = Assertions.assertThrows(
ValidationException thrown = assertThrows(
ValidationException.class,
() -> MavenDominoGenerator.builder().withDominoDir(null).build().run(projectDir));

Expand All @@ -53,7 +53,7 @@ void testFailedWhenNoDominoDirProvided(@TempDir Path projectDir) {

@Test
void testFailedWhenDominoDirDoesntExist(@TempDir Path projectDir) {
ValidationException thrown = Assertions.assertThrows(
ValidationException thrown = assertThrows(
ValidationException.class,
() -> MavenDominoGenerator.builder().withDominoDir(Path.of("some/dir")).build().run(projectDir));

Expand All @@ -64,7 +64,7 @@ void testFailedWhenDominoDirDoesntExist(@TempDir Path projectDir) {

@Test
void testFailedWhenDominoDoesntExistForDefaultVersion(@TempDir Path projectDir, @TempDir Path wrongDir) {
ValidationException thrown = Assertions.assertThrows(
ValidationException thrown = assertThrows(
ValidationException.class,
() -> MavenDominoGenerator.builder().withDominoDir(wrongDir).build().run(projectDir));

Expand All @@ -77,7 +77,7 @@ void testFailedWhenDominoDoesntExistForDefaultVersion(@TempDir Path projectDir,

@Test
void testFailedWhenDominoDirDoesntExistWithCustomVersion(@TempDir Path projectDir, @TempDir Path dominoDir) {
ValidationException thrown = Assertions.assertThrows(
ValidationException thrown = assertThrows(
ValidationException.class,
() -> MavenDominoGenerator.builder()
.withDominoDir(dominoDir)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.jboss.sbomer.cli.test.unit.process;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Optional;

import org.cyclonedx.model.Bom;
import org.cyclonedx.model.Component;
Expand All @@ -26,15 +29,18 @@ void addAll() {
processor.process(bom);

assertEquals(3, component.getProperties().size());
assertEquals(
"pName",
SbomUtils.findPropertyWithNameInComponent("errata-tool-product-name", component).get().getValue());
assertEquals(
"pVersion",
SbomUtils.findPropertyWithNameInComponent("errata-tool-product-version", component).get().getValue());
assertEquals(
"pVariant",
SbomUtils.findPropertyWithNameInComponent("errata-tool-product-variant", component).get().getValue());
Optional<Property> errataToolProductName = SbomUtils
.findPropertyWithNameInComponent("errata-tool-product-name", component);
assertTrue(errataToolProductName.isPresent());
assertEquals("pName", errataToolProductName.get().getValue());
Optional<Property> errataToolProductVersion = SbomUtils
.findPropertyWithNameInComponent("errata-tool-product-version", component);
assertTrue(errataToolProductVersion.isPresent());
assertEquals("pVersion", errataToolProductVersion.get().getValue());
Optional<Property> errataToolProductVariant = SbomUtils
.findPropertyWithNameInComponent("errata-tool-product-variant", component);
assertTrue(errataToolProductVariant.isPresent());
assertEquals("pVariant", errataToolProductVariant.get().getValue());
}

@Test
Expand All @@ -56,14 +62,17 @@ void addOnlyIfMissing() {
processor.process(bom);

assertEquals(3, component.getProperties().size());
assertEquals(
"original-value",
SbomUtils.findPropertyWithNameInComponent("errata-tool-product-name", component).get().getValue());
assertEquals(
"pVersion",
SbomUtils.findPropertyWithNameInComponent("errata-tool-product-version", component).get().getValue());
assertEquals(
"pVariant",
SbomUtils.findPropertyWithNameInComponent("errata-tool-product-variant", component).get().getValue());
Optional<Property> errataToolProductName = SbomUtils
.findPropertyWithNameInComponent("errata-tool-product-name", component);
assertTrue(errataToolProductName.isPresent());
assertEquals("original-value", errataToolProductName.get().getValue());
Optional<Property> errataToolProductVersion = SbomUtils
.findPropertyWithNameInComponent("errata-tool-product-version", component);
assertTrue(errataToolProductVersion.isPresent());
assertEquals("pVersion", errataToolProductVersion.get().getValue());
Optional<Property> errataToolProductVariant = SbomUtils
.findPropertyWithNameInComponent("errata-tool-product-variant", component);
assertTrue(errataToolProductVariant.isPresent());
assertEquals("pVariant", errataToolProductVariant.get().getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import org.jboss.pnc.build.finder.koji.ClientSession;

import com.redhat.red.build.koji.KojiClientException;
import com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo;
import com.redhat.red.build.koji.model.xmlrpc.KojiArchiveQuery;
import com.redhat.red.build.koji.model.xmlrpc.KojiArchiveType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;

import jakarta.enterprise.inject.Alternative;

Expand Down Expand Up @@ -31,7 +32,9 @@ protected void doClone(String url, String tag, Path path, boolean force) {
protected Path doGenerate(String buildCmdOptions) {

try {
Files.copy(getClass().getClassLoader().getResourceAsStream("boms/plain.json"), getParent().getOutput());
Files.copy(
Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream("boms/plain.json")),
getParent().getOutput());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down Expand Up @@ -206,7 +206,7 @@ void tackleDoubleMvnCommandTest() throws IOException, IllegalArgumentException {
}

@Test
void tackleAlternativePomFileTest() throws IOException, IllegalArgumentException {
void tackleAlternativePomFileTest() throws IllegalArgumentException {
String script = "mvn deploy -f productized/logic/pom.xml";

MavenCommandLineParser lineParser = MavenCommandLineParser.build().launder(script);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
Expand Down
Loading

0 comments on commit 676fcd3

Please sign in to comment.