| Step 8a: Implement | previous contents next |
InvalidURLException ensures that maintenance
does not break the behaviour we expect from the class.
The remaining tests in this tutorial ensure that the URL
and Parser classes fulfill the customer requirements.
First we define the missing details for the URL class:
URL should have a constructor which
takes it's attributes as arguments.
toString() should format the attributes
of the URL into a well-formed string.
equals()
methods.
URL class for now. The other requirements will
now be written down as tests:
de.extremejava.url package
and right-click the URL class. Since we do not want to
go through the pattern dialog, just select 'Create test case' in the
XP submenu. You can also use the hotkey Ctrl-Shift-E.
URL class gets the stereotype <<tested>>.
unittests.de.extremejava.url by
opening the tree and double-clicking on the symbol
public void testEquals ()
{
assert (new URL ("1", "2", "3", "4", 1, "5", "6", "7").equals (
new URL ("1", "2", "3", "4", 1, "5", "6", "7")));
}
|
assert is a method inherited from
junit.framework.TestCase. If it's argument is not true,
it will throw an exception to show that the test failed. Every test
method should use a variant of assert to ensure a result. An alternative
is throwing an exception which will then be shown by the JUnit UIs.
null arguments test
public void testEqualsNull ()
{
assert (new URL (null, null, null, null, -1, null, null, null).equals (
new URL (null, null, null, null, -1, null, null, null)));
}
|
toString() method
public void testToStringNotNull ()
{
URL url = new URL ("http", "heilwagen", "mypwd", "www.extreme-java.de", 80,
"/links/links.html", "xp", "query=false");
assertEquals ("http://heilwagen:mypwd@www.extreme-java.de:80/"
+ "links/links.html#xp?query=false",
url.toString ());
}
|
equals()URL
class. Please add the following code to that class:
public URL (String aProtocol, String aUser, String aPassword, String aHost,
int aPort, String aPath, String aFragment, String aQuery)
{
protocol = aProtocol;
user = aUser;
password = aPassword;
host = aHost;
port = aPort;
path = aPath;
fragment = aFragment;
query = aQuery;
}
public String toString ()
{
return "";
}
public boolean equals (URL anURL)
{
return false;
}
|
| previous contents next |
© 2001 A. Heilwagen