From 6274cfce4b2811c6a5db308582db59f4c4a48637 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Tue, 19 Feb 2013 21:35:24 -0500 Subject: [PATCH] cleanup and spelling fixes Former-commit-id: 9c44ae88606f12728bc424d566ef11194c5c399b --- .../codesecure/dependencycheck/Engine.java | 1 - .../analyzer/AbstractAnalyzer.java | 6 +- .../dependencycheck/analyzer/Analyzer.java | 4 +- .../analyzer/AnalyzerService.java | 2 +- .../analyzer/FileNameAnalyzer.java | 2 +- .../dependencycheck/analyzer/JarAnalyzer.java | 6 +- .../analyzer/SpringCleaningAnalyzer.java | 6 +- .../pom/generated/DeploymentRepository.java | 2 +- .../analyzer/pom/generated/ObjectFactory.java | 2 +- .../analyzer/pom/generated/Repository.java | 2 +- .../dependencycheck/data/UpdateService.java | 2 +- .../dependencycheck/data/cpe/CPEAnalyzer.java | 18 ++-- .../data/lucene/LuceneUtils.java | 6 +- .../lucene/TokenPairConcatenatingFilter.java | 6 +- .../data/lucene/VersionTokenizingFilter.java | 13 ++- .../data/nvdcve/NvdCveAnalyzer.java | 4 +- .../data/nvdcve/xml/DatabaseUpdater.java | 6 +- .../data/nvdcve/xml/InvalidDataException.java | 2 +- .../data/nvdcve/xml/NvdCve20Handler.java | 8 +- .../dependency/Dependency.java | 2 +- .../dependency/Identifier.java | 6 +- .../dependency/Vulnerability.java | 4 +- .../dependency/VulnerableSoftware.java | 2 +- .../reporting/ReportGenerator.java | 4 +- .../dependencycheck/utils/Checksum.java | 2 +- .../dependencycheck/utils/CliParser.java | 28 ++--- .../dependencycheck/utils/Downloader.java | 6 +- .../utils/NonClosingStream.java | 2 +- .../dependencycheck/utils/Settings.java | 2 +- .../analyzer/JarAnalyzerTest.java | 4 +- .../data/cpe/CPEAnalyzerTest.java | 45 ++++---- .../data/cpe/IndexIntegrationTest.java | 6 +- .../dependencycheck/data/cpe/IndexTest.java | 17 +-- .../dependencycheck/data/cwe/CweDBTest.java | 2 +- .../reporting/ReportGeneratorTest.java | 8 +- .../dependencycheck/utils/ChecksumTest.java | 35 +++--- .../dependencycheck/utils/CliParserTest.java | 101 +++++++++--------- .../utils/DownloaderIntegrationTest.java | 2 +- .../dependencycheck/utils/SettingsTest.java | 37 +++---- 39 files changed, 188 insertions(+), 225 deletions(-) diff --git a/src/main/java/org/codesecure/dependencycheck/Engine.java b/src/main/java/org/codesecure/dependencycheck/Engine.java index 1311045d2..c45b14680 100644 --- a/src/main/java/org/codesecure/dependencycheck/Engine.java +++ b/src/main/java/org/codesecure/dependencycheck/Engine.java @@ -200,7 +200,6 @@ public class Engine { } catch (Exception ex1) { Logger.getLogger(Engine.class.getName()).log(Level.FINER, null, ex1); } - continue; } } } diff --git a/src/main/java/org/codesecure/dependencycheck/analyzer/AbstractAnalyzer.java b/src/main/java/org/codesecure/dependencycheck/analyzer/AbstractAnalyzer.java index 0a9d016f2..e9230f4c7 100644 --- a/src/main/java/org/codesecure/dependencycheck/analyzer/AbstractAnalyzer.java +++ b/src/main/java/org/codesecure/dependencycheck/analyzer/AbstractAnalyzer.java @@ -18,6 +18,7 @@ */ package org.codesecure.dependencycheck.analyzer; +import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -39,10 +40,7 @@ public abstract class AbstractAnalyzer implements Analyzer { protected static Set newHashSet(String... strings) { Set set = new HashSet(); - //yes, in Java7 we could use Array.toList(...) - but I'm trying to keep this Java 6 compliant. - for (String s : strings) { - set.add(s); - } + Collections.addAll(set, strings); return set; } } diff --git a/src/main/java/org/codesecure/dependencycheck/analyzer/Analyzer.java b/src/main/java/org/codesecure/dependencycheck/analyzer/Analyzer.java index 96511c184..a463be5a1 100644 --- a/src/main/java/org/codesecure/dependencycheck/analyzer/Analyzer.java +++ b/src/main/java/org/codesecure/dependencycheck/analyzer/Analyzer.java @@ -33,7 +33,7 @@ public interface Analyzer { /** * Analyzes the given dependency. The analysis could be anything from - * identifying an Idenifier for the dependency, to finding vulnerabilities, + * identifying an Identifier for the dependency, to finding vulnerabilities, * etc. Additionally, if the analyzer collects enough information to add a * description or license information for the dependency it should be added. * @@ -71,7 +71,7 @@ public interface Analyzer { * Returns whether or not this analyzer can process the given extension. * * @param extension the file extension to test for support. - * @return whether or not the specified file extension is supported by tihs + * @return whether or not the specified file extension is supported by this * analyzer. */ boolean supportsExtension(String extension); diff --git a/src/main/java/org/codesecure/dependencycheck/analyzer/AnalyzerService.java b/src/main/java/org/codesecure/dependencycheck/analyzer/AnalyzerService.java index 048f4e30d..13e2b5788 100644 --- a/src/main/java/org/codesecure/dependencycheck/analyzer/AnalyzerService.java +++ b/src/main/java/org/codesecure/dependencycheck/analyzer/AnalyzerService.java @@ -28,7 +28,7 @@ import java.util.ServiceLoader; public class AnalyzerService { private static AnalyzerService service; - private ServiceLoader loader; + private final ServiceLoader loader; /** * Creates a new instance of AnalyzerService diff --git a/src/main/java/org/codesecure/dependencycheck/analyzer/FileNameAnalyzer.java b/src/main/java/org/codesecure/dependencycheck/analyzer/FileNameAnalyzer.java index 9b85e7bb2..3a10e11e4 100644 --- a/src/main/java/org/codesecure/dependencycheck/analyzer/FileNameAnalyzer.java +++ b/src/main/java/org/codesecure/dependencycheck/analyzer/FileNameAnalyzer.java @@ -66,7 +66,7 @@ public class FileNameAnalyzer implements Analyzer { * Returns whether or not this analyzer can process the given extension. * * @param extension the file extension to test for support. - * @return whether or not the specified file extension is supported by tihs + * @return whether or not the specified file extension is supported by this * analyzer. */ public boolean supportsExtension(String extension) { diff --git a/src/main/java/org/codesecure/dependencycheck/analyzer/JarAnalyzer.java b/src/main/java/org/codesecure/dependencycheck/analyzer/JarAnalyzer.java index 8b5d801e9..39881e7c9 100644 --- a/src/main/java/org/codesecure/dependencycheck/analyzer/JarAnalyzer.java +++ b/src/main/java/org/codesecure/dependencycheck/analyzer/JarAnalyzer.java @@ -115,10 +115,6 @@ public class JarAnalyzer extends AbstractAnalyzer implements Analyzer { * item in some manifest, should be considered medium confidence. */ private static final String BUNDLE_VENDOR = "Bundle-Vendor"; //: Apache Software Foundation - /** - * The JAXB Contexts used to unmarshall the pom.xml from a JAR file. - */ - private JAXBContext jaxbContext = null; /** * The unmarshaller used to parse the pom.xml from a JAR file. */ @@ -129,7 +125,7 @@ public class JarAnalyzer extends AbstractAnalyzer implements Analyzer { */ public JarAnalyzer() { try { - jaxbContext = JAXBContext.newInstance("org.codesecure.dependencycheck.analyzer.pom.generated"); + JAXBContext jaxbContext = JAXBContext.newInstance("org.codesecure.dependencycheck.analyzer.pom.generated"); pomUnmarshaller = jaxbContext.createUnmarshaller(); } catch (JAXBException ex) { //guess we will just have a null pointer exception later... Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, null, ex); diff --git a/src/main/java/org/codesecure/dependencycheck/analyzer/SpringCleaningAnalyzer.java b/src/main/java/org/codesecure/dependencycheck/analyzer/SpringCleaningAnalyzer.java index 16f1a2475..9e9bc9824 100644 --- a/src/main/java/org/codesecure/dependencycheck/analyzer/SpringCleaningAnalyzer.java +++ b/src/main/java/org/codesecure/dependencycheck/analyzer/SpringCleaningAnalyzer.java @@ -69,8 +69,8 @@ public class SpringCleaningAnalyzer extends AbstractAnalyzer { /** * Returns whether or not this analyzer can process the given extension. * - * @param extension the file extension to test for support. - * @return whether or not the specified file extension is supported by tihs + * @param extension the file extension to test for support + * @return whether or not the specified file extension is supported by this * analyzer. */ public boolean supportsExtension(String extension) { @@ -104,7 +104,7 @@ public class SpringCleaningAnalyzer extends AbstractAnalyzer { private List springVersions = null; /** - * Determines if several "spring" libraries were scanned and trimes the + * Determines if several "spring" libraries were scanned and trims the * cpe:/a:springsource:spring_framework:[version] from the none "core" framework * if the core framework was part of the scan. * diff --git a/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/DeploymentRepository.java b/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/DeploymentRepository.java index dcfb52a9d..a1c4e4d86 100644 --- a/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/DeploymentRepository.java +++ b/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/DeploymentRepository.java @@ -17,7 +17,7 @@ import javax.xml.bind.annotation.XmlType; /** * - * Repository contains the information needed for deploying to the remote repoistory. + * Repository contains the information needed for deploying to the remote repository. * * *

Java class for DeploymentRepository complex type. diff --git a/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/ObjectFactory.java b/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/ObjectFactory.java index b7b2278f1..a8b1b51bf 100644 --- a/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/ObjectFactory.java +++ b/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/ObjectFactory.java @@ -18,7 +18,7 @@ import javax.xml.namespace.QName; * This object contains factory methods for each * Java content interface and Java element interface * generated in the org.codesecure.dependencycheck.analyzer.pom.generated package. - *

An ObjectFactory allows you to programatically + *

An ObjectFactory allows you to programmatically * construct new instances of the Java representation * for XML content. The Java representation of XML * content can consist of schema derived interfaces diff --git a/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/Repository.java b/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/Repository.java index 1935cfa3b..e5d2147b5 100644 --- a/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/Repository.java +++ b/src/main/java/org/codesecure/dependencycheck/analyzer/pom/generated/Repository.java @@ -17,7 +17,7 @@ import javax.xml.bind.annotation.XmlType; /** * - * A repository contains the information needed for establishing connections with remote repoistory. + * A repository contains the information needed for establishing connections with remote repository. * * *

Java class for Repository complex type. diff --git a/src/main/java/org/codesecure/dependencycheck/data/UpdateService.java b/src/main/java/org/codesecure/dependencycheck/data/UpdateService.java index 4b88edec9..50fbf7f8d 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/UpdateService.java +++ b/src/main/java/org/codesecure/dependencycheck/data/UpdateService.java @@ -28,7 +28,7 @@ import java.util.ServiceLoader; public class UpdateService { private static UpdateService service; - private ServiceLoader loader; + private final ServiceLoader loader; /** * Creates a new instance of UpdateService diff --git a/src/main/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzer.java b/src/main/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzer.java index 8533f07d9..a2f42df73 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzer.java +++ b/src/main/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzer.java @@ -40,7 +40,7 @@ import org.codesecure.dependencycheck.dependency.EvidenceCollection; /** * CPEAnalyzer is a utility class that takes a project dependency and attempts - * to decern if there is an associated CPE. It uses the evidence contained + * to discern if there is an associated CPE. It uses the evidence contained * within the dependency to search the Lucene index. * * @author Jeremy Long (jeremy.long@gmail.com) @@ -78,7 +78,7 @@ public class CPEAnalyzer implements org.codesecure.dependencycheck.analyzer.Anal /** * Opens the data source. * - * @throws IOException when the Lucene directory to be querried does not + * @throws IOException when the Lucene directory to be queried does not * exist or is corrupt. */ public void open() throws IOException { @@ -99,7 +99,7 @@ public class CPEAnalyzer implements org.codesecure.dependencycheck.analyzer.Anal * @return true or false. */ public boolean isOpen() { - return (cpe == null) ? false : cpe.isOpen(); + return (cpe != null) && cpe.isOpen(); } /** @@ -118,7 +118,7 @@ public class CPEAnalyzer implements org.codesecure.dependencycheck.analyzer.Anal /** * Searches the data store of CPE entries, trying to identify the CPE for * the given dependency based on the evidence contained within. The - * depencency passed in is updated with any identified CPE values. + * dependency passed in is updated with any identified CPE values. * * @param dependency the dependency to search for CPE entries on. * @throws CorruptIndexException is thrown when the Lucene index is corrupt. @@ -194,7 +194,7 @@ public class CPEAnalyzer implements org.codesecure.dependencycheck.analyzer.Anal * @param text the base text. * @param ec an EvidenceCollection * @param confidenceFilter a Confidence level to filter the evidence by. - * @return + * @return the new evidence text */ private String addEvidenceWithoutDuplicateTerms(final String text, final EvidenceCollection ec, Confidence confidenceFilter) { String txt = (text == null) ? "" : text; @@ -286,12 +286,12 @@ public class CPEAnalyzer implements org.codesecure.dependencycheck.analyzer.Anal * @param version text to search the version field. * @param vendorWeighting a list of strings to apply to the vendor to boost * the terms weight. - * @param produdctWeightings a list of strings to apply to the product to + * @param productWeightings a list of strings to apply to the product to * boost the terms weight. * @return the Lucene query. */ protected String buildSearch(String vendor, String product, String version, - Set vendorWeighting, Set produdctWeightings) { + Set vendorWeighting, Set productWeightings) { StringBuilder sb = new StringBuilder(vendor.length() + product.length() + version.length() + Fields.PRODUCT.length() + Fields.VERSION.length() @@ -301,7 +301,7 @@ public class CPEAnalyzer implements org.codesecure.dependencycheck.analyzer.Anal return null; } - if (!appendWeightedSearch(sb, Fields.PRODUCT, product, produdctWeightings)) { + if (!appendWeightedSearch(sb, Fields.PRODUCT, product, productWeightings)) { return null; } sb.append(" AND "); @@ -332,7 +332,7 @@ public class CPEAnalyzer implements org.codesecure.dependencycheck.analyzer.Anal /** * This method constructs a Lucene query for a given field. The searchText - * is split into seperate words and if the word is within the list of + * is split into separate words and if the word is within the list of * weighted words then an additional weighting is applied to the term as it * is appended into the query. * diff --git a/src/main/java/org/codesecure/dependencycheck/data/lucene/LuceneUtils.java b/src/main/java/org/codesecure/dependencycheck/data/lucene/LuceneUtils.java index f9bdbd87e..a83d137a4 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/lucene/LuceneUtils.java +++ b/src/main/java/org/codesecure/dependencycheck/data/lucene/LuceneUtils.java @@ -19,15 +19,15 @@ package org.codesecure.dependencycheck.data.lucene; /** - *

Lucene utils is a set of utilitize written to make constructing Lucene - * queries simplier.

+ *

Lucene utils is a set of utilize written to make constructing Lucene + * queries simpler.

* * @author Jeremy Long (jeremy.long@gmail.com) */ public final class LuceneUtils { /** - * Provate contructor as this is a utility class. + * Private constructor as this is a utility class. */ private LuceneUtils() { } diff --git a/src/main/java/org/codesecure/dependencycheck/data/lucene/TokenPairConcatenatingFilter.java b/src/main/java/org/codesecure/dependencycheck/data/lucene/TokenPairConcatenatingFilter.java index b13bb4e65..1d041871c 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/lucene/TokenPairConcatenatingFilter.java +++ b/src/main/java/org/codesecure/dependencycheck/data/lucene/TokenPairConcatenatingFilter.java @@ -39,7 +39,7 @@ public final class TokenPairConcatenatingFilter extends TokenFilter { private LinkedList words = null; /** - * Consructs a new TokenPairConcatenatingFilter + * Constructs a new TokenPairConcatenatingFilter * @param stream the TokenStream that this filter will process */ public TokenPairConcatenatingFilter(TokenStream stream) { @@ -48,8 +48,8 @@ public final class TokenPairConcatenatingFilter extends TokenFilter { } /** - * Increments the underlying TokenStream and sets CharTermAtttributes to - * construct an expanded set of tokens by concatenting tokens with the + * Increments the underlying TokenStream and sets CharTermAttributes to + * construct an expanded set of tokens by concatenating tokens with the * previous token. * * @return whether or not we have hit the end of the TokenStream diff --git a/src/main/java/org/codesecure/dependencycheck/data/lucene/VersionTokenizingFilter.java b/src/main/java/org/codesecure/dependencycheck/data/lucene/VersionTokenizingFilter.java index bc4f70c9e..01e8b023e 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/lucene/VersionTokenizingFilter.java +++ b/src/main/java/org/codesecure/dependencycheck/data/lucene/VersionTokenizingFilter.java @@ -39,7 +39,7 @@ public final class VersionTokenizingFilter extends TokenFilter { protected LinkedList tokens = null; /** - * Consructs a new VersionTokenizingFilter + * Constructs a new VersionTokenizingFilter * @param stream the TokenStream that this filter will process */ public VersionTokenizingFilter(TokenStream stream) { @@ -48,8 +48,8 @@ public final class VersionTokenizingFilter extends TokenFilter { } /** - * Increments the underlying TokenStream and sets CharTermAtttributes to - * construct an expanded set of tokens by concatenting tokens with the + * Increments the underlying TokenStream and sets CharTermAttributes to + * construct an expanded set of tokens by concatenating tokens with the * previous token. * * @return whether or not we have hit the end of the TokenStream @@ -65,8 +65,8 @@ public final class VersionTokenizingFilter extends TokenFilter { } /** - * Adds a term, if one exists, from the tokens collection.. - * @return + * Adds a term, if one exists, from the tokens collection. + * @return whether or not a new term was added */ private boolean addTerm() { boolean termAdded = tokens.size() > 0; @@ -84,8 +84,7 @@ public final class VersionTokenizingFilter extends TokenFilter { // to incorporate the dash or underscore back in... String[] versionParts = version.split("\\."); String dottedVersion = null; - for (int x = 0; x < versionParts.length; x++) { - String current = versionParts[x]; + for (String current : versionParts) { if (!current.matches("^/d+$")) { tokens.add(current); } diff --git a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/NvdCveAnalyzer.java b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/NvdCveAnalyzer.java index dfbd4afa4..e0ed6ccaa 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/NvdCveAnalyzer.java +++ b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/NvdCveAnalyzer.java @@ -31,7 +31,7 @@ import org.codesecure.dependencycheck.dependency.Identifier; /** * NvdCveAnalyzer is a utility class that takes a project dependency and - * attempts to decern if there is an associated CVEs. It uses the the + * attempts to discern if there is an associated CVEs. It uses the the * identifiers found by other analyzers to lookup the CVE data. * * @author Jeremy Long (jeremy.long@gmail.com) @@ -50,7 +50,7 @@ public class NvdCveAnalyzer implements org.codesecure.dependencycheck.analyzer.A /** * Opens the data source. * - * @throws SQLException thrown wwhen there is a SQL Exception + * @throws SQLException thrown when there is a SQL Exception * @throws IOException thrown when there is an IO Exception * @throws DatabaseException thrown when there is a database exceptions */ diff --git a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/DatabaseUpdater.java b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/DatabaseUpdater.java index b9dbb4a45..aad4d112d 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/DatabaseUpdater.java +++ b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/DatabaseUpdater.java @@ -209,7 +209,7 @@ public class DatabaseUpdater implements CachedWebDataSource { * Writes a properties file containing the last updated date to the * VULNERABLE_CPE directory. * - * @param timeStamp the timestamp to write. + * @param updated a map of the updated nvdcve. */ private void writeLastUpdatedPropertyFile(Map updated) throws UpdateException { String dir; @@ -321,8 +321,8 @@ public class DatabaseUpdater implements CachedWebDataSource { FileUtils.delete(f); //this importer also updates the CPE index and it is also using an old version - org.codesecure.dependencycheck.data.cpe.Index cpeidx = new org.codesecure.dependencycheck.data.cpe.Index(); - File cpeDir = cpeidx.getDataDirectory(); + org.codesecure.dependencycheck.data.cpe.Index cpeid = new org.codesecure.dependencycheck.data.cpe.Index(); + File cpeDir = cpeid.getDataDirectory(); FileUtils.delete(cpeDir); return currentlyPublished; } diff --git a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/InvalidDataException.java b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/InvalidDataException.java index bbc41027d..92ede21a3 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/InvalidDataException.java +++ b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/InvalidDataException.java @@ -19,7 +19,7 @@ package org.codesecure.dependencycheck.data.nvdcve.xml; /** - * An InvalidataDataException is a generic exception used when trying to load + * An InvalidDataDataException is a generic exception used when trying to load * the nvd cve meta data. * * @author Jeremy diff --git a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/NvdCve20Handler.java b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/NvdCve20Handler.java index 11fe26204..7fba59aec 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/NvdCve20Handler.java +++ b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/NvdCve20Handler.java @@ -248,7 +248,7 @@ public class NvdCve20Handler extends DefaultHandler { /** * A node type in the NVD CVE Schema 2.0 */ - public static final String VULN_REFERNCES = "vuln:references"; + public static final String VULN_REFERENCES = "vuln:references"; /** * A node type in the NVD CVE Schema 2.0 */ @@ -256,7 +256,7 @@ public class NvdCve20Handler extends DefaultHandler { /** * A node type in the NVD CVE Schema 2.0 */ - public static final String VULN_REFERNCE = "vuln:reference"; + public static final String VULN_REFERENCE = "vuln:reference"; /** * A node type in the NVD CVE Schema 2.0 */ @@ -348,7 +348,7 @@ public class NvdCve20Handler extends DefaultHandler { * @return true or false */ public boolean isVulnReferencesNode() { - return VULN_REFERNCES.equals(node); + return VULN_REFERENCES.equals(node); } /** @@ -357,7 +357,7 @@ public class NvdCve20Handler extends DefaultHandler { * @return true or false */ public boolean isVulnReferenceNode() { - return VULN_REFERNCE.equals(node); + return VULN_REFERENCE.equals(node); } /** diff --git a/src/main/java/org/codesecure/dependencycheck/dependency/Dependency.java b/src/main/java/org/codesecure/dependencycheck/dependency/Dependency.java index 3d9b076e8..72f604f65 100644 --- a/src/main/java/org/codesecure/dependencycheck/dependency/Dependency.java +++ b/src/main/java/org/codesecure/dependencycheck/dependency/Dependency.java @@ -293,7 +293,7 @@ public class Dependency { return this.versionEvidence; } /** - * A list of exceptions that occured during analysis of this dependency. + * A list of exceptions that occurred during analysis of this dependency. */ protected List analysisExceptions = new ArrayList(); diff --git a/src/main/java/org/codesecure/dependencycheck/dependency/Identifier.java b/src/main/java/org/codesecure/dependencycheck/dependency/Identifier.java index 55220444f..21beef5fd 100644 --- a/src/main/java/org/codesecure/dependencycheck/dependency/Identifier.java +++ b/src/main/java/org/codesecure/dependencycheck/dependency/Identifier.java @@ -50,7 +50,7 @@ public class Identifier { this.description = description; } /** - * The value of the identifeir + * The value of the identifier */ protected String value; @@ -73,7 +73,7 @@ public class Identifier { } /** - * The url for the identifeir + * The url for the identifier */ protected String url; @@ -95,7 +95,7 @@ public class Identifier { this.url = url; } /** - * The type of the identifeir + * The type of the identifier */ protected String type; diff --git a/src/main/java/org/codesecure/dependencycheck/dependency/Vulnerability.java b/src/main/java/org/codesecure/dependencycheck/dependency/Vulnerability.java index b6dc52d4a..0e0b726f0 100644 --- a/src/main/java/org/codesecure/dependencycheck/dependency/Vulnerability.java +++ b/src/main/java/org/codesecure/dependencycheck/dependency/Vulnerability.java @@ -108,7 +108,7 @@ public class Vulnerability implements Serializable, Comparable { /** * Adds a reference - * @param referenceSource the source of the referece + * @param referenceSource the source of the reference * @param referenceName the referenceName of the reference * @param referenceUrl the url of the reference */ @@ -378,7 +378,7 @@ public class Vulnerability implements Serializable, Comparable { /** * Compares two vulnerabilities * - * @param v a vulnerabilitiy to be compared + * @param v a vulnerability to be compared * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified vulnerability */ public int compareTo(Vulnerability v) { diff --git a/src/main/java/org/codesecure/dependencycheck/dependency/VulnerableSoftware.java b/src/main/java/org/codesecure/dependencycheck/dependency/VulnerableSoftware.java index 218bc9f20..da954341a 100644 --- a/src/main/java/org/codesecure/dependencycheck/dependency/VulnerableSoftware.java +++ b/src/main/java/org/codesecure/dependencycheck/dependency/VulnerableSoftware.java @@ -35,7 +35,7 @@ public class VulnerableSoftware extends Entry implements Serializable { private static final long serialVersionUID = 307319490326651052L; /** - * Parse a CPE entry from the cpe string repesentation + * Parse a CPE entry from the cpe string representation * * @param cpe a cpe entry (e.g. cpe:/a:vendor:software:version) */ diff --git a/src/main/java/org/codesecure/dependencycheck/reporting/ReportGenerator.java b/src/main/java/org/codesecure/dependencycheck/reporting/ReportGenerator.java index e1396fb30..0676fca58 100644 --- a/src/main/java/org/codesecure/dependencycheck/reporting/ReportGenerator.java +++ b/src/main/java/org/codesecure/dependencycheck/reporting/ReportGenerator.java @@ -88,7 +88,7 @@ public class ReportGenerator { /** * Creates a new Velocity Context initialized with escape and date tools. - * @return a Velcotiy Context. + * @return a Velocity Context. */ private Context createContext() { ToolManager manager = new ToolManager(); @@ -106,7 +106,7 @@ public class ReportGenerator { * @param outputDir the path where the reports should be written. * @param outputFormat the format the report should be written in. * @throws IOException is thrown when the template file does not exist. - * @throws Exception is thrown if there is an error writting out the + * @throws Exception is thrown if there is an error writing out the * reports. */ public void generateReports(String outputDir, String outputFormat) throws IOException, Exception { diff --git a/src/main/java/org/codesecure/dependencycheck/utils/Checksum.java b/src/main/java/org/codesecure/dependencycheck/utils/Checksum.java index 1214f42de..e439cd2dc 100644 --- a/src/main/java/org/codesecure/dependencycheck/utils/Checksum.java +++ b/src/main/java/org/codesecure/dependencycheck/utils/Checksum.java @@ -23,7 +23,7 @@ public class Checksum { /** *

Creates the cryptographic checksum of a given file using the specified - * alogirhtm.

This algorithm was copied and heavily modified from + * algorithm.

This algorithm was copied and heavily modified from * Real's How To: http://www.rgagnon.com/javadetails/java-0416.html

* * @param algorithm the algorithm to use to calculate the checksum diff --git a/src/main/java/org/codesecure/dependencycheck/utils/CliParser.java b/src/main/java/org/codesecure/dependencycheck/utils/CliParser.java index 9d21b4d0f..5426a4c8b 100644 --- a/src/main/java/org/codesecure/dependencycheck/utils/CliParser.java +++ b/src/main/java/org/codesecure/dependencycheck/utils/CliParser.java @@ -209,7 +209,7 @@ public final class CliParser { * @return whether or not the 'version' command line argument was passed in */ public boolean isGetVersion() { - return (line != null) ? line.hasOption(ArgumentName.VERSION) : false; + return (line != null) && line.hasOption(ArgumentName.VERSION); } /** @@ -218,7 +218,7 @@ public final class CliParser { * @return whether or not the 'help' command line argument was passed in */ public boolean isGetHelp() { - return (line != null) ? line.hasOption(ArgumentName.HELP) : false; + return (line != null) && line.hasOption(ArgumentName.HELP); } /** @@ -227,7 +227,7 @@ public final class CliParser { * @return whether or not the 'scan' command line argument was passed in */ public boolean isRunScan() { - return (line != null) ? isValid && line.hasOption(ArgumentName.SCAN) : false; + return (line != null) && isValid && line.hasOption(ArgumentName.SCAN); } /** @@ -319,7 +319,7 @@ public final class CliParser { * @return if auto-update is allowed. */ public boolean isAutoUpdate() { - return (line != null) ? !line.hasOption(ArgumentName.DISABLE_AUTO_UPDATE) : true; + return (line == null) || !line.hasOption(ArgumentName.DISABLE_AUTO_UPDATE); } /** @@ -329,50 +329,50 @@ public final class CliParser { public static class ArgumentName { /** - * The long CLI argument name specifing the directory/file to scan + * The long CLI argument name specifying the directory/file to scan */ public static final String SCAN = "scan"; /** - * The short CLI argument name specifing the directory/file to scan + * The short CLI argument name specifying the directory/file to scan */ public static final String SCAN_SHORT = "s"; /** - * The long CLI argument name specifing that the CPE/CVE/etc. data + * The long CLI argument name specifying that the CPE/CVE/etc. data * should not be automatically updated. */ public static final String DISABLE_AUTO_UPDATE = "noupdate"; /** - * The short CLI argument name specifing that the CPE/CVE/etc. data + * The short CLI argument name specifying that the CPE/CVE/etc. data * should not be automatically updated. */ public static final String DISABLE_AUTO_UPDATE_SHORT = "n"; /** - * The long CLI argument name specifing the directory to write the + * The long CLI argument name specifying the directory to write the * reports to. */ public static final String OUT = "out"; /** - * The short CLI argument name specifing the directory to write the + * The short CLI argument name specifying the directory to write the * reports to. */ public static final String OUT_SHORT = "o"; /** - * The long CLI argument name specifing the output format to write the + * The long CLI argument name specifying the output format to write the * reports to. */ public static final String OUTPUT_FORMAT = "format"; /** - * The short CLI argument name specifing the output format to write the + * The short CLI argument name specifying the output format to write the * reports to. */ public static final String OUTPUT_FORMAT_SHORT = "f"; /** - * The long CLI argument name specifing the name of the application to + * The long CLI argument name specifying the name of the application to * be scanned. */ public static final String APPNAME = "app"; /** - * The short CLI argument name specifing the name of the application to + * The short CLI argument name specifying the name of the application to * be scanned. */ public static final String APPNAME_SHORT = "a"; diff --git a/src/main/java/org/codesecure/dependencycheck/utils/Downloader.java b/src/main/java/org/codesecure/dependencycheck/utils/Downloader.java index f9b272c15..a1e7b5cb0 100644 --- a/src/main/java/org/codesecure/dependencycheck/utils/Downloader.java +++ b/src/main/java/org/codesecure/dependencycheck/utils/Downloader.java @@ -64,7 +64,7 @@ public class Downloader { * @param url the URL of the file to download. * @param outputPath the path to the save the file to. * @param unzip true/false indicating that the file being retrieved is - * gzipped and if true, should be uncompressed before writting to the file. + * gzipped and if true, should be uncompressed before writing to the file. * @throws DownloadFailedException is thrown if there is an error * downloading the file. */ @@ -91,7 +91,7 @@ public class Downloader { * @param url the URL of the file to download. * @param outputPath the path to the save the file to. * @param unzip true/false indicating that the file being retrieved is - * gzipped and if true, should be uncompressed before writting to the file. + * gzipped and if true, should be uncompressed before writing to the file. * @throws DownloadFailedException is thrown if there is an error * downloading the file. */ @@ -190,7 +190,7 @@ public class Downloader { } /** - * Utility method to get an HttpURLConnectoin. If the app is configured to + * Utility method to get an HttpURLConnection. If the app is configured to * use a proxy this method will retrieve the proxy settings and use them * when setting up the connection. * diff --git a/src/main/java/org/codesecure/dependencycheck/utils/NonClosingStream.java b/src/main/java/org/codesecure/dependencycheck/utils/NonClosingStream.java index c24000c6d..bad9a531b 100644 --- a/src/main/java/org/codesecure/dependencycheck/utils/NonClosingStream.java +++ b/src/main/java/org/codesecure/dependencycheck/utils/NonClosingStream.java @@ -24,7 +24,7 @@ import java.io.InputStream; /** * NonClosingStream is a stream filter which prevents * another class that processes the stream from closing - * it. This is necassary when dealing with things like + * it. This is necessary when dealing with things like * JAXB and zipInputStreams. * * @author Jeremy Long (jeremy.long@gmail.com) diff --git a/src/main/java/org/codesecure/dependencycheck/utils/Settings.java b/src/main/java/org/codesecure/dependencycheck/utils/Settings.java index fdf9c0300..ad9e7987d 100644 --- a/src/main/java/org/codesecure/dependencycheck/utils/Settings.java +++ b/src/main/java/org/codesecure/dependencycheck/utils/Settings.java @@ -39,7 +39,7 @@ public class Settings { public static class KEYS { /** - * private contructor because this is a "utility" class containing constants + * private constructor because this is a "utility" class containing constants */ private KEYS() { //do nothing diff --git a/src/test/java/org/codesecure/dependencycheck/analyzer/JarAnalyzerTest.java b/src/test/java/org/codesecure/dependencycheck/analyzer/JarAnalyzerTest.java index 50f992839..7e4379d54 100644 --- a/src/test/java/org/codesecure/dependencycheck/analyzer/JarAnalyzerTest.java +++ b/src/test/java/org/codesecure/dependencycheck/analyzer/JarAnalyzerTest.java @@ -44,8 +44,8 @@ public class JarAnalyzerTest { } /** - * Test of insepct method, of class JarAnalyzer. - * @throws Exception is thrown when an excpetion occurs. + * Test of inspect method, of class JarAnalyzer. + * @throws Exception is thrown when an exception occurs. */ @Test public void testAnalyze() throws Exception { diff --git a/src/test/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzerTest.java b/src/test/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzerTest.java index 929040258..128420510 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzerTest.java +++ b/src/test/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzerTest.java @@ -13,26 +13,23 @@ import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.queryparser.classic.ParseException; import org.codesecure.dependencycheck.dependency.Dependency; import org.codesecure.dependencycheck.analyzer.JarAnalyzer; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; import org.junit.Test; /** * * @author jeremy */ -public class CPEAnalyzerTest extends BaseIndexTestCase { +public class CPEAnalyzerTest { - public CPEAnalyzerTest(String testName) { - super(testName); + @Before + public void setUp() throws Exception { } - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { } /** @@ -57,19 +54,19 @@ public class CPEAnalyzerTest extends BaseIndexTestCase { String queryText = instance.buildSearch(vendor, product, version, null, null); String expResult = " product:( struts 2 core ) AND vendor:( apache software foundation ) AND version:(2.1.2^0.7 )"; - assertTrue(expResult.equals(queryText)); + Assert.assertTrue(expResult.equals(queryText)); queryText = instance.buildSearch(vendor, product, version, null, productWeightings); expResult = " product:( struts^5 struts2^5 2 core ) AND vendor:( apache software foundation ) AND version:(2.1.2^0.2 )"; - assertTrue(expResult.equals(queryText)); + Assert.assertTrue(expResult.equals(queryText)); queryText = instance.buildSearch(vendor, product, version, vendorWeightings, null); expResult = " product:( struts 2 core ) AND vendor:( apache^5 software foundation ) AND version:(2.1.2^0.2 )"; - assertTrue(expResult.equals(queryText)); + Assert.assertTrue(expResult.equals(queryText)); queryText = instance.buildSearch(vendor, product, version, vendorWeightings, productWeightings); expResult = " product:( struts^5 struts2^5 2 core ) AND vendor:( apache^5 software foundation ) AND version:(2.1.2^0.2 )"; - assertTrue(expResult.equals(queryText)); + Assert.assertTrue(expResult.equals(queryText)); } /** @@ -80,11 +77,11 @@ public class CPEAnalyzerTest extends BaseIndexTestCase { public void testOpen() throws Exception { System.out.println("open"); CPEAnalyzer instance = new CPEAnalyzer(); - assertFalse(instance.isOpen()); + Assert.assertFalse(instance.isOpen()); instance.open(); - assertTrue(instance.isOpen()); + Assert.assertTrue(instance.isOpen()); instance.close(); - assertFalse(instance.isOpen()); + Assert.assertFalse(instance.isOpen()); } /** @@ -116,11 +113,11 @@ public class CPEAnalyzerTest extends BaseIndexTestCase { instance.determineCPE(spring); instance.determineCPE(spring3); instance.close(); - assertTrue("Incorrect match size - struts", depends.getIdentifiers().size() == 1); - assertTrue("Incorrect match - struts", depends.getIdentifiers().get(0).getValue().equals(expResult)); - assertTrue("Incorrect match size - spring", spring.getIdentifiers().size() == 1); - assertTrue("Incorrect match - spring", spring.getIdentifiers().get(0).getValue().equals(expResultSpring)); - assertTrue("Incorrect match size - spring3 - " + spring3.getIdentifiers().size(), spring3.getIdentifiers().size() >= 1); + Assert.assertTrue("Incorrect match size - struts", depends.getIdentifiers().size() == 1); + Assert.assertTrue("Incorrect match - struts", depends.getIdentifiers().get(0).getValue().equals(expResult)); + Assert.assertTrue("Incorrect match size - spring", spring.getIdentifiers().size() == 1); + Assert.assertTrue("Incorrect match - spring", spring.getIdentifiers().get(0).getValue().equals(expResultSpring)); + Assert.assertTrue("Incorrect match size - spring3 - " + spring3.getIdentifiers().size(), spring3.getIdentifiers().size() >= 1); //assertTrue("Incorrect match - spring3", spring3.getIdentifiers().get(0).getValue().equals(expResultSpring3)); } @@ -148,7 +145,7 @@ public class CPEAnalyzerTest extends BaseIndexTestCase { vendorWeightings.add("apache"); List result = instance.searchCPE(vendor, product, version, productWeightings, vendorWeightings); - assertEquals(expResult, result.get(0).getName()); + Assert.assertEquals(expResult, result.get(0).getName()); instance.close(); diff --git a/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexIntegrationTest.java b/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexIntegrationTest.java index 550a99a66..f21fd42d6 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexIntegrationTest.java +++ b/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexIntegrationTest.java @@ -18,11 +18,7 @@ import static org.junit.Assert.*; * * @author Jeremy Long (jeremy.long@gmail.com) */ -public class IndexIntegrationTest extends BaseIndexTestCase { - - public IndexIntegrationTest(String testCase) { - super(testCase); - } +public class IndexIntegrationTest { @BeforeClass public static void setUpClass() throws Exception { diff --git a/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexTest.java b/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexTest.java index d0e8db07c..3e9e109a3 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexTest.java +++ b/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexTest.java @@ -7,22 +7,15 @@ package org.codesecure.dependencycheck.data.cpe; import java.io.File; import java.io.IOException; import org.apache.lucene.store.Directory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.*; + import static org.junit.Assert.*; /** * * @author Jeremy Long (jeremy.long@gmail.com) */ -public class IndexTest extends BaseIndexTestCase { - - public IndexTest(String testCase) { - super(testCase); - } +public class IndexTest { @BeforeClass public static void setUpClass() throws Exception { @@ -50,7 +43,7 @@ public class IndexTest extends BaseIndexTestCase { try { instance.open(); } catch (IOException ex) { - fail(ex.getMessage()); + Assert.fail(ex.getMessage()); } instance.close(); } @@ -65,6 +58,6 @@ public class IndexTest extends BaseIndexTestCase { Directory result = index.getDirectory(); String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cpe"; - assertTrue(result.toString().contains(exp)); + Assert.assertTrue(result.toString().contains(exp)); } } diff --git a/src/test/java/org/codesecure/dependencycheck/data/cwe/CweDBTest.java b/src/test/java/org/codesecure/dependencycheck/data/cwe/CweDBTest.java index cbade30f4..10c2cc320 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/cwe/CweDBTest.java +++ b/src/test/java/org/codesecure/dependencycheck/data/cwe/CweDBTest.java @@ -43,7 +43,7 @@ public class CweDBTest { } /** - * Method to serlize the CWE HashMap. This is not used in + * Method to serialize the CWE HashMap. This is not used in * production; this is only used once during dev to create * the serialized hashmap. */ diff --git a/src/test/java/org/codesecure/dependencycheck/reporting/ReportGeneratorTest.java b/src/test/java/org/codesecure/dependencycheck/reporting/ReportGeneratorTest.java index fff8b7b69..a02455393 100644 --- a/src/test/java/org/codesecure/dependencycheck/reporting/ReportGeneratorTest.java +++ b/src/test/java/org/codesecure/dependencycheck/reporting/ReportGeneratorTest.java @@ -15,11 +15,7 @@ import org.junit.Test; * * @author Jeremy Long (jeremy.long@gmail.com) */ -public class ReportGeneratorTest extends BaseIndexTestCase { - - public ReportGeneratorTest(String testName) { - super(testName); - } +public class ReportGeneratorTest { @BeforeClass public static void setUpClass() throws Exception { @@ -30,12 +26,10 @@ public class ReportGeneratorTest extends BaseIndexTestCase { } @Before - @Override public void setUp() { } @After - @Override public void tearDown() { } diff --git a/src/test/java/org/codesecure/dependencycheck/utils/ChecksumTest.java b/src/test/java/org/codesecure/dependencycheck/utils/ChecksumTest.java index a9299fc14..1c553c9bf 100644 --- a/src/test/java/org/codesecure/dependencycheck/utils/ChecksumTest.java +++ b/src/test/java/org/codesecure/dependencycheck/utils/ChecksumTest.java @@ -8,26 +8,23 @@ import java.io.File; import java.io.IOException; import java.security.NoSuchAlgorithmException; import junit.framework.TestCase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; import org.junit.Test; /** * * @author jeremy */ -public class ChecksumTest extends TestCase { +public class ChecksumTest { - public ChecksumTest(String testName) { - super(testName); + @Before + public void setUp() throws Exception { } - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { } /** @@ -47,14 +44,14 @@ public class ChecksumTest extends TestCase { arraysAreEqual = result[i] == expResult[i]; } } else { - fail("Checksum results do not match expected results."); + Assert.fail("Checksum results do not match expected results."); } - assertTrue(arraysAreEqual); + Assert.assertTrue(arraysAreEqual); } /** * Test of getChecksum method, of class Checksum. This checks that an - * excpetion is thrown when an invalid path is specified. + * exception is thrown when an invalid path is specified. * * @throws Exception is thrown when an exception occurs. */ @@ -69,7 +66,7 @@ public class ChecksumTest extends TestCase { } catch (IOException ex) { exceptionThrown = true; } - assertTrue(exceptionThrown); + Assert.assertTrue(exceptionThrown); } /** @@ -89,7 +86,7 @@ public class ChecksumTest extends TestCase { } catch (NoSuchAlgorithmException ex) { exceptionThrown = true; } - assertTrue(exceptionThrown); + Assert.assertTrue(exceptionThrown); } /** @@ -102,7 +99,7 @@ public class ChecksumTest extends TestCase { File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath()); String expResult = "F0915C5F46B8CFA283E5AD67A09B3793"; String result = Checksum.getMD5Checksum(file); - assertEquals(expResult, result); + Assert.assertEquals(expResult, result); } /** @@ -115,7 +112,7 @@ public class ChecksumTest extends TestCase { File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath()); String expResult = "B8A9FF28B21BCB1D0B50E24A5243D8B51766851A"; String result = Checksum.getSHA1Checksum(file); - assertEquals(expResult, result); + Assert.assertEquals(expResult, result); } /** @@ -127,6 +124,6 @@ public class ChecksumTest extends TestCase { byte[] raw = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; String expResult = "000102030405060708090A0B0C0D0E0F10"; String result = Checksum.getHex(raw); - assertEquals(expResult, result); + Assert.assertEquals(expResult, result); } } diff --git a/src/test/java/org/codesecure/dependencycheck/utils/CliParserTest.java b/src/test/java/org/codesecure/dependencycheck/utils/CliParserTest.java index b9b9ed51c..03914a087 100644 --- a/src/test/java/org/codesecure/dependencycheck/utils/CliParserTest.java +++ b/src/test/java/org/codesecure/dependencycheck/utils/CliParserTest.java @@ -11,31 +11,28 @@ import java.io.IOException; import java.io.PrintStream; import junit.framework.TestCase; import org.apache.commons.cli.ParseException; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; import org.junit.Test; /** * * @author jeremy */ -public class CliParserTest extends TestCase { +public class CliParserTest { - public CliParserTest(String testName) { - super(testName); + @Before + public void setUp() throws Exception { } - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { } /** * Test of parse method, of class CliParser. - * @throws Exception thrown when an excpetion occurs. + * @throws Exception thrown when an exception occurs. */ @Test public void testParse() throws Exception { @@ -50,14 +47,14 @@ public class CliParserTest extends TestCase { CliParser instance = new CliParser(); instance.parse(args); - assertFalse(instance.isGetVersion()); - assertFalse(instance.isGetHelp()); - assertFalse(instance.isRunScan()); + Assert.assertFalse(instance.isGetVersion()); + Assert.assertFalse(instance.isGetHelp()); + Assert.assertFalse(instance.isRunScan()); } /** * Test of parse method with help arg, of class CliParser. - * @throws Exception thrown when an excpetion occurs. + * @throws Exception thrown when an exception occurs. */ @Test public void testParse_help() throws Exception { @@ -69,14 +66,14 @@ public class CliParserTest extends TestCase { CliParser instance = new CliParser(); instance.parse(args); - assertFalse(instance.isGetVersion()); - assertTrue(instance.isGetHelp()); - assertFalse(instance.isRunScan()); + Assert.assertFalse(instance.isGetVersion()); + Assert.assertTrue(instance.isGetHelp()); + Assert.assertFalse(instance.isRunScan()); } /** * Test of parse method with version arg, of class CliParser. - * @throws Exception thrown when an excpetion occurs. + * @throws Exception thrown when an exception occurs. */ @Test public void testParse_version() throws Exception { @@ -86,15 +83,15 @@ public class CliParserTest extends TestCase { CliParser instance = new CliParser(); instance.parse(args); - assertTrue(instance.isGetVersion()); - assertFalse(instance.isGetHelp()); - assertFalse(instance.isRunScan()); + Assert.assertTrue(instance.isGetVersion()); + Assert.assertFalse(instance.isGetHelp()); + Assert.assertFalse(instance.isRunScan()); } /** * Test of parse method with jar and cpe args, of class CliParser. - * @throws Exception thrown when an excpetion occurs. + * @throws Exception thrown when an exception occurs. */ @Test public void testParse_unknown() throws Exception { @@ -114,16 +111,16 @@ public class CliParserTest extends TestCase { try { instance.parse(args); } catch (ParseException ex) { - assertTrue(ex.getMessage().contains("Unrecognized option")); + Assert.assertTrue(ex.getMessage().contains("Unrecognized option")); } - assertFalse(instance.isGetVersion()); - assertFalse(instance.isGetHelp()); - assertFalse(instance.isRunScan()); + Assert.assertFalse(instance.isGetVersion()); + Assert.assertFalse(instance.isGetHelp()); + Assert.assertFalse(instance.isRunScan()); } /** * Test of parse method with scan arg, of class CliParser. - * @throws Exception thrown when an excpetion occurs. + * @throws Exception thrown when an exception occurs. */ @Test public void testParse_scan() throws Exception { @@ -136,17 +133,17 @@ public class CliParserTest extends TestCase { try { instance.parse(args); } catch (ParseException ex) { - assertTrue(ex.getMessage().contains("Missing argument")); + Assert.assertTrue(ex.getMessage().contains("Missing argument")); } - assertFalse(instance.isGetVersion()); - assertFalse(instance.isGetHelp()); - assertFalse(instance.isRunScan()); + Assert.assertFalse(instance.isGetVersion()); + Assert.assertFalse(instance.isGetHelp()); + Assert.assertFalse(instance.isRunScan()); } /** * Test of parse method with jar arg, of class CliParser. - * @throws Exception thrown when an excpetion occurs. + * @throws Exception thrown when an exception occurs. */ @Test public void testParse_scan_unknownFile() throws Exception { @@ -158,17 +155,17 @@ public class CliParserTest extends TestCase { try { instance.parse(args); } catch (FileNotFoundException ex) { - assertTrue(ex.getMessage().contains("Invalid file argument")); + Assert.assertTrue(ex.getMessage().contains("Invalid file argument")); } - assertFalse(instance.isGetVersion()); - assertFalse(instance.isGetHelp()); - assertFalse(instance.isRunScan()); + Assert.assertFalse(instance.isGetVersion()); + Assert.assertFalse(instance.isGetHelp()); + Assert.assertFalse(instance.isRunScan()); } /** * Test of parse method with jar arg, of class CliParser. - * @throws Exception thrown when an excpetion occurs. + * @throws Exception thrown when an exception occurs. */ @Test public void testParse_scan_withFileExists() throws Exception { @@ -179,16 +176,16 @@ public class CliParserTest extends TestCase { CliParser instance = new CliParser(); instance.parse(args); - assertEquals(path.getCanonicalPath(), instance.getScanFiles()[0]); + Assert.assertEquals(path.getCanonicalPath(), instance.getScanFiles()[0]); - assertFalse(instance.isGetVersion()); - assertFalse(instance.isGetHelp()); - assertTrue(instance.isRunScan()); + Assert.assertFalse(instance.isGetVersion()); + Assert.assertFalse(instance.isGetHelp()); + Assert.assertTrue(instance.isRunScan()); } /** * Test of printVersionInfo, of class CliParser. - * @throws Exception thrown when an excpetion occurs. + * @throws Exception thrown when an exception occurs. */ @Test public void testParse_printVersionInfo() throws Exception { @@ -204,12 +201,12 @@ public class CliParserTest extends TestCase { baos.flush(); String text = (new String(baos.toByteArray())).toLowerCase(); String[] lines = text.split(System.getProperty("line.separator")); - assertEquals(1, lines.length); - assertTrue(text.contains("version")); - assertTrue(!text.contains("unknown")); + Assert.assertEquals(1, lines.length); + Assert.assertTrue(text.contains("version")); + Assert.assertTrue(!text.contains("unknown")); } catch (IOException ex) { System.setOut(out); - fail("CliParser.printVersionInfo did not write anything to system.out."); + Assert.fail("CliParser.printVersionInfo did not write anything to system.out."); } finally { System.setOut(out); } @@ -217,7 +214,7 @@ public class CliParserTest extends TestCase { /** * Test of printHelp, of class CliParser. - * @throws Exception thrown when an excpetion occurs. + * @throws Exception thrown when an exception occurs. */ @Test public void testParse_printHelp() throws Exception { @@ -238,11 +235,11 @@ public class CliParserTest extends TestCase { baos.flush(); String text = (new String(baos.toByteArray())); String[] lines = text.split(System.getProperty("line.separator")); - assertTrue(lines[0].startsWith("usage: ")); - assertTrue((lines.length > 2)); + Assert.assertTrue(lines[0].startsWith("usage: ")); + Assert.assertTrue((lines.length > 2)); } catch (IOException ex) { System.setOut(out); - fail("CliParser.printVersionInfo did not write anything to system.out."); + Assert.fail("CliParser.printVersionInfo did not write anything to system.out."); } finally { System.setOut(out); } diff --git a/src/test/java/org/codesecure/dependencycheck/utils/DownloaderIntegrationTest.java b/src/test/java/org/codesecure/dependencycheck/utils/DownloaderIntegrationTest.java index 29b6959f9..8dffae7ca 100644 --- a/src/test/java/org/codesecure/dependencycheck/utils/DownloaderIntegrationTest.java +++ b/src/test/java/org/codesecure/dependencycheck/utils/DownloaderIntegrationTest.java @@ -39,7 +39,7 @@ public class DownloaderIntegrationTest { /** * Test of fetchFile method, of class Downloader. - * @throws Exception thrown when an excpetion occurs. + * @throws Exception thrown when an exception occurs. */ @Test public void testFetchFile() throws Exception { diff --git a/src/test/java/org/codesecure/dependencycheck/utils/SettingsTest.java b/src/test/java/org/codesecure/dependencycheck/utils/SettingsTest.java index 24f1befc9..1f9c89aca 100644 --- a/src/test/java/org/codesecure/dependencycheck/utils/SettingsTest.java +++ b/src/test/java/org/codesecure/dependencycheck/utils/SettingsTest.java @@ -8,26 +8,23 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import junit.framework.TestCase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; import org.junit.Test; /** * * @author jeremy */ -public class SettingsTest extends TestCase { +public class SettingsTest { - public SettingsTest(String testName) { - super(testName); + @Before + public void setUp() throws Exception { } - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { } /** @@ -39,7 +36,7 @@ public class SettingsTest extends TestCase { String key = Settings.KEYS.CPE_INDEX; String expResult = "target/data/cpe"; String result = Settings.getString(key); - assertTrue(result.endsWith(expResult)); + Assert.assertTrue(result.endsWith(expResult)); } /** @@ -54,7 +51,7 @@ public class SettingsTest extends TestCase { //InputStream in = this.getClass().getClassLoader().getResourceAsStream("test.properties"); Settings.mergeProperties(f.getAbsolutePath()); String result = Settings.getString(key); - assertTrue("setting didn't change?", (expResult == null && result != null) || !expResult.equals(result)); + Assert.assertTrue("setting didn't change?", (expResult == null && result != null) || !expResult.equals(result)); } /** @@ -67,7 +64,7 @@ public class SettingsTest extends TestCase { String value = "someValue"; Settings.setString(key, value); String expResults = Settings.getString(key); - assertEquals(expResults, value); + Assert.assertEquals(expResults, value); } /** @@ -80,9 +77,9 @@ public class SettingsTest extends TestCase { String defaultValue = "blue bunny"; String expResult = "blue bunny"; String result = Settings.getString(key); - assertTrue(result == null); + Assert.assertTrue(result == null); result = Settings.getString(key, defaultValue); - assertEquals(expResult, result); + Assert.assertEquals(expResult, result); } /** @@ -93,7 +90,7 @@ public class SettingsTest extends TestCase { System.out.println("getString"); String key = Settings.KEYS.CONNECTION_TIMEOUT; String result = Settings.getString(key); - assertTrue(result == null); + Assert.assertTrue(result == null); } /** @@ -106,7 +103,7 @@ public class SettingsTest extends TestCase { int expResult = 85; Settings.setString(key, "85"); int result = Settings.getInt(key); - assertEquals(expResult, result); + Assert.assertEquals(expResult, result); } /** @@ -119,7 +116,7 @@ public class SettingsTest extends TestCase { long expResult = 300L; Settings.setString(key, "300"); long result = Settings.getLong(key); - assertEquals(expResult, result); + Assert.assertEquals(expResult, result); } /** @@ -132,6 +129,6 @@ public class SettingsTest extends TestCase { Settings.setString(key, "false"); boolean expResult = false; boolean result = Settings.getBoolean(key); - assertEquals(expResult, result); + Assert.assertEquals(expResult, result); } }