1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.report.xml;
20
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.rat.report.xml.writer.IXmlWriter;
26
27 public class MockXmlWriter implements IXmlWriter {
28
29 public final List calls;
30
31 public MockXmlWriter() {
32 calls = new ArrayList();
33 }
34
35 public IXmlWriter attribute(CharSequence name, CharSequence value)
36 throws IOException {
37 calls.add(new Attribute(name, value));
38 return this;
39 }
40
41 public IXmlWriter closeDocument() throws IOException {
42 calls.add(new CloseDocument());
43 return this;
44 }
45
46 public IXmlWriter closeElement() throws IOException {
47 calls.add(new CloseElement());
48 return this;
49 }
50
51 public IXmlWriter content(CharSequence content) throws IOException {
52 calls.add(new Content(content));
53 return this;
54 }
55
56 public IXmlWriter openElement(CharSequence elementName) throws IOException {
57 calls.add(new OpenElement(elementName));
58 return this;
59 }
60
61 public IXmlWriter startDocument() throws IOException {
62 calls.add(new StartDocument());
63 return this;
64 }
65
66 public boolean isCloseElement(int index) {
67 boolean result = false;
68 final Object call = calls.get(index);
69 result = call instanceof CloseElement;
70 return result;
71 }
72
73 public boolean isContent(String content, int index) {
74 boolean result = false;
75 final Object call = calls.get(index);
76 if (call instanceof Content) {
77 Content contentCall = (Content) call;
78 result = content.equals(contentCall.content);
79 }
80 return result;
81 }
82
83 public boolean isOpenElement(String name, int index) {
84 boolean result = false;
85 final Object call = calls.get(index);
86 if (call instanceof OpenElement) {
87 OpenElement openElement = (OpenElement) call;
88 result = name.equals(openElement.elementName);
89 }
90 return result;
91 }
92
93 public boolean isAttribute(String name, String value, int index) {
94 boolean result = false;
95 final Object call = calls.get(index);
96 if (call instanceof Attribute) {
97 Attribute attribute = (Attribute) call;
98 result = name.equals(attribute.name) && value.equals(attribute.value);
99 }
100 return result;
101 }
102
103 public class StartDocument {}
104 public class CloseDocument {}
105 public class CloseElement {}
106 public class OpenElement {
107 public final CharSequence elementName;
108 private OpenElement(CharSequence elementName) {
109 this.elementName = elementName;
110 }
111 }
112 public class Content {
113 public final CharSequence content;
114 private Content(CharSequence content) {
115 this.content = content;
116 }
117 }
118 public class Attribute {
119 public final CharSequence name;
120 public final CharSequence value;
121 private Attribute(CharSequence name, CharSequence value) {
122 this.name = name;
123 this.value = value;
124 }
125 }
126 }