mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-14 15:53:36 +01:00
Autocloseable
This commit is contained in:
@@ -55,7 +55,7 @@ import static org.owasp.dependencycheck.analyzer.AnalysisPhase.*;
|
||||
*
|
||||
* @author Jeremy Long
|
||||
*/
|
||||
public class Engine implements FileFilter {
|
||||
public class Engine implements FileFilter, AutoCloseable {
|
||||
|
||||
/**
|
||||
* {@link Engine} execution modes.
|
||||
@@ -193,6 +193,11 @@ public class Engine implements FileFilter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the analyzers specified in the configuration file (or system
|
||||
* properties).
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.owasp.dependencycheck;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -26,48 +25,45 @@ public class EngineModeTest extends BaseTest {
|
||||
public TemporaryFolder tempDir = new TemporaryFolder();
|
||||
@Rule
|
||||
public TestName testName = new TestName();
|
||||
private Engine engine;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Settings.setString(Settings.KEYS.DATA_DIRECTORY, tempDir.newFolder().getAbsolutePath());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
engine.cleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvidenceCollectionMode() throws Exception {
|
||||
engine = new Engine(Engine.Mode.EVIDENCE_COLLECTION);
|
||||
assertDatabase(false);
|
||||
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_COLLECTION.phases) {
|
||||
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
||||
}
|
||||
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_PROCESSING.phases) {
|
||||
assertThat(engine.getAnalyzers(phase), is(nullValue()));
|
||||
try (Engine engine = new Engine(Engine.Mode.EVIDENCE_COLLECTION)) {
|
||||
assertDatabase(false);
|
||||
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_COLLECTION.phases) {
|
||||
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
||||
}
|
||||
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_PROCESSING.phases) {
|
||||
assertThat(engine.getAnalyzers(phase), is(nullValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvidenceProcessingMode() throws Exception {
|
||||
engine = new Engine(Engine.Mode.EVIDENCE_PROCESSING);
|
||||
assertDatabase(true);
|
||||
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_PROCESSING.phases) {
|
||||
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
||||
}
|
||||
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_COLLECTION.phases) {
|
||||
assertThat(engine.getAnalyzers(phase), is(nullValue()));
|
||||
try (Engine engine = new Engine(Engine.Mode.EVIDENCE_PROCESSING)) {
|
||||
assertDatabase(true);
|
||||
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_PROCESSING.phases) {
|
||||
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
||||
}
|
||||
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_COLLECTION.phases) {
|
||||
assertThat(engine.getAnalyzers(phase), is(nullValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandaloneMode() throws Exception {
|
||||
engine = new Engine(Engine.Mode.STANDALONE);
|
||||
assertDatabase(true);
|
||||
for (AnalysisPhase phase : Engine.Mode.STANDALONE.phases) {
|
||||
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
||||
try (Engine engine = new Engine(Engine.Mode.STANDALONE)) {
|
||||
assertDatabase(true);
|
||||
for (AnalysisPhase phase : Engine.Mode.STANDALONE.phases) {
|
||||
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user