mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-14 15:53:36 +01:00
Improved extensibility by using ServiceLoader
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.codesecure.dependencycheck.scanner;
|
||||
|
||||
import java.util.Set;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jeremy Long (jeremy.long@gmail.com)
|
||||
*/
|
||||
public class AbstractAnalyzerTest {
|
||||
|
||||
public AbstractAnalyzerTest() {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of newHashSet method, of class AbstractAnalyzer.
|
||||
*/
|
||||
@Test
|
||||
public void testNewHashSet() {
|
||||
System.out.println("newHashSet");
|
||||
Set result = AbstractAnalyzer.newHashSet("one","two");
|
||||
assertEquals(2, result.size());
|
||||
assertTrue(result.contains("one"));
|
||||
assertTrue(result.contains("two"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.codesecure.dependencycheck.scanner;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Iterator;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jeremy Long (jeremy.long@gmail.com)
|
||||
*/
|
||||
public class AnalyzerServiceTest {
|
||||
|
||||
public AnalyzerServiceTest() {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getAnalyzers method, of class AnalyzerService.
|
||||
*/
|
||||
@Test
|
||||
public void testGetAnalyzers() {
|
||||
System.out.println("getAnalyzers");
|
||||
AnalyzerService instance = AnalyzerService.getInstance();
|
||||
Iterator<Analyzer> result = instance.getAnalyzers();
|
||||
|
||||
boolean found = false;
|
||||
while (result.hasNext()) {
|
||||
Analyzer a = result.next();
|
||||
Set<String> e = a.getSupportedExtensions();
|
||||
if (e.contains("jar")) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
assertTrue("JarAnalyzer loaded", found);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@
|
||||
*/
|
||||
package org.codesecure.dependencycheck.scanner;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
@@ -52,4 +54,42 @@ public class JarAnalyzerTest {
|
||||
assertTrue(result.getVendorEvidence().toString().toLowerCase().contains("apache"));
|
||||
assertTrue(result.getVendorEvidence().getWeighting().contains("apache"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getSupportedExtensions method, of class JarAnalyzer.
|
||||
*/
|
||||
@Test
|
||||
public void testGetSupportedExtensions() {
|
||||
System.out.println("getSupportedExtensions");
|
||||
JarAnalyzer instance = new JarAnalyzer();
|
||||
Set expResult = new HashSet();
|
||||
expResult.add("jar");
|
||||
Set result = instance.getSupportedExtensions();
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getName method, of class JarAnalyzer.
|
||||
*/
|
||||
@Test
|
||||
public void testGetName() {
|
||||
System.out.println("getName");
|
||||
JarAnalyzer instance = new JarAnalyzer();
|
||||
String expResult = "Jar Analyzer";
|
||||
String result = instance.getName();
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of supportsExtension method, of class JarAnalyzer.
|
||||
*/
|
||||
@Test
|
||||
public void testSupportsExtension() {
|
||||
System.out.println("supportsExtension");
|
||||
String extension = "jar";
|
||||
JarAnalyzer instance = new JarAnalyzer();
|
||||
boolean expResult = true;
|
||||
boolean result = instance.supportsExtension(extension);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user