Java Reference
In-Depth Information
8.4.4
Test
To test the intermediate representation we have to check the correctness of
both the internal static representation and the serialized form. The simpli-
fied test class TestDOM performs these two checks for the specific case of the
page described in Figure 8.6. The test method testStaticStructure() checks if
the structure of the internal representation conforms to the structure pre-
sented in Figure 8.7. The test method testSerialize() checks if the result of the
serialization is as expected; it verifies the presence of given substrings in the
output (as done in Chapter 6 for the calculator).
public class TestDOM extends TestCase {
public void testStaticStructure() {
Page P # new Page();
Head T # new Head("Test");
Body B # new Body("white");
P.addChild(T);
P.addChild(B);
Heading H # new Heading();
Text T1 # new Text("This is a test");
H.addChild(T1);
B.addChild(H);
Text T2 # new Text("This is plain text");
B.addChild(T2);
Link L # new Link("http://www.w3.org");
Text T3 # new Text("Click here...");
L.addChild(T3);
B.addChild(L);
assertEquals(T,P.firstChild());
assertEquals(B,P.firstChild().nextSibling());
assertEquals(H,B.firstChild());
assertEquals(T1,H.firstChild());
}
public void testSerialize() {
Page P # new Page();
Head T # new Head("Test");
Body B # new Body("white");
P.addChild(T);
P.addChild(B);
Heading H # new Heading();
Text T1 # new Text("This is a test");
H.addChild(T1);
B.addChild(H);
Text T2 # new Text("This is plain text");
B.addChild(T2);
Link L # new Link("http://www.w3c.org");
Text T3 # new Text("Click here...");
 
Search WWH ::




Custom Search