Skip to content

Commit 0925b84

Browse files
[FAILING] Test stub for Java logging config
Explicitly failing test for verifying the intended behavior when the JavaLogFactory is attempting to load a file from configuration. Still need to work out some of the static mocks for forcing the underlying exception, as well as trying to capture the resulting output.
1 parent 5f89a16 commit 0925b84

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/test/java/org/owasp/esapi/logging/java/JavaLogFactoryTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414
*/
1515
package org.owasp.esapi.logging.java;
1616

17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertTrue;
19+
20+
import java.io.IOException;
21+
import java.io.OutputStream;
22+
import java.io.PrintStream;
1723
import java.util.List;
24+
import java.util.concurrent.atomic.AtomicReference;
1825

1926
import org.junit.Assert;
2027
import org.junit.Rule;
@@ -39,6 +46,28 @@ public class JavaLogFactoryTest {
3946
@Rule
4047
public TestName testName = new TestName();
4148

49+
@Test
50+
public void testIOExceptionOnMissingConfiguration() throws Exception {
51+
org.junit.Assert.fail("Unimplemented!");
52+
53+
IOException originException = new IOException(testName.getMethodName());
54+
final AtomicReference<IOException> stdErrOut = new AtomicReference<IOException>();
55+
56+
//FIXME Mock static so that java.util.logging.LogManager.readConfiguration(any(java.io.InputStream.class) throws IOException
57+
58+
59+
System.setErr(new PrintStream(new OutputStream() {
60+
public void write(int b) {
61+
//FIXME: How do I capture the object here?
62+
}
63+
}));
64+
65+
IOException actual = stdErrOut.get();
66+
assertTrue(actual != null);
67+
assertTrue(originException.equals(actual.getCause()));
68+
assertEquals("Failed to load esapi-java-logging.properties.", actual.getMessage());
69+
}
70+
4271
@Test
4372
public void testCreateLoggerByString() {
4473
Logger logger = new JavaLogFactory().getLogger("test");

0 commit comments

Comments
 (0)