mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-23 09:31:32 +01:00
updated test case using an invalid mono path so that it does not run on Windows
Former-commit-id: 4a26ca21e64614bf74cb329d8d9b424442e7647c
This commit is contained in:
@@ -17,12 +17,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck.analyzer;
|
package org.owasp.dependencycheck.analyzer;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.codeaffine.junit.ignore.ConditionalIgnoreRule;
|
||||||
import static org.junit.Assert.assertTrue;
|
import com.codeaffine.junit.ignore.ConditionalIgnoreRule.ConditionalIgnore;
|
||||||
|
import com.codeaffine.junit.ignore.NotRunningOnWindows;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.owasp.dependencycheck.dependency.Confidence;
|
import org.owasp.dependencycheck.dependency.Confidence;
|
||||||
import org.owasp.dependencycheck.dependency.Dependency;
|
import org.owasp.dependencycheck.dependency.Dependency;
|
||||||
@@ -31,14 +35,17 @@ import org.owasp.dependencycheck.utils.Settings;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the AssemblyAnalyzer.
|
* Tests for the AssemblyAnalyzer.
|
||||||
|
*
|
||||||
* @author colezlaw
|
* @author colezlaw
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AssemblyAnalyzerTest {
|
public class AssemblyAnalyzerTest {
|
||||||
|
|
||||||
AssemblyAnalyzer analyzer;
|
AssemblyAnalyzer analyzer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the analyzer.
|
* Sets up the analyzer.
|
||||||
|
*
|
||||||
* @throws Exception if anything goes sideways
|
* @throws Exception if anything goes sideways
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
@@ -73,7 +80,7 @@ public class AssemblyAnalyzerTest {
|
|||||||
assertTrue(d.getProductEvidence().getEvidence().contains(new Evidence("grokassembly", "product", "log4net", Confidence.HIGH)));
|
assertTrue(d.getProductEvidence().getEvidence().contains(new Evidence("grokassembly", "product", "log4net", Confidence.HIGH)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=AnalysisException.class)
|
@Test(expected = AnalysisException.class)
|
||||||
public void testNonexistent() throws Exception {
|
public void testNonexistent() throws Exception {
|
||||||
File f = new File(AssemblyAnalyzerTest.class.getClassLoader().getResource("log4net.dll").getPath());
|
File f = new File(AssemblyAnalyzerTest.class.getClassLoader().getResource("log4net.dll").getPath());
|
||||||
File test = new File(f.getParent(), "nonexistent.dll");
|
File test = new File(f.getParent(), "nonexistent.dll");
|
||||||
@@ -81,7 +88,11 @@ public class AssemblyAnalyzerTest {
|
|||||||
analyzer.analyze(d, null);
|
analyzer.analyze(d, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=AnalysisException.class)
|
@Rule
|
||||||
|
public ConditionalIgnoreRule rule = new ConditionalIgnoreRule();
|
||||||
|
|
||||||
|
@Test()
|
||||||
|
@ConditionalIgnore(condition = NotRunningOnWindows.class)
|
||||||
public void testWithSettingMono() throws Exception {
|
public void testWithSettingMono() throws Exception {
|
||||||
String oldValue = Settings.getString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH);
|
String oldValue = Settings.getString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH);
|
||||||
// if oldValue is null, that means that neither the system property nor the setting has
|
// if oldValue is null, that means that neither the system property nor the setting has
|
||||||
@@ -94,10 +105,14 @@ public class AssemblyAnalyzerTest {
|
|||||||
Settings.setString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, "/yooser/bine/mono");
|
Settings.setString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, "/yooser/bine/mono");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//** @Test(expected = AnalysisException) doesn't seem to work with the conditional test **//
|
||||||
|
AnalysisException aex = null;
|
||||||
try {
|
try {
|
||||||
// Have to make a NEW analyzer because during setUp, it would have gotten the correct one
|
// Have to make a NEW analyzer because during setUp, it would have gotten the correct one
|
||||||
AssemblyAnalyzer aanalyzer = new AssemblyAnalyzer();
|
AssemblyAnalyzer aanalyzer = new AssemblyAnalyzer();
|
||||||
aanalyzer.initialize();
|
aanalyzer.initialize();
|
||||||
|
} catch (AnalysisException ex) {
|
||||||
|
aex = ex;
|
||||||
} finally {
|
} finally {
|
||||||
// Now recover the way we came in. If we had to set a System property, delete it. Otherwise,
|
// Now recover the way we came in. If we had to set a System property, delete it. Otherwise,
|
||||||
// reset the old value
|
// reset the old value
|
||||||
@@ -107,6 +122,7 @@ public class AssemblyAnalyzerTest {
|
|||||||
Settings.setString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, oldValue);
|
Settings.setString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, oldValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assertNull("Excpted exception: org.owasp.dependencycheck.analyzer.AnalysisException", aex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|||||||
Reference in New Issue
Block a user