Autocloseable

This commit is contained in:
Mark Rekveld
2017-07-10 16:58:08 +02:00
parent 1fe24a2e0c
commit e6ec9d9aa3
2 changed files with 27 additions and 26 deletions

View File

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

View File

@@ -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()));
}
}
}