[ejuf-cvs] ejuf/src/xdocs/htdocs/assertions-impl/convert-existing-ext index.xml,NONE,1.1
Brought to you by:
fbos
|
From: <fb...@us...> - 2002-11-29 19:19:22
|
Update of /cvsroot/ejuf/ejuf/src/xdocs/htdocs/assertions-impl/convert-existing-ext
In directory sc8-pr-cvs1:/tmp/cvs-serv14983/htdocs/assertions-impl/convert-existing-ext
Added Files:
index.xml
Log Message:
Updated information about JUnit and assertions class extension implementers
--- NEW FILE: index.xml ---
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE page PUBLIC "-//EJUF//Documentation DTD v1.0//EN"
"http://ejuf.sourceforge.net/dtd/page-1.0.dtd">
<page xmlns="http://ejuf.sourceforge.net/ejuf-1.0" depth="2">
<title>Converting existing JUnit extensions to EJUF extensions</title>
<body xmlns="http://www.w3.org/1999/xhtml">
<p>It really is quite easy to convert existing JUnit extensions.
Especially if they extend TestCase.
</p>
<p>The easiest way to do this is to create a new interface and class
paid which both extend some EJUF interfaces and classes.
</p>
<p>As an example, we will convert XMLUnit's XMLTestCase to an
XMLTestCaseWrapperAssertions in EJUF. If you cannnot wait and
must see the converted class, take a look at the
<code>ejuf.ext.assertions.XMLTestCaseWrapperAssertions</code> class.
</p>
<h2>Creating the interface to XMLTestCase</h2>
<p>
First off, we will start by creating the interface to the
XMLTestCase. Take a look at this:
</p>
<java xmlns="http://ejuf.sourceforge.net/ejuf-1.0">
package org.custommonkey.xmlunit.ext.ejuf;
public interface <link>ejuf/ext/assertions/XMLTestCaseWrapperAssertions</link> extends <link>ejuf/assertions/Assertions</link>, XSLTConstants {
void assertXMLEqual(String s, Diff diff, boolean b);
...
}
</java>
<p>
What we have done here is to declare an interface that users of
XMLUnit will need to implement. This is the same kind of interface
than EqualityAssertions or FailureAssertions that EJUF provides
by default.
</p>
<h2>Creating the interface implementation</h2>
<p>
Next, we have to create an implementation of this interface which
provides the services to the users. Ideally, we want to do the
minimum amount of work which will bring us to the desired point
of functionnality ( lazy users :) ). So, we declare the type:
</p>
<java xmlns="http://ejuf.sourceforge.net/ejuf-1.0">
package org.custommonkey.xmlunit.ext.ejuf;
public class XMLTestCaseAssertionsImpl extends <link>ejuf/assertions/AssertionServices</link>
implements XMLTestCaseAssertions {
private static final XMLTestCase xmlTestCase = new XMLTestCase("null");
public void assertXMLEqual(String s, Diff diff, boolean b) {
xmlTestCase.assertXMLEqual(s, diff, b);
}
...
}
</java>
<p>
Notice that we have reused the XMLTestCase as-is. No modifications
were necessary. We only added a layer of indirection so that users
may call into the test case abstractly from any test instance.
</p>
<h2>Update implementation to generate events about assertions</h2>
<p>
Finally, the last thing to do is to implement the assertion
notification function. The following is a first draft of such
functionnality:
</p>
<java xmlns="http://ejuf.sourceforge.net/ejuf-1.0">
package org.custommonkey.xmlunit.ext.ejuf;
public class XMLTestCaseAssertionsImpl extends <link>ejuf/assertions/AssertionServices</link>
implements XMLTestCaseAssertions {
private final <link>ejuf/assertions/AssertionsRegistry</link> registry;
...
public XMLTestCaseAssertionsImpl(final <link>ejuf/assertions/AssertionsRegistry</link> registry) {
this.registry = registry;
}
public void assertXMLEqual(String s, Diff diff, boolean b) {
xmlTestCase.assertXMLEqual(s, diff, b);
registry.assertion(new AssertionError("Comparing differences: "
+ diff.toString()));
}
...
}
</java>
<p>
As you may have noticed, the part about the registry was added in
the XMLTestCaseAssertionsImpl. This means that the same
XMLTestCase can be used <strong>both</strong> by JUnit and by EJUF
users... This is an extra bonus for extension developers.
</p>
</body>
<navigation>
<prev href="assertions-impl"/>
</navigation>
</page>
|