cleanup and spelling fixes

Former-commit-id: 9c44ae88606f12728bc424d566ef11194c5c399b
This commit is contained in:
Jeremy Long
2013-02-19 21:35:24 -05:00
parent 9d624702f6
commit 6274cfce4b
39 changed files with 188 additions and 225 deletions

View File

@@ -200,7 +200,6 @@ public class Engine {
} catch (Exception ex1) { } catch (Exception ex1) {
Logger.getLogger(Engine.class.getName()).log(Level.FINER, null, ex1); Logger.getLogger(Engine.class.getName()).log(Level.FINER, null, ex1);
} }
continue;
} }
} }
} }

View File

@@ -18,6 +18,7 @@
*/ */
package org.codesecure.dependencycheck.analyzer; package org.codesecure.dependencycheck.analyzer;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@@ -39,10 +40,7 @@ public abstract class AbstractAnalyzer implements Analyzer {
protected static Set<String> newHashSet(String... strings) { protected static Set<String> newHashSet(String... strings) {
Set<String> set = new HashSet<String>(); Set<String> set = new HashSet<String>();
//yes, in Java7 we could use Array.toList(...) - but I'm trying to keep this Java 6 compliant. Collections.addAll(set, strings);
for (String s : strings) {
set.add(s);
}
return set; return set;
} }
} }

View File

