1 package org.apache.maven.doxia.module.twiki.parser;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Arrays;
23
24 import junit.framework.TestCase;
25
26
27
28
29
30
31
32
33 public class BlockTest
34 extends TestCase
35 {
36
37
38
39
40 public final void testTextBlockEquals()
41 {
42 testEquals( new TextBlock( "bar" ), new TextBlock( "bar" ), new TextBlock( "foo" ) );
43 }
44
45
46
47
48 public final void testWikiWordBlockEquals()
49 {
50 final WikiWordLinkResolver resolver = new XHTMLWikiWordLinkResolver();
51 testEquals( new WikiWordBlock( "bar", resolver ), new WikiWordBlock( "bar", resolver ),
52 new WikiWordBlock( "foo", resolver ) );
53
54 testEquals( new WikiWordBlock( "bar", new TextBlock( "text" ), resolver ),
55 new WikiWordBlock( "bar", new TextBlock( "text" ), resolver ), new WikiWordBlock( "bar",
56 resolver ) );
57
58 testEquals( new WikiWordBlock( "bar", new TextBlock( "text" ), resolver ),
59 new WikiWordBlock( "bar", new TextBlock( "text" ), resolver ),
60 new WikiWordBlock( "text", new TextBlock( "bar" ), resolver ) );
61
62 }
63
64
65
66
67 public final void testLinkBlockEquals()
68 {
69 testEquals( new LinkBlock( "foo", new TextBlock( "bar" ) ),
70 new LinkBlock( "foo", new TextBlock( "bar" ) ), new LinkBlock( "bar", new TextBlock( "foo" ) ) );
71 }
72
73
74
75
76 public final void testListBlockEquals()
77 {
78 final Block[] blocks = new Block[] { new TextBlock( "hello" ) };
79
80 testEquals( new ListItemBlock( blocks ), new ListItemBlock( blocks ), new ListItemBlock( new Block[] {} ) );
81 }
82
83
84
85
86 public final void testNestedBlockEquals()
87 {
88
89 testEquals( new ParagraphBlock( new Block[] { new BoldBlock( new Block[] { new TextBlock( "foo" ) } ) } ),
90 new ParagraphBlock( new Block[] { new BoldBlock( new Block[] { new TextBlock( "foo" ) } ) } ),
91 new ParagraphBlock( new Block[] { new BoldBlock( new Block[] { new TextBlock( "bar" ) } ) } ) );
92 }
93
94
95
96
97 public final void testAbstractFatherBlockEquals()
98 {
99 assertFalse( Arrays
100 .equals(
101 new Block[] {
102 new TextBlock( "mary " ),
103 new ItalicBlock(
104 new Block[] { new MonospaceBlock(
105 new Block[] { new TextBlock(
106 "has" ) } ) } ) },
107 new Block[] {
108 new TextBlock( "mary " ),
109 new BoldBlock(
110 new Block[] { new MonospaceBlock(
111 new Block[] { new TextBlock(
112 "has" ) } ) } ) } ) );
113 }
114
115
116
117
118 public final void testAnchorBlockEquals()
119 {
120 testEquals( new AnchorBlock( "anchor" ), new AnchorBlock( "anchor" ), new AnchorBlock( "anch" ) );
121 }
122
123
124
125
126 public final void testHorizontalEquals()
127 {
128 testEquals( new HorizontalRuleBlock(), new HorizontalRuleBlock(), "foo" );
129 }
130
131
132
133
134
135
136 public final void testEquals( final Object a, final Object b, final Object c )
137 {
138 assertFalse( a.equals( null ) );
139 assertFalse( b.equals( null ) );
140 assertFalse( c.equals( null ) );
141
142 assertNotSame( a, b );
143
144 assertEquals( a, a );
145 assertEquals( b, b );
146 assertEquals( c, c );
147
148 assertEquals( a, b );
149 assertEquals( b, a );
150 assertFalse( a.equals( c ) );
151
152 assertEquals( a.hashCode(), b.hashCode() );
153 }
154 }