mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-21 16:49:43 +01:00
fixed unit test
Former-commit-id: d4560b518805dcdf20d17f92c7b214dad2fa9676
This commit is contained in:
@@ -24,9 +24,14 @@ import java.util.Arrays;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.junit.After;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.owasp.dependencycheck.BaseTest;
|
import org.owasp.dependencycheck.BaseTest;
|
||||||
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
||||||
|
import org.owasp.dependencycheck.dependency.Dependency;
|
||||||
|
import org.owasp.dependencycheck.dependency.Evidence;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for PythonPackageAnalyzer.
|
* Unit tests for PythonPackageAnalyzer.
|
||||||
@@ -35,13 +40,41 @@ import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
|||||||
*/
|
*/
|
||||||
public class PythonPackageAnalyzerTest extends BaseTest {
|
public class PythonPackageAnalyzerTest extends BaseTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The package analyzer to test.
|
||||||
|
*/
|
||||||
|
PythonPackageAnalyzer analyzer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the PtyhonPackageAnalyzer.
|
||||||
|
*
|
||||||
|
* @throws Exception if there is a problem
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
analyzer = new PythonPackageAnalyzer();
|
||||||
|
analyzer.setFilesMatched(true);
|
||||||
|
analyzer.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanup any resources used.
|
||||||
|
*
|
||||||
|
* @throws Exception if there is a problem
|
||||||
|
*/
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
analyzer.close();
|
||||||
|
analyzer = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getName method, of class PythonPackageAnalyzer.
|
* Test of getName method, of class PythonPackageAnalyzer.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetName() {
|
public void testGetName() {
|
||||||
assertEquals("Analyzer name wrong.", "Python Distribution Analyzer",
|
assertEquals("Analyzer name wrong.", "Python Package Analyzer",
|
||||||
new PythonDistributionAnalyzer().getName());
|
analyzer.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,11 +82,11 @@ public class PythonPackageAnalyzerTest extends BaseTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetSupportedExtensions() {
|
public void testGetSupportedExtensions() {
|
||||||
final String[] expected = { "py" };
|
final String[] expected = {"py"};
|
||||||
assertEquals("Supported extensions should just have the following: "
|
assertEquals("Supported extensions should just have the following: "
|
||||||
+ StringUtils.join(expected, ", "),
|
+ StringUtils.join(expected, ", "),
|
||||||
new HashSet<String>(Arrays.asList(expected)),
|
new HashSet<String>(Arrays.asList(expected)),
|
||||||
new PythonPackageAnalyzer().getSupportedExtensions());
|
analyzer.getSupportedExtensions());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,12 +95,28 @@ public class PythonPackageAnalyzerTest extends BaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testSupportsExtension() {
|
public void testSupportsExtension() {
|
||||||
assertTrue("Should support \"py\" extension.",
|
assertTrue("Should support \"py\" extension.",
|
||||||
new PythonPackageAnalyzer().supportsExtension("py"));
|
analyzer.supportsExtension("py"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnalyzeSourceMetadata() throws AnalysisException {
|
public void testAnalyzeSourceMetadata() throws AnalysisException {
|
||||||
PythonDistributionAnalyzerTest.eggtestAssertions(this,
|
eggtestAssertions(this,
|
||||||
"python/eggtest/__init__.py", new PythonPackageAnalyzer());
|
"python/eggtest/__init__.py");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void eggtestAssertions(Object context, final String resource) throws AnalysisException {
|
||||||
|
boolean found = false;
|
||||||
|
final Dependency result = new Dependency(BaseTest.getResourceAsFile(
|
||||||
|
context, resource));
|
||||||
|
analyzer.analyze(result, null);
|
||||||
|
assertTrue("Expected vendor evidence to contain \"example\".", result
|
||||||
|
.getVendorEvidence().toString().contains("example"));
|
||||||
|
for (final Evidence e : result.getVersionEvidence()) {
|
||||||
|
if ("0.0.1".equals(e.getValue())) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue("Version 0.0.1 not found in EggTest dependency.", found);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user