formating and codacy recommended updates

This commit is contained in:
Jeremy Long
2017-02-17 12:59:17 -05:00
parent 71724461a9
commit 960a2e27ab
35 changed files with 149 additions and 153 deletions

View File

@@ -17,13 +17,13 @@ import org.owasp.dependencycheck.utils.Settings;
public class AnalysisTaskTest extends BaseTest {
@Mocked
FileTypeAnalyzer fileTypeAnalyzer;
private FileTypeAnalyzer fileTypeAnalyzer;
@Mocked
Dependency dependency;
private Dependency dependency;
@Mocked
Engine engine;
private Engine engine;
@Test

View File

@@ -25,7 +25,6 @@ import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.junit.Before;
import org.owasp.dependencycheck.BaseTest;
import org.owasp.dependencycheck.utils.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,10 +53,10 @@ public abstract class BaseDBTestCase extends BaseTest {
f.delete();
}
java.io.File dataPath = Settings.getDataDirectory();
File dataPath = Settings.getDataDirectory();
String fileName = Settings.getString(Settings.KEYS.DB_FILE_NAME);
LOGGER.trace("DB file name {}", fileName);
java.io.File dataFile = new File(dataPath, fileName);
File dataFile = new File(dataPath, fileName);
LOGGER.trace("Ensuring {} exists", dataFile.toString());
if (!dataPath.exists() || !dataFile.exists()) {
LOGGER.trace("Extracting database to {}", dataPath.toString());

View File

@@ -46,9 +46,11 @@ public class EngineTest extends BaseDBTestCase {
@Mocked
private AnalysisTask analysisTask;
/**
* Test of scanFile method, of class Engine.
*
* @throws org.owasp.dependencycheck.data.nvdcve.DatabaseException thrown is
* there is an exception
*/
@Test
public void testScanFile() throws DatabaseException {
@@ -64,30 +66,34 @@ public class EngineTest extends BaseDBTestCase {
Dependency secondDwr = instance.scanFile(file);
assertEquals(2, instance.getDependencies().size());
assertTrue(dwr == secondDwr);
assertEquals(dwr, secondDwr);
}
@Test(expected = ExceptionCollection.class)
public void exceptionDuringAnalysisTaskExecutionIsFatal() throws DatabaseException, ExceptionCollection {
final ExecutorService executorService = Executors.newFixedThreadPool(3);
final Engine instance = new Engine();
final List<Throwable> exceptions = new ArrayList<Throwable>();
final List<Throwable> exceptions = new ArrayList<>();
new Expectations() {{
analysisTask.call();
result = new IllegalStateException("Analysis task execution threw an exception");
}};
new Expectations() {
{
analysisTask.call();
result = new IllegalStateException("Analysis task execution threw an exception");
}
};
final List<AnalysisTask> failingAnalysisTask = new ArrayList<AnalysisTask>();
final List<AnalysisTask> failingAnalysisTask = new ArrayList<>();
failingAnalysisTask.add(analysisTask);
new Expectations(instance) {{
instance.getExecutorService(analyzer);
result = executorService;
new Expectations(instance) {
{
instance.getExecutorService(analyzer);
result = executorService;
instance.getAnalysisTasks(analyzer, exceptions);
result = failingAnalysisTask;
}};
instance.getAnalysisTasks(analyzer, exceptions);
result = failingAnalysisTask;
}
};
instance.executeAnalysisTasks(analyzer, exceptions);

View File

@@ -49,7 +49,7 @@ public class AssemblyAnalyzerTest extends BaseTest {
private static final String LOG_KEY = "org.slf4j.simpleLogger.org.owasp.dependencycheck.analyzer.AssemblyAnalyzer";
AssemblyAnalyzer analyzer;
private AssemblyAnalyzer analyzer;
/**
* Sets up the analyzer.

View File

@@ -43,7 +43,7 @@ public class AutoconfAnalyzerTest extends BaseTest {
/**
* The analyzer to test.
*/
AutoconfAnalyzer analyzer;
private AutoconfAnalyzer analyzer;
private void assertCommonEvidence(Dependency result, String product,
String version, String vendor) {

View File

@@ -53,7 +53,7 @@ public class CMakeAnalyzerTest extends BaseDBTestCase {
/**
* The package analyzer to test.
*/
CMakeAnalyzer analyzer;
private CMakeAnalyzer analyzer;
/**
* Setup the CmakeAnalyzer.

View File

@@ -47,7 +47,7 @@ public class ComposerLockAnalyzerTest extends BaseDBTestCase {
/**
* The analyzer to test.
*/
ComposerLockAnalyzer analyzer;
private ComposerLockAnalyzer analyzer;
/**
* Correctly setup the analyzer for testing.

View File

@@ -34,7 +34,7 @@ import static org.junit.Assert.assertTrue;
public class DependencyBundlingAnalyzerTest extends BaseTest {
@Mocked
Engine engineMock;
private Engine engineMock;
/**
* Test of getName method, of class DependencyBundlingAnalyzer.

View File

@@ -40,7 +40,7 @@ public class NodePackageAnalyzerTest extends BaseTest {
/**
* The analyzer to test.
*/
NodePackageAnalyzer analyzer;
private NodePackageAnalyzer analyzer;
/**
* Correctly setup the analyzer for testing.

View File

@@ -57,7 +57,7 @@ public class RubyBundleAuditAnalyzerTest extends BaseDBTestCase {
/**
* The analyzer to test.
*/
RubyBundleAuditAnalyzer analyzer;
private RubyBundleAuditAnalyzer analyzer;
/**
* Correctly setup the analyzer for testing.

View File

@@ -40,7 +40,7 @@ public class RubyGemspecAnalyzerTest extends BaseTest {
/**
* The analyzer to test.
*/
RubyGemspecAnalyzer analyzer;
private RubyGemspecAnalyzer analyzer;
/**
* Correctly setup the analyzer for testing.

View File

@@ -20,6 +20,7 @@ package org.owasp.dependencycheck.data.nvdcve;
import org.owasp.dependencycheck.BaseDBTestCase;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.owasp.dependencycheck.data.update.nvd.NvdCveInfo;
@@ -40,8 +41,7 @@ public class DatabasePropertiesIntegrationTest extends BaseDBTestCase {
cveDB = new CveDB();
cveDB.open();
DatabaseProperties instance = cveDB.getDatabaseProperties();
boolean expResult = false;
boolean result = instance.isEmpty();
assertNotNull(instance);
//no exception means the call worked... whether or not it is empty depends on if the db is new
//assertEquals(expResult, result);
} finally {

View File

@@ -18,8 +18,10 @@
package org.owasp.dependencycheck.data.update;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.owasp.dependencycheck.BaseTest;
import org.owasp.dependencycheck.data.update.exception.UpdateException;
import org.owasp.dependencycheck.data.update.nvd.UpdateableNvdCve;
/**
@@ -38,9 +40,13 @@ import org.owasp.dependencycheck.data.update.nvd.UpdateableNvdCve;
* Test of update method.
*/
@Test
public void testUpdate() throws Exception {
NvdCveUpdater instance = getUpdater();
instance.update();
public void testUpdate() {
try {
NvdCveUpdater instance = getUpdater();
instance.update();
} catch (UpdateException ex) {
fail(ex.getMessage());
}
}
/**

View File

@@ -23,9 +23,7 @@ import java.util.List;
import java.util.Map;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.junit.Test;
import org.owasp.dependencycheck.BaseTest;
import org.owasp.dependencycheck.dependency.VulnerableSoftware;
@@ -47,6 +45,6 @@ public class NvdCve_1_2_HandlerTest extends BaseTest {
NvdCve12Handler instance = new NvdCve12Handler();
saxParser.parse(file, instance);
Map<String, List<VulnerableSoftware>> results = instance.getVulnerabilities();
assertTrue("No vulnerable software identified with a previous version in 2012 CVE 1.2?", !results.isEmpty());
assertFalse("No vulnerable software identified with a previous version in 2012 CVE 1.2?", results.isEmpty());
}
}

View File

@@ -48,9 +48,10 @@ public class ModelTest extends BaseTest {
*/
@Test
public void testSetName() {
String name = "";
String name = "name";
Model instance = new Model();
instance.setName(name);
assertEquals("name", instance.getName());
}
/**
@@ -209,9 +210,10 @@ public class ModelTest extends BaseTest {
*/
@Test
public void testSetParentArtifactId() {
String parentArtifactId = "";
String parentArtifactId = "something";
Model instance = new Model();
instance.setParentArtifactId(parentArtifactId);
assertNotNull(instance.getParentArtifactId());
}
/**
@@ -231,9 +233,10 @@ public class ModelTest extends BaseTest {
*/
@Test
public void testSetParentVersion() {
String parentVersion = "";
String parentVersion = "1.0";
Model instance = new Model();
instance.setParentVersion(parentVersion);
assertNotNull(instance.getParentVersion());
}
/**
@@ -257,6 +260,7 @@ public class ModelTest extends BaseTest {
License license = new License("name", "url");
Model instance = new Model();
instance.addLicense(license);
assertNotNull(instance.getLicenses());
}
/**