<?xml version="1.0"?> | |
<!-- | |
Copyright 2002,2004 The Apache Software Foundation. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
--> | |
<test:suite xmlns:j="jelly:core" | |
xmlns:test="jelly:junit"> | |
<test:case name="assertTests"> | |
<test:assert test="${2 == 2}">This should never fail</test:assert> | |
<j:catch var="ex"> | |
<test:assert test="${2 != 2}">This should always fail</test:assert> | |
</j:catch> | |
<test:assert test="${ex != null}">We should have created an exception</test:assert> | |
The exception was: ${ex.message} | |
</test:case> | |
<test:case name="failTests"> | |
<j:catch var="ex"> | |
<test:fail>This should always fail</test:fail> | |
</j:catch> | |
<test:assert test="${ex != null}">We should have created an exception</test:assert> | |
The exception was: ${ex.message} | |
<j:catch var="ex"> | |
<test:fail message="This should always fail"/> | |
</j:catch> | |
<test:assert test="${ex != null}">We should have created an exception</test:assert> | |
The exception was: ${ex.message} | |
</test:case> | |
<test:case name="assertEqualTests"> | |
<j:set var="foo" value="abc"/> | |
<test:assertEquals actual="${foo}" expected="abc">This should never fail</test:assertEquals> | |
<j:catch var="ex"> | |
<test:assertEquals actual="${foo}" expected="def">This should always fail</test:assertEquals> | |
</j:catch> | |
<test:assert test="${ex != null}">We should have created an exception</test:assert> | |
The exception was: ${ex.message} | |
</test:case> | |
<test:case name="assertThrowsTests"> | |
<!-- test using var attribute --> | |
<test:assertThrows var="ex"> | |
<test:fail message="This exeption should be exported"/> | |
</test:assertThrows> | |
<test:assert test="${ex != null}">No exception exported</test:assert> | |
<!-- test using superclass of expected throwable --> | |
<test:assertThrows expected="java.lang.Error"> | |
<test:fail message="This should always fail"/> | |
</test:assertThrows> | |
<!-- test using non exception class --> | |
<test:assertThrows expected="java.lang.Class"> | |
<test:fail message="This should always fail"/> | |
</test:assertThrows> | |
<!-- test using undefined class --> | |
<test:assertThrows expected="java.lang.ClassNotFoundException"> | |
<test:assertThrows expected="foo.bar.Baz"> | |
<test:fail message="This should always fail"/> | |
</test:assertThrows> | |
</test:assertThrows> | |
<!-- test using other exception class --> | |
<j:catch var="ex"> | |
<test:assertThrows expected="java.io.IOException"> | |
<test:fail message="This should always fail"/> | |
</test:assertThrows> | |
</j:catch> | |
<test:assert test="${ex != null}">We should have created an exception</test:assert> | |
<!-- test with no exception from body --> | |
<j:catch var="ex"> | |
<test:assertThrows> | |
</test:assertThrows> | |
</j:catch> | |
<test:assert test="${ex != null}">assertThrows should fail when nothing is thrown from within it</test:assert> | |
<test:assert test="${ex.message.endsWith('No exception was thrown.')}"/> | |
<test:assertEquals actual="${ex.elementName}" expected="test:assertThrows"/> | |
<test:assert test="${ex.fileName != null}">fileName not set</test:assert> | |
<test:assert test="${ex.lineNumber gt 0}">lineNumber not set</test:assert> | |
<test:assert test="${ex.columnNumber gt 0}">columnNumber not set</test:assert> | |
</test:case> | |
<!-- | |
#### uncomment when assertEquals supports type conversions | |
<test:case name="assertEqualsConversion"> | |
<test:assertEquals expected="${4}" actual="${2+2}"/> | |
</test:case> | |
--> | |
</test:suite> |