updated test case using an invalid mono path so that it does not run on Windows

Former-commit-id: d6a822f2ce18d9f163839d5d1108cbac06a04516
This commit is contained in:
Jeremy Long
2014-02-01 08:49:00 -05:00
parent f1e1d67f4e
commit b4b53cfa4c

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
@@ -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