|
From: <fb...@us...> - 2003-06-29 04:02:21
|
Update of /cvsroot/jgb/jgb/src/java/tests/jgb/builder
In directory sc8-pr-cvs1:/tmp/cvs-serv4135/src/java/tests/jgb/builder
Modified Files:
TestDefaultBuilder.java
Log Message:
* src/java/tests/jgb/builder/TestDefaultBuilder.java:
Added and modified tests to assert behavior of error handling
methods in DefaultBuilder.
* src/java/core/jgb/builder/DefaultBuilder.java:
Implemented tests.
Index: TestDefaultBuilder.java
===================================================================
RCS file: /cvsroot/jgb/jgb/src/java/tests/jgb/builder/TestDefaultBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TestDefaultBuilder.java 27 Jun 2003 16:45:49 -0000 1.2
--- TestDefaultBuilder.java 29 Jun 2003 04:02:19 -0000 1.3
***************
*** 23,33 ****
import org.xml.sax.SAXException;
! public class TestDefaultBuilder extends AbstractBuilderTest{
public TestDefaultBuilder(String s) {
super(s);
}
! public void testErrorStopsParsingImmediately() {
! SAXParseException parseException = new SAXParseException("", "", "", 0, 0);
try {
--- 23,47 ----
import org.xml.sax.SAXException;
! import java.io.StringWriter;
! import java.io.PrintWriter;
!
! public class TestDefaultBuilder extends AbstractBuilderTest {
! private StringWriter loggingStream = new StringWriter();
! private PrintWriter out = new PrintWriter(loggingStream);
!
public TestDefaultBuilder(String s) {
super(s);
}
! protected void setUp() throws Exception {
! super.setUp();
!
! builder.setLoggingStream(out);
! }
!
! public void testUnQuietErrorHandlingStopsBuildImmediatelyAndLogsException() {
! builder.setQuiet(false);
! SAXParseException parseException = new SAXParseException(
! "cause of exception", "PubId", "SysId", 241, 144);
try {
***************
*** 38,45 ****
parseException, possibleSuccess.getException());
}
}
! public void testFatalErrorStopsParsingImmediately() {
! SAXParseException parseException = new SAXParseException("", "", "", 0, 0);
try {
--- 52,103 ----
parseException, possibleSuccess.getException());
}
+
+ out.flush();
+ out.close();
+
+ String exceptionMessage = loggingStream.toString();
+
+ assertTrue("logs to passed stream",
+ 0 < exceptionMessage.length());
+ assertTrue("starts with ERROR:",
+ exceptionMessage.startsWith("ERROR:"));
+ assertTrue("writes exception message to log stream",
+ -1 != exceptionMessage.indexOf("cause of exception"));
+ assertTrue("write line number to log stream",
+ -1 != exceptionMessage.indexOf("line: 241"));
+ assertTrue("writes column number to log stream",
+ -1 != exceptionMessage.indexOf("column: 144"));
+ assertTrue("write Public ID to log stream",
+ -1 != exceptionMessage.indexOf("\"PubId\""));
+ assertTrue("writes System ID to log stream",
+ -1 != exceptionMessage.indexOf("\"SysId\""));
}
! public void testQuietErrorHandlingStopsBuildImmediatelyAndDoesNotLogException() {
! builder.setQuiet(true);
! SAXParseException parseException = new SAXParseException(
! "cause of exception", "PubId", "SysId", 128, 14);
!
! try {
! ((DefaultBuilder)builder).error(parseException);
! fail("Did not stop build by throwing new exception !");
! } catch (SAXException possibleSuccess) {
! assertSame("cause of exception must be set",
! parseException, possibleSuccess.getException());
! }
!
! out.flush();
! out.close();
!
! String exceptionMessage = loggingStream.toString();
!
! assertEquals("did not log anything: '" + exceptionMessage + "'",
! 0, exceptionMessage.length());
! }
!
! public void testUnQuietFatalErrorHandlingStopsBuildImmediatelyAndLogsException() {
! builder.setQuiet(false);
! SAXParseException parseException = new SAXParseException(
! "cause of exception", "PubId", "SysId", 33, 14);
try {
***************
*** 47,62 ****
fail("Did not stop build by throwing new exception !");
} catch (SAXException possibleSuccess) {
! assertSame("cause of exception must be set", parseException, possibleSuccess.getException());
}
}
! public void testWarningDoesNotStopsParsing() {
! SAXParseException parseException = new SAXParseException("", "", "", 0, 0);
try {
((DefaultBuilder)builder).warning(parseException);
pass();
! } catch (SAXException e) {
! fail("Parsing was stopped !");
}
}
--- 105,207 ----
fail("Did not stop build by throwing new exception !");
} catch (SAXException possibleSuccess) {
! assertSame("cause of exception must be set",
! parseException, possibleSuccess.getException());
}
+
+ out.flush();
+ out.close();
+
+ String exceptionMessage = loggingStream.toString();
+
+ assertTrue("logs to passed stream",
+ 0 < exceptionMessage.length());
+ assertTrue("starts with FATAL:",
+ exceptionMessage.startsWith("FATAL:"));
+ assertTrue("writes exception message to log stream",
+ -1 != exceptionMessage.indexOf("cause of exception"));
+ assertTrue("write line number to log stream",
+ -1 != exceptionMessage.indexOf("line: 33"));
+ assertTrue("writes column number to log stream",
+ -1 != exceptionMessage.indexOf("column: 14"));
+ assertTrue("write Public ID to log stream",
+ -1 != exceptionMessage.indexOf("\"PubId\""));
+ assertTrue("writes System ID to log stream",
+ -1 != exceptionMessage.indexOf("\"SysId\""));
}
! public void testQuietFatalErrorHandlingStopsBuildImmediatelyAndDoesNotLogException() {
! builder.setQuiet(true);
! SAXParseException parseException = new SAXParseException(
! "cause of exception", "PubId", "SysId", 32, 13);
!
! try {
! ((DefaultBuilder)builder).fatalError(parseException);
! fail("Did not stop build by throwing new exception !");
! } catch (SAXException possibleSuccess) {
! assertSame("cause of exception must be set",
! parseException, possibleSuccess.getException());
! }
!
! out.flush();
! out.close();
!
! String exceptionMessage = loggingStream.toString();
!
! assertEquals("did not log anything: '" + exceptionMessage + "'",
! 0, exceptionMessage.length());
! }
!
! public void testUnQuietWarningHandlingDoesNotStopBuildAndLogsException() {
! builder.setQuiet(false);
! SAXParseException parseException = new SAXParseException(
! "cause of exception", "PubId", "SysId", 47, 12);
!
try {
((DefaultBuilder)builder).warning(parseException);
pass();
! } catch (SAXException possibleSuccess) {
! fail("Threw an Exception when not required to");
}
+
+ out.flush();
+ out.close();
+
+ String exceptionMessage = loggingStream.toString();
+
+ assertTrue("logs to passed stream",
+ 0 < exceptionMessage.length());
+ assertTrue("starts with WARNING:",
+ exceptionMessage.startsWith("WARNING:"));
+ assertTrue("writes exception message to log stream",
+ -1 != exceptionMessage.indexOf("cause of exception"));
+ assertTrue("write line number to log stream",
+ -1 != exceptionMessage.indexOf("line: 47"));
+ assertTrue("writes column number to log stream",
+ -1 != exceptionMessage.indexOf("column: 12"));
+ assertTrue("write Public ID to log stream",
+ -1 != exceptionMessage.indexOf("\"PubId\""));
+ assertTrue("writes System ID to log stream",
+ -1 != exceptionMessage.indexOf("\"SysId\""));
+ }
+
+ public void testQuietWarningHandlingDoesNotStopBuildImmediatelyAndDoesNotLogException() {
+ builder.setQuiet(true);
+ SAXParseException parseException = new SAXParseException(
+ "cause of exception", "PubId", "SysId", 31, 57);
+
+ try {
+ ((DefaultBuilder)builder).warning(parseException);
+ pass();
+ } catch (SAXException possibleSuccess) {
+ fail("Threw an Exception when not required to");
+ }
+
+ out.flush();
+ out.close();
+
+ String exceptionMessage = loggingStream.toString();
+
+ assertEquals("did not log anything: '" + exceptionMessage + "'",
+ 0, exceptionMessage.length());
}
|