@@ -33,7 +33,7 @@ public interface Analyzer {
/** /**
* Analyzes the given dependency. The analysis could be anything from * 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 * etc. Additionally, if the analyzer collects enough information to add a
* description or license information for the dependency it should be added. * 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. * Returns whether or not this analyzer can process the given extension.
* *
* @param extension the file extension to test for support. * @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. * analyzer.
*/ */
boolean supportsExtension(String extension); boolean supportsExtension(String extension);

View File

@@ -28,7 +28,7 @@ import java.util.ServiceLoader;
public class AnalyzerService { public class AnalyzerService {
private static AnalyzerService service; private static AnalyzerService service;
private ServiceLoader<Analyzer> loader; private final ServiceLoader<Analyzer> loader;
/** /**
* Creates a new instance of AnalyzerService * Creates a new instance of AnalyzerService

View File

@@ -66,7 +66,7 @@ public class FileNameAnalyzer implements Analyzer {
* Returns whether or not this analyzer can process the given extension. * Returns whether or not this analyzer can process the given extension.
* *
* @param extension the file extension to test for support. * @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. * analyzer.
*/ */
public boolean supportsExtension(String extension) { public boolean supportsExtension(String extension) {

View File

@@ -115,10 +115,6 @@ public class JarAnalyzer extends AbstractAnalyzer implements Analyzer {
* item in some manifest, should be considered medium confidence. * item in some manifest, should be considered medium confidence.
*/ */
private static final String BUNDLE_VENDOR = "Bundle-Vendor"; //: Apache Software Foundation 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. * 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() { public JarAnalyzer() {
try { try {
jaxbContext = JAXBContext.newInstance("org.codesecure.dependencycheck.analyzer.pom.generated"); JAXBContext jaxbContext = JAXBContext.newInstance("org.codesecure.dependencycheck.analyzer.pom.generated");
pomUnmarshaller = jaxbContext.createUnmarshaller(); pomUnmarshaller = jaxbContext.createUnmarshaller();
} catch (JAXBException ex) { //guess we will just have a null pointer exception later... } catch (JAXBException ex) { //guess we will just have a null pointer exception later...
Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, null, ex);

View File

@@ -69,8 +69,8 @@ public class SpringCleaningAnalyzer extends AbstractAnalyzer {
/** /**
* Returns whether or not this analyzer can process the given extension. * Returns whether or not this analyzer can process the given extension.
* *
* @param extension the file extension to test for support. * @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. * analyzer.
*/ */
public boolean supportsExtension(String extension) { public boolean supportsExtension(String extension) {
@@ -104,7 +104,7 @@ public class SpringCleaningAnalyzer extends AbstractAnalyzer {
private List<Identifier> springVersions = null; private List<Identifier> 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 * cpe:/a:springsource:spring_framework:[version] from the none "core" framework
* if the core framework was part of the scan. * if the core framework was part of the scan.
* *

View File

@@ -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.
* *
* *
* <p>Java class for DeploymentRepository complex type. * <p>Java class for DeploymentRepository complex type.

View File

@@ -18,7 +18,7 @@ import javax.xml.namespace.QName;
* This object contains factory methods for each * This object contains factory methods for each
* Java content interface and Java element interface * Java content interface and Java element interface
* generated in the org.codesecure.dependencycheck.analyzer.pom.generated package. * generated in the org.codesecure.dependencycheck.analyzer.pom.generated package.
* <p>An ObjectFactory allows you to programatically * <p>An ObjectFactory allows you to programmatically
* construct new instances of the Java representation * construct new instances of the Java representation
* for XML content. The Java representation of XML * for XML content. The Java representation of XML
* content can consist of schema derived interfaces * content can consist of schema derived interfaces

View File

@@ -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.
* *
* *
* <p>Java class for Repository complex type. * <p>Java class for Repository complex type.

View File

@@ -28,7 +28,7 @@ import java.util.ServiceLoader;
public class UpdateService { public class UpdateService {
private static UpdateService service; private static UpdateService service;
private ServiceLoader<CachedWebDataSource> loader; private final ServiceLoader<CachedWebDataSource> loader;
/** /**
* Creates a new instance of UpdateService * Creates a new instance of UpdateService

View File

@@ -40,7 +40,7 @@ import org.codesecure.dependencycheck.dependency.EvidenceCollection;
/** /**
* CPEAnalyzer is a utility class that takes a project dependency and attempts * 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. * within the dependency to search the Lucene index.
* *
* @author Jeremy Long (jeremy.long@gmail.com) * @author Jeremy Long (jeremy.long@gmail.com)
@@ -78,7 +78,7 @@ public class CPEAnalyzer implements org.codesecure.dependencycheck.analyzer.Anal
/** /**
* Opens the data source. * 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. * exist or is corrupt.
*/ */
public void open() throws IOException { public void open() throws IOException {
@@ -99,7 +99,7 @@ public class CPEAnalyzer implements org.codesecure.dependencycheck.analyzer.Anal
* @return true or false. * @return true or false.
*/ */
public boolean isOpen() { 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 * Searches the data store of CPE entries, trying to identify the CPE for
* the given dependency based on the evidence contained within. The * 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. * @param dependency the dependency to search for CPE entries on.
* @throws CorruptIndexException is thrown when the Lucene index is corrupt. * @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 text the base text.
* @param ec an EvidenceCollection * @param ec an EvidenceCollection
* @param confidenceFilter a Confidence level to filter the evidence by. * @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) { private String addEvidenceWithoutDuplicateTerms(final String text, final EvidenceCollection ec, Confidence confidenceFilter) {
String txt = (text == null) ? "" : text; 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 version text to search the version field.
* @param vendorWeighting a list of strings to apply to the vendor to boost * @param vendorWeighting a list of strings to apply to the vendor to boost
* the terms weight. * 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. * boost the terms weight.
* @return the Lucene query. * @return the Lucene query.
*/ */
protected String buildSearch(String vendor, String product, String version, protected String buildSearch(String vendor, String product, String version,
Set<String> vendorWeighting, Set<String> produdctWeightings) { Set<String> vendorWeighting, Set<String> productWeightings) {
StringBuilder sb = new StringBuilder(vendor.length() + product.length() StringBuilder sb = new StringBuilder(vendor.length() + product.length()
+ version.length() + Fields.PRODUCT.length() + Fields.VERSION.length() + version.length() + Fields.PRODUCT.length() + Fields.VERSION.length()
@@ -301,7 +301,7 @@ public class CPEAnalyzer implements org.codesecure.dependencycheck.analyzer.Anal
return null; return null;
} }
if (!appendWeightedSearch(sb, Fields.PRODUCT, product, produdctWeightings)) { if (!appendWeightedSearch(sb, Fields.PRODUCT, product, productWeightings)) {
return null; return null;
} }
sb.append(" AND "); 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 * 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 * weighted words then an additional weighting is applied to the term as it
* is appended into the query. * is appended into the query.
* *

View File

@@ -19,15 +19,15 @@
package org.codesecure.dependencycheck.data.lucene; package org.codesecure.dependencycheck.data.lucene;
/** /**
* <p>Lucene utils is a set of utilitize written to make constructing Lucene * <p>Lucene utils is a set of utilize written to make constructing Lucene
* queries simplier.</p> * queries simpler.</p>
* *
* @author Jeremy Long (jeremy.long@gmail.com) * @author Jeremy Long (jeremy.long@gmail.com)
*/ */
public final class LuceneUtils { public final class LuceneUtils {
/** /**
* Provate contructor as this is a utility class. * Private constructor as this is a utility class.
*/ */
private LuceneUtils() { private LuceneUtils() {
} }

View File

@@ -39,7 +39,7 @@ public final class TokenPairConcatenatingFilter extends TokenFilter {
private LinkedList<String> words = null; private LinkedList<String> words = null;
/** /**
* Consructs a new TokenPairConcatenatingFilter * Constructs a new TokenPairConcatenatingFilter
* @param stream the TokenStream that this filter will process * @param stream the TokenStream that this filter will process
*/ */
public TokenPairConcatenatingFilter(TokenStream stream) { public TokenPairConcatenatingFilter(TokenStream stream) {
@@ -48,8 +48,8 @@ public final class TokenPairConcatenatingFilter extends TokenFilter {
} }
/** /**
* Increments the underlying TokenStream and sets CharTermAtttributes to * Increments the underlying TokenStream and sets CharTermAttributes to
* construct an expanded set of tokens by concatenting tokens with the * construct an expanded set of tokens by concatenating tokens with the
* previous token. * previous token.
* *
* @return whether or not we have hit the end of the TokenStream * @return whether or not we have hit the end of the TokenStream

View File

@@ -39,7 +39,7 @@ public final class VersionTokenizingFilter extends TokenFilter {
protected LinkedList<String> tokens = null; protected LinkedList<String> tokens = null;
/** /**
* Consructs a new VersionTokenizingFilter * Constructs a new VersionTokenizingFilter
* @param stream the TokenStream that this filter will process * @param stream the TokenStream that this filter will process
*/ */
public VersionTokenizingFilter(TokenStream stream) { public VersionTokenizingFilter(TokenStream stream) {
@@ -48,8 +48,8 @@ public final class VersionTokenizingFilter extends TokenFilter {
} }
/** /**
* Increments the underlying TokenStream and sets CharTermAtttributes to * Increments the underlying TokenStream and sets CharTermAttributes to
* construct an expanded set of tokens by concatenting tokens with the * construct an expanded set of tokens by concatenating tokens with the
* previous token. * previous token.
* *
* @return whether or not we have hit the end of the TokenStream * @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.. * Adds a term, if one exists, from the tokens collection.
* @return * @return whether or not a new term was added
*/ */
private boolean addTerm() { private boolean addTerm() {
boolean termAdded = tokens.size() > 0; boolean termAdded = tokens.size() > 0;
@@ -84,8 +84,7 @@ public final class VersionTokenizingFilter extends TokenFilter {
// to incorporate the dash or underscore back in... // to incorporate the dash or underscore back in...
String[] versionParts = version.split("\\."); String[] versionParts = version.split("\\.");
String dottedVersion = null; String dottedVersion = null;
for (int x = 0; x < versionParts.length; x++) { for (String current : versionParts) {
String current = versionParts[x];
if (!current.matches("^/d+$")) { if (!current.matches("^/d+$")) {
tokens.add(current); tokens.add(current);
} }

View File

@@ -31,7 +31,7 @@ import org.codesecure.dependencycheck.dependency.Identifier;
/** /**
* NvdCveAnalyzer is a utility class that takes a project dependency and * 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. * identifiers found by other analyzers to lookup the CVE data.
* *
* @author Jeremy Long (jeremy.long@gmail.com) * @author Jeremy Long (jeremy.long@gmail.com)
@@ -50,7 +50,7 @@ public class NvdCveAnalyzer implements org.codesecure.dependencycheck.analyzer.A
/** /**
* Opens the data source. * 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 IOException thrown when there is an IO Exception
* @throws DatabaseException thrown when there is a database exceptions * @throws DatabaseException thrown when there is a database exceptions
*/ */

View File

@@ -209,7 +209,7 @@ public class DatabaseUpdater implements CachedWebDataSource {
* Writes a properties file containing the last updated date to the * Writes a properties file containing the last updated date to the
* VULNERABLE_CPE directory. * VULNERABLE_CPE directory.
* *
* @param timeStamp the timestamp to write. * @param updated a map of the updated nvdcve.
*/ */
private void writeLastUpdatedPropertyFile(Map<String, NvdCveUrl> updated) throws UpdateException { private void writeLastUpdatedPropertyFile(Map<String, NvdCveUrl> updated) throws UpdateException {
String dir; String dir;
@@ -321,8 +321,8 @@ public class DatabaseUpdater implements CachedWebDataSource {
FileUtils.delete(f); FileUtils.delete(f);
//this importer also updates the CPE index and it is also using an old version //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(); org.codesecure.dependencycheck.data.cpe.Index cpeid = new org.codesecure.dependencycheck.data.cpe.Index();
File cpeDir = cpeidx.getDataDirectory(); File cpeDir = cpeid.getDataDirectory();
FileUtils.delete(cpeDir); FileUtils.delete(cpeDir);
return currentlyPublished; return currentlyPublished;
} }

View File

@@ -19,7 +19,7 @@
package org.codesecure.dependencycheck.data.nvdcve.xml; 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. * the nvd cve meta data.
* *
* @author Jeremy * @author Jeremy

View File

@@ -248,7 +248,7 @@ public class NvdCve20Handler extends DefaultHandler {
/** /**
* A node type in the NVD CVE Schema 2.0 * 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 * 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 * 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 * A node type in the NVD CVE Schema 2.0
*/ */
@@ -348,7 +348,7 @@ public class NvdCve20Handler extends DefaultHandler {
* @return true or false * @return true or false
*/ */
public boolean isVulnReferencesNode() { 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 * @return true or false
*/ */
public boolean isVulnReferenceNode() { public boolean isVulnReferenceNode() {
return VULN_REFERNCE.equals(node); return VULN_REFERENCE.equals(node);
} }
/** /**

View File

@@ -293,7 +293,7 @@ public class Dependency {
return this.versionEvidence; 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<Exception> analysisExceptions = new ArrayList<Exception>(); protected List<Exception> analysisExceptions = new ArrayList<Exception>();

View File

@@ -50,7 +50,7 @@ public class Identifier {
this.description = description; this.description = description;
} }
/** /**
* The value of the identifeir * The value of the identifier
*/ */
protected String value; protected String value;
@@ -73,7 +73,7 @@ public class Identifier {
} }
/** /**
* The url for the identifeir * The url for the identifier
*/ */
protected String url; protected String url;
@@ -95,7 +95,7 @@ public class Identifier {
this.url = url; this.url = url;
} }
/** /**
* The type of the identifeir * The type of the identifier
*/ */
protected String type; protected String type;

View File

@@ -108,7 +108,7 @@ public class Vulnerability implements Serializable, Comparable<Vulnerability> {
/** /**
* Adds a reference * 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 referenceName the referenceName of the reference
* @param referenceUrl the url of the reference * @param referenceUrl the url of the reference
*/ */
@@ -378,7 +378,7 @@ public class Vulnerability implements Serializable, Comparable<Vulnerability> {
/** /**
* Compares two vulnerabilities * 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 * @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) { public int compareTo(Vulnerability v) {

View File

@@ -35,7 +35,7 @@ public class VulnerableSoftware extends Entry implements Serializable {
private static final long serialVersionUID = 307319490326651052L; 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) * @param cpe a cpe entry (e.g. cpe:/a:vendor:software:version)
*/ */

View File

@@ -88,7 +88,7 @@ public class ReportGenerator {
/** /**
* Creates a new Velocity Context initialized with escape and date tools. * Creates a new Velocity Context initialized with escape and date tools.
* @return a Velcotiy Context. * @return a Velocity Context.
*/ */
private Context createContext() { private Context createContext() {
ToolManager manager = new ToolManager(); ToolManager manager = new ToolManager();
@@ -106,7 +106,7 @@ public class ReportGenerator {
* @param outputDir the path where the reports should be written. * @param outputDir the path where the reports should be written.
* @param outputFormat the format the report should be written in. * @param outputFormat the format the report should be written in.
* @throws IOException is thrown when the template file does not exist. * @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. * reports.
*/ */
public void generateReports(String outputDir, String outputFormat) throws IOException, Exception { public void generateReports(String outputDir, String outputFormat) throws IOException, Exception {

View File

@@ -23,7 +23,7 @@ public class Checksum {
/** /**
* <p>Creates the cryptographic checksum of a given file using the specified * <p>Creates the cryptographic checksum of a given file using the specified
* alogirhtm.</p> <p>This algorithm was copied and heavily modified from * algorithm.</p> <p>This algorithm was copied and heavily modified from
* Real's How To: http://www.rgagnon.com/javadetails/java-0416.html</p> * Real's How To: http://www.rgagnon.com/javadetails/java-0416.html</p>
* *
* @param algorithm the algorithm to use to calculate the checksum * @param algorithm the algorithm to use to calculate the checksum

View File

@@ -209,7 +209,7 @@ public final class CliParser {
* @return whether or not the 'version' command line argument was passed in * @return whether or not the 'version' command line argument was passed in
*/ */
public boolean isGetVersion() { 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 * @return whether or not the 'help' command line argument was passed in
*/ */
public boolean isGetHelp() { 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 * @return whether or not the 'scan' command line argument was passed in
*/ */
public boolean isRunScan() { 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. * @return if auto-update is allowed.
*/ */
public boolean isAutoUpdate() { 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 { 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"; 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"; 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. * should not be automatically updated.
*/ */
public static final String DISABLE_AUTO_UPDATE = "noupdate"; 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. * should not be automatically updated.
*/ */
public static final String DISABLE_AUTO_UPDATE_SHORT = "n"; 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. * reports to.
*/ */
public static final String OUT = "out"; 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. * reports to.
*/ */
public static final String OUT_SHORT = "o"; 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. * reports to.
*/ */
public static final String OUTPUT_FORMAT = "format"; 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. * reports to.
*/ */
public static final String OUTPUT_FORMAT_SHORT = "f"; 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. * be scanned.
*/ */
public static final String APPNAME = "app"; 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. * be scanned.
*/ */
public static final String APPNAME_SHORT = "a"; public static final String APPNAME_SHORT = "a";

View File

@@ -64,7 +64,7 @@ public class Downloader {
* @param url the URL of the file to download. * @param url the URL of the file to download.
* @param outputPath the path to the save the file to. * @param outputPath the path to the save the file to.
* @param unzip true/false indicating that the file being retrieved is * @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 * @throws DownloadFailedException is thrown if there is an error
* downloading the file. * downloading the file.
*/ */
@@ -91,7 +91,7 @@ public class Downloader {
* @param url the URL of the file to download. * @param url the URL of the file to download.
* @param outputPath the path to the save the file to. * @param outputPath the path to the save the file to.
* @param unzip true/false indicating that the file being retrieved is * @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 * @throws DownloadFailedException is thrown if there is an error
* downloading the file. * 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 * use a proxy this method will retrieve the proxy settings and use them
* when setting up the connection. * when setting up the connection.
* *

View File

@@ -24,7 +24,7 @@ import java.io.InputStream;
/** /**
* NonClosingStream is a stream filter which prevents * NonClosingStream is a stream filter which prevents
* another class that processes the stream from closing * 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. * JAXB and zipInputStreams.
* *
* @author Jeremy Long (jeremy.long@gmail.com) * @author Jeremy Long (jeremy.long@gmail.com)

View File

@@ -39,7 +39,7 @@ public class Settings {
public static class KEYS { 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() { private KEYS() {
//do nothing //do nothing

View File

@@ -44,8 +44,8 @@ public class JarAnalyzerTest {
} }
/** /**
* Test of insepct method, of class JarAnalyzer. * Test of inspect method, of class JarAnalyzer.
* @throws Exception is thrown when an excpetion occurs. * @throws Exception is thrown when an exception occurs.
*/ */
@Test @Test
public void testAnalyze() throws Exception { public void testAnalyze() throws Exception {

View File

@@ -13,26 +13,23 @@ import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.queryparser.classic.ParseException;
import org.codesecure.dependencycheck.dependency.Dependency; import org.codesecure.dependencycheck.dependency.Dependency;
import org.codesecure.dependencycheck.analyzer.JarAnalyzer; import org.codesecure.dependencycheck.analyzer.JarAnalyzer;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** /**
* *
* @author jeremy * @author jeremy
*/ */
public class CPEAnalyzerTest extends BaseIndexTestCase { public class CPEAnalyzerTest {
public CPEAnalyzerTest(String testName) { @Before
super(testName); public void setUp() throws Exception {
} }
@Override @After
protected void setUp() throws Exception { public void tearDown() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
} }
/** /**
@@ -57,19 +54,19 @@ public class CPEAnalyzerTest extends BaseIndexTestCase {
String queryText = instance.buildSearch(vendor, product, version, null, null); 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 )"; 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); 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 )"; 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); 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 )"; 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); 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 )"; 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 { public void testOpen() throws Exception {
System.out.println("open"); System.out.println("open");
CPEAnalyzer instance = new CPEAnalyzer(); CPEAnalyzer instance = new CPEAnalyzer();
assertFalse(instance.isOpen()); Assert.assertFalse(instance.isOpen());
instance.open(); instance.open();
assertTrue(instance.isOpen()); Assert.assertTrue(instance.isOpen());
instance.close(); instance.close();
assertFalse(instance.isOpen()); Assert.assertFalse(instance.isOpen());
} }
/** /**
@@ -116,11 +113,11 @@ public class CPEAnalyzerTest extends BaseIndexTestCase {
instance.determineCPE(spring); instance.determineCPE(spring);
instance.determineCPE(spring3); instance.determineCPE(spring3);
instance.close(); instance.close();
assertTrue("Incorrect match size - struts", depends.getIdentifiers().size() == 1); Assert.assertTrue("Incorrect match size - struts", depends.getIdentifiers().size() == 1);
assertTrue("Incorrect match - struts", depends.getIdentifiers().get(0).getValue().equals(expResult)); Assert.assertTrue("Incorrect match - struts", depends.getIdentifiers().get(0).getValue().equals(expResult));
assertTrue("Incorrect match size - spring", spring.getIdentifiers().size() == 1); Assert.assertTrue("Incorrect match size - spring", spring.getIdentifiers().size() == 1);
assertTrue("Incorrect match - spring", spring.getIdentifiers().get(0).getValue().equals(expResultSpring)); Assert.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 - spring3 - " + spring3.getIdentifiers().size(), spring3.getIdentifiers().size() >= 1);
//assertTrue("Incorrect match - spring3", spring3.getIdentifiers().get(0).getValue().equals(expResultSpring3)); //assertTrue("Incorrect match - spring3", spring3.getIdentifiers().get(0).getValue().equals(expResultSpring3));
} }
@@ -148,7 +145,7 @@ public class CPEAnalyzerTest extends BaseIndexTestCase {
vendorWeightings.add("apache"); vendorWeightings.add("apache");
List<Entry> result = instance.searchCPE(vendor, product, version, productWeightings, vendorWeightings); List<Entry> result = instance.searchCPE(vendor, product, version, productWeightings, vendorWeightings);
assertEquals(expResult, result.get(0).getName()); Assert.assertEquals(expResult, result.get(0).getName());
instance.close(); instance.close();

View File

@@ -18,11 +18,7 @@ import static org.junit.Assert.*;
* *
* @author Jeremy Long (jeremy.long@gmail.com) * @author Jeremy Long (jeremy.long@gmail.com)
*/ */
public class IndexIntegrationTest extends BaseIndexTestCase { public class IndexIntegrationTest {
public IndexIntegrationTest(String testCase) {
super(testCase);
}
@BeforeClass @BeforeClass
public static void setUpClass() throws Exception { public static void setUpClass() throws Exception {

View File

@@ -7,22 +7,15 @@ package org.codesecure.dependencycheck.data.cpe;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.junit.After; import org.junit.*;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
* *
* @author Jeremy Long (jeremy.long@gmail.com) * @author Jeremy Long (jeremy.long@gmail.com)
*/ */
public class IndexTest extends BaseIndexTestCase { public class IndexTest {
public IndexTest(String testCase) {
super(testCase);
}
@BeforeClass @BeforeClass
public static void setUpClass() throws Exception { public static void setUpClass() throws Exception {
@@ -50,7 +43,7 @@ public class IndexTest extends BaseIndexTestCase {
try { try {
instance.open(); instance.open();
} catch (IOException ex) { } catch (IOException ex) {
fail(ex.getMessage()); Assert.fail(ex.getMessage());
} }
instance.close(); instance.close();
} }
@@ -65,6 +58,6 @@ public class IndexTest extends BaseIndexTestCase {
Directory result = index.getDirectory(); Directory result = index.getDirectory();
String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cpe"; String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cpe";
assertTrue(result.toString().contains(exp)); Assert.assertTrue(result.toString().contains(exp));
} }
} }

View File

@@ -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 * production; this is only used once during dev to create
* the serialized hashmap. * the serialized hashmap.
*/ */

View File

@@ -15,11 +15,7 @@ import org.junit.Test;
* *
* @author Jeremy Long (jeremy.long@gmail.com) * @author Jeremy Long (jeremy.long@gmail.com)
*/ */
public class ReportGeneratorTest extends BaseIndexTestCase { public class ReportGeneratorTest {
public ReportGeneratorTest(String testName) {
super(testName);
}
@BeforeClass @BeforeClass
public static void setUpClass() throws Exception { public static void setUpClass() throws Exception {
@@ -30,12 +26,10 @@ public class ReportGeneratorTest extends BaseIndexTestCase {
} }
@Before @Before
@Override
public void setUp() { public void setUp() {
} }
@After @After
@Override
public void tearDown() { public void tearDown() {
} }

View File

@@ -8,26 +8,23 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** /**
* *
* @author jeremy * @author jeremy
*/ */
public class ChecksumTest extends TestCase { public class ChecksumTest {
public ChecksumTest(String testName) { @Before
super(testName); public void setUp() throws Exception {
} }
@Override @After
protected void setUp() throws Exception { public void tearDown() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
} }
/** /**
@@ -47,14 +44,14 @@ public class ChecksumTest extends TestCase {
arraysAreEqual = result[i] == expResult[i]; arraysAreEqual = result[i] == expResult[i];
} }
} else { } 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 * 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. * @throws Exception is thrown when an exception occurs.
*/ */
@@ -69,7 +66,7 @@ public class ChecksumTest extends TestCase {
} catch (IOException ex) { } catch (IOException ex) {
exceptionThrown = true; exceptionThrown = true;
} }
assertTrue(exceptionThrown); Assert.assertTrue(exceptionThrown);
} }
/** /**
@@ -89,7 +86,7 @@ public class ChecksumTest extends TestCase {
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
exceptionThrown = true; 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()); File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
String expResult = "F0915C5F46B8CFA283E5AD67A09B3793"; String expResult = "F0915C5F46B8CFA283E5AD67A09B3793";
String result = Checksum.getMD5Checksum(file); 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()); File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
String expResult = "B8A9FF28B21BCB1D0B50E24A5243D8B51766851A"; String expResult = "B8A9FF28B21BCB1D0B50E24A5243D8B51766851A";
String result = Checksum.getSHA1Checksum(file); 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}; byte[] raw = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
String expResult = "000102030405060708090A0B0C0D0E0F10"; String expResult = "000102030405060708090A0B0C0D0E0F10";
String result = Checksum.getHex(raw); String result = Checksum.getHex(raw);
assertEquals(expResult, result); Assert.assertEquals(expResult, result);
} }
} }

View File

@@ -11,31 +11,28 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** /**
* *
* @author jeremy * @author jeremy
*/ */
public class CliParserTest extends TestCase { public class CliParserTest {
public CliParserTest(String testName) { @Before
super(testName); public void setUp() throws Exception {
} }
@Override @After
protected void setUp() throws Exception { public void tearDown() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
} }
/** /**
* Test of parse method, of class CliParser. * Test of parse method, of class CliParser.
* @throws Exception thrown when an excpetion occurs. * @throws Exception thrown when an exception occurs.
*/ */
@Test @Test
public void testParse() throws Exception { public void testParse() throws Exception {
@@ -50,14 +47,14 @@ public class CliParserTest extends TestCase {
CliParser instance = new CliParser(); CliParser instance = new CliParser();
instance.parse(args); instance.parse(args);
assertFalse(instance.isGetVersion()); Assert.assertFalse(instance.isGetVersion());
assertFalse(instance.isGetHelp()); Assert.assertFalse(instance.isGetHelp());
assertFalse(instance.isRunScan()); Assert.assertFalse(instance.isRunScan());
} }
/** /**
* Test of parse method with help arg, of class CliParser. * 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 @Test
public void testParse_help() throws Exception { public void testParse_help() throws Exception {
@@ -69,14 +66,14 @@ public class CliParserTest extends TestCase {
CliParser instance = new CliParser(); CliParser instance = new CliParser();
instance.parse(args); instance.parse(args);
assertFalse(instance.isGetVersion()); Assert.assertFalse(instance.isGetVersion());
assertTrue(instance.isGetHelp()); Assert.assertTrue(instance.isGetHelp());
assertFalse(instance.isRunScan()); Assert.assertFalse(instance.isRunScan());
} }
/** /**
* Test of parse method with version arg, of class CliParser. * 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 @Test
public void testParse_version() throws Exception { public void testParse_version() throws Exception {
@@ -86,15 +83,15 @@ public class CliParserTest extends TestCase {
CliParser instance = new CliParser(); CliParser instance = new CliParser();
instance.parse(args); instance.parse(args);
assertTrue(instance.isGetVersion()); Assert.assertTrue(instance.isGetVersion());
assertFalse(instance.isGetHelp()); Assert.assertFalse(instance.isGetHelp());
assertFalse(instance.isRunScan()); Assert.assertFalse(instance.isRunScan());
} }
/** /**
* Test of parse method with jar and cpe args, of class CliParser. * 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 @Test
public void testParse_unknown() throws Exception { public void testParse_unknown() throws Exception {
@@ -114,16 +111,16 @@ public class CliParserTest extends TestCase {
try { try {
instance.parse(args); instance.parse(args);
} catch (ParseException ex) { } catch (ParseException ex) {
assertTrue(ex.getMessage().contains("Unrecognized option")); Assert.assertTrue(ex.getMessage().contains("Unrecognized option"));
} }
assertFalse(instance.isGetVersion()); Assert.assertFalse(instance.isGetVersion());
assertFalse(instance.isGetHelp()); Assert.assertFalse(instance.isGetHelp());
assertFalse(instance.isRunScan()); Assert.assertFalse(instance.isRunScan());
} }
/** /**
* Test of parse method with scan arg, of class CliParser. * 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 @Test
public void testParse_scan() throws Exception { public void testParse_scan() throws Exception {
@@ -136,17 +133,17 @@ public class CliParserTest extends TestCase {
try { try {
instance.parse(args); instance.parse(args);
} catch (ParseException ex) { } catch (ParseException ex) {
assertTrue(ex.getMessage().contains("Missing argument")); Assert.assertTrue(ex.getMessage().contains("Missing argument"));
} }
assertFalse(instance.isGetVersion()); Assert.assertFalse(instance.isGetVersion());
assertFalse(instance.isGetHelp()); Assert.assertFalse(instance.isGetHelp());
assertFalse(instance.isRunScan()); Assert.assertFalse(instance.isRunScan());
} }
/** /**
* Test of parse method with jar arg, of class CliParser. * 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 @Test
public void testParse_scan_unknownFile() throws Exception { public void testParse_scan_unknownFile() throws Exception {
@@ -158,17 +155,17 @@ public class CliParserTest extends TestCase {
try { try {
instance.parse(args); instance.parse(args);
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
assertTrue(ex.getMessage().contains("Invalid file argument")); Assert.assertTrue(ex.getMessage().contains("Invalid file argument"));
} }
assertFalse(instance.isGetVersion()); Assert.assertFalse(instance.isGetVersion());
assertFalse(instance.isGetHelp()); Assert.assertFalse(instance.isGetHelp());
assertFalse(instance.isRunScan()); Assert.assertFalse(instance.isRunScan());
} }
/** /**
* Test of parse method with jar arg, of class CliParser. * 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 @Test
public void testParse_scan_withFileExists() throws Exception { public void testParse_scan_withFileExists() throws Exception {
@@ -179,16 +176,16 @@ public class CliParserTest extends TestCase {
CliParser instance = new CliParser(); CliParser instance = new CliParser();
instance.parse(args); instance.parse(args);
assertEquals(path.getCanonicalPath(), instance.getScanFiles()[0]); Assert.assertEquals(path.getCanonicalPath(), instance.getScanFiles()[0]);
assertFalse(instance.isGetVersion()); Assert.assertFalse(instance.isGetVersion());
assertFalse(instance.isGetHelp()); Assert.assertFalse(instance.isGetHelp());
assertTrue(instance.isRunScan()); Assert.assertTrue(instance.isRunScan());
} }
/** /**
* Test of printVersionInfo, of class CliParser. * Test of printVersionInfo, of class CliParser.
* @throws Exception thrown when an excpetion occurs. * @throws Exception thrown when an exception occurs.
*/ */
@Test @Test
public void testParse_printVersionInfo() throws Exception { public void testParse_printVersionInfo() throws Exception {
@@ -204,12 +201,12 @@ public class CliParserTest extends TestCase {
baos.flush(); baos.flush();
String text = (new String(baos.toByteArray())).toLowerCase(); String text = (new String(baos.toByteArray())).toLowerCase();
String[] lines = text.split(System.getProperty("line.separator")); String[] lines = text.split(System.getProperty("line.separator"));
assertEquals(1, lines.length); Assert.assertEquals(1, lines.length);
assertTrue(text.contains("version")); Assert.assertTrue(text.contains("version"));
assertTrue(!text.contains("unknown")); Assert.assertTrue(!text.contains("unknown"));
} catch (IOException ex) { } catch (IOException ex) {
System.setOut(out); 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 { } finally {
System.setOut(out); System.setOut(out);
} }
@@ -217,7 +214,7 @@ public class CliParserTest extends TestCase {
/** /**
* Test of printHelp, of class CliParser. * Test of printHelp, of class CliParser.
* @throws Exception thrown when an excpetion occurs. * @throws Exception thrown when an exception occurs.
*/ */
@Test @Test
public void testParse_printHelp() throws Exception { public void testParse_printHelp() throws Exception {
@@ -238,11 +235,11 @@ public class CliParserTest extends TestCase {
baos.flush(); baos.flush();
String text = (new String(baos.toByteArray())); String text = (new String(baos.toByteArray()));
String[] lines = text.split(System.getProperty("line.separator")); String[] lines = text.split(System.getProperty("line.separator"));
assertTrue(lines[0].startsWith("usage: ")); Assert.assertTrue(lines[0].startsWith("usage: "));
assertTrue((lines.length > 2)); Assert.assertTrue((lines.length > 2));
} catch (IOException ex) { } catch (IOException ex) {
System.setOut(out); 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 { } finally {
System.setOut(out); System.setOut(out);
} }

View File

@@ -39,7 +39,7 @@ public class DownloaderIntegrationTest {
/** /**
* Test of fetchFile method, of class Downloader. * Test of fetchFile method, of class Downloader.
* @throws Exception thrown when an excpetion occurs. * @throws Exception thrown when an exception occurs.
*/ */
@Test @Test
public void testFetchFile() throws Exception { public void testFetchFile() throws Exception {

View File

@@ -8,26 +8,23 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** /**
* *
* @author jeremy * @author jeremy
*/ */
public class SettingsTest extends TestCase { public class SettingsTest {
public SettingsTest(String testName) { @Before
super(testName); public void setUp() throws Exception {
} }
@Override @After
protected void setUp() throws Exception { public void tearDown() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
} }
/** /**
@@ -39,7 +36,7 @@ public class SettingsTest extends TestCase {
String key = Settings.KEYS.CPE_INDEX; String key = Settings.KEYS.CPE_INDEX;
String expResult = "target/data/cpe"; String expResult = "target/data/cpe";
String result = Settings.getString(key); 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"); //InputStream in = this.getClass().getClassLoader().getResourceAsStream("test.properties");
Settings.mergeProperties(f.getAbsolutePath()); Settings.mergeProperties(f.getAbsolutePath());
String result = Settings.getString(key); 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"; String value = "someValue";
Settings.setString(key, value); Settings.setString(key, value);
String expResults = Settings.getString(key); 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 defaultValue = "blue bunny";
String expResult = "blue bunny"; String expResult = "blue bunny";
String result = Settings.getString(key); String result = Settings.getString(key);
assertTrue(result == null); Assert.assertTrue(result == null);
result = Settings.getString(key, defaultValue); 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"); System.out.println("getString");
String key = Settings.KEYS.CONNECTION_TIMEOUT; String key = Settings.KEYS.CONNECTION_TIMEOUT;
String result = Settings.getString(key); String result = Settings.getString(key);
assertTrue(result == null); Assert.assertTrue(result == null);
} }
/** /**
@@ -106,7 +103,7 @@ public class SettingsTest extends TestCase {
int expResult = 85; int expResult = 85;
Settings.setString(key, "85"); Settings.setString(key, "85");
int result = Settings.getInt(key); int result = Settings.getInt(key);
assertEquals(expResult, result); Assert.assertEquals(expResult, result);
} }
/** /**
@@ -119,7 +116,7 @@ public class SettingsTest extends TestCase {
long expResult = 300L; long expResult = 300L;
Settings.setString(key, "300"); Settings.setString(key, "300");
long result = Settings.getLong(key); 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"); Settings.setString(key, "false");
boolean expResult = false; boolean expResult = false;
boolean result = Settings.getBoolean(key); boolean result = Settings.getBoolean(key);
assertEquals(expResult, result); Assert.assertEquals(expResult, result);
} }
} }