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:
Jeremy Long
2014-02-01 08:49:00 -05:00
parent 73903cbd1f
commit 20d1abd2e1

View File

@@ -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
@@ -46,7 +53,7 @@ public class AssemblyAnalyzerTest {
analyzer = new AssemblyAnalyzer(); analyzer = new AssemblyAnalyzer();
analyzer.initialize(); analyzer.initialize();
} }
/** /**
* Tests to make sure the name is correct. * Tests to make sure the name is correct.
*/ */
@@ -54,7 +61,7 @@ public class AssemblyAnalyzerTest {
public void testGetName() { public void testGetName() {
assertEquals("Assembly Analyzer", analyzer.getName()); assertEquals("Assembly Analyzer", analyzer.getName());
} }
@Test @Test
public void testAnalysis() throws Exception { public void testAnalysis() throws Exception {
File f = new File(AssemblyAnalyzerTest.class.getClassLoader().getResource("GrokAssembly.exe").getPath()); File f = new File(AssemblyAnalyzerTest.class.getClassLoader().getResource("GrokAssembly.exe").getPath());
@@ -62,7 +69,7 @@ public class AssemblyAnalyzerTest {
analyzer.analyze(d, null); analyzer.analyze(d, null);
assertTrue(d.getVersionEvidence().getEvidence().contains(new Evidence("grokassembly", "version", "1.0.5140.29700", Confidence.HIGHEST))); assertTrue(d.getVersionEvidence().getEvidence().contains(new Evidence("grokassembly", "version", "1.0.5140.29700", Confidence.HIGHEST)));
} }
@Test @Test
public void testLog4Net() throws Exception { public void testLog4Net() throws Exception {
File f = new File(AssemblyAnalyzerTest.class.getClassLoader().getResource("log4net.dll").getPath()); File f = new File(AssemblyAnalyzerTest.class.getClassLoader().getResource("log4net.dll").getPath());
@@ -72,16 +79,20 @@ public class AssemblyAnalyzerTest {
assertTrue(d.getVendorEvidence().getEvidence().contains(new Evidence("grokassembly", "vendor", "The Apache Software Foundation", Confidence.HIGH))); assertTrue(d.getVendorEvidence().getEvidence().contains(new Evidence("grokassembly", "vendor", "The Apache Software Foundation", Confidence.HIGH)));
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");
Dependency d = new Dependency(test); Dependency d = new Dependency(test);
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
@@ -93,11 +104,15 @@ public class AssemblyAnalyzerTest {
} else { } else {
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,8 +122,9 @@ 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
public void tearDown() throws Exception { public void tearDown() throws Exception {
analyzer.close(); analyzer.close();