NIHVIVO-1229 Create the RevisionInfoBean, with setup listener and unit tests.
This commit is contained in:
parent
bc86f50c5b
commit
b438f7d36d
6 changed files with 860 additions and 11 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
package stubs.javax.servlet;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
@ -19,7 +20,6 @@ import javax.servlet.ServletException;
|
|||
/**
|
||||
* A simple stand-in for the {@link ServletContext}, for use in unit tests.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ServletContextStub implements ServletContext {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -27,6 +27,18 @@ public class ServletContextStub implements ServletContext {
|
|||
// ----------------------------------------------------------------------
|
||||
|
||||
private final Map<String, Object> attributes = new HashMap<String, Object>();
|
||||
private final Map<String, String> mockResources = new HashMap<String, String>();
|
||||
|
||||
public void setMockResource(String path, String contents) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("path may not be null.");
|
||||
}
|
||||
if (contents == null) {
|
||||
mockResources.remove(path);
|
||||
} else {
|
||||
mockResources.put(path, contents);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
|
@ -56,6 +68,15 @@ public class ServletContextStub implements ServletContext {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String path) {
|
||||
if (mockResources.containsKey(path)) {
|
||||
return new ByteArrayInputStream(mockResources.get(path).getBytes());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -79,7 +100,7 @@ public class ServletContextStub implements ServletContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getInitParameterNames() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getInitParameterNames() not implemented.");
|
||||
|
@ -128,13 +149,7 @@ public class ServletContextStub implements ServletContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getResourceAsStream() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Set getResourcePaths(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getResourcePaths() not implemented.");
|
||||
|
@ -159,14 +174,14 @@ public class ServletContextStub implements ServletContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getServletNames() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServletNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getServlets() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServlets() not implemented.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue