1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.jsieve.util;
20
21 import org.jmock.Mock;
22 import org.jmock.MockObjectTestCase;
23
24 public class SieveToXmlNullNameTest extends MockObjectTestCase {
25
26 SieveToXml subject;
27 Mock mockOut;
28 SieveHandler instance;
29
30 protected void setUp() throws Exception {
31 super.setUp();
32 subject = new SieveToXml();
33 subject.setNameAttributeName(null);
34 mockOut = mock(SieveToXml.Out.class);
35 instance = subject.build((SieveToXml.Out) mockOut.proxy());
36 }
37
38 protected void tearDown() throws Exception {
39 super.tearDown();
40 }
41
42 private void assertElementIsOutput(final String commandName, final String elementName) throws HaltTraversalException {
43 mockOut.expects(once()).method("openElement").with(eq(elementName),
44 eq(SieveToXml.DEFAULT_NAMESPACE), eq(SieveToXml.DEFAULT_PREFIX)).id("1");
45 mockOut.expects(once()).method("closeElement").after("1");
46 assertBuilderIsReturned(instance.startCommand(commandName));
47 assertBuilderIsReturned(instance.endCommand(commandName));
48 }
49
50 private void assertBuilderIsReturned(SieveHandler handler) {
51 assertEquals("Builder pattern so instance should be returned", instance, handler);
52 }
53
54 public void testBuildIsNotNull() {
55 assertNotNull(instance);
56 }
57
58 public void testControlCommandShouldOutputElement() throws Exception {
59 assertElementIsOutput("if", SieveToXml.DEFAULT_NAME_CONTROL_COMMAND);
60 }
61
62 public void testActionCommandShouldOutputElement() throws Exception {
63 assertElementIsOutput("other", SieveToXml.DEFAULT_NAME_ACTION_COMMAND);
64 }
65
66 public void testTestShouldOutputElement() throws Exception {
67 final String testName = "is";
68 mockOut.expects(once()).method("openElement").with(eq(SieveToXml.DEFAULT_NAME_TEST),
69 eq(SieveToXml.DEFAULT_NAMESPACE), eq(SieveToXml.DEFAULT_PREFIX)).id("1");
70 mockOut.expects(once()).method("closeElement").after("1");
71 assertBuilderIsReturned(instance.startTest(testName));
72 assertBuilderIsReturned(instance.endTest(testName));
73 }
74
75 }