View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   */ 
19  package org.apache.rat.report.xml;
20  
21  import org.apache.rat.report.xml.writer.IXmlWriter;
22  
23  import java.io.IOException;
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  public class MockXmlWriter implements IXmlWriter {
28  
29      public final List<Object> calls = new ArrayList<Object>();
30      
31      public IXmlWriter attribute(CharSequence name, CharSequence value)
32              throws IOException {
33          calls.add(new Attribute(name, value));
34          return this;
35      }
36  
37      public IXmlWriter closeDocument() throws IOException {
38          calls.add(new CloseDocument());
39          return this;
40      }
41  
42      public IXmlWriter closeElement() throws IOException {
43          calls.add(new CloseElement());
44          return this;
45      }
46  
47      public IXmlWriter content(CharSequence content) throws IOException {
48          calls.add(new Content(content));
49          return this;
50      }
51  
52      public IXmlWriter openElement(CharSequence elementName) throws IOException {
53          calls.add(new OpenElement(elementName));
54          return this;
55      }
56  
57      public IXmlWriter startDocument() throws IOException {
58          calls.add(new StartDocument());
59          return this;
60      }
61      
62      public boolean isCloseElement(int index) {
63          boolean result = false;
64          final Object call = calls.get(index);
65          result = call instanceof CloseElement;
66          return result;
67      }
68      
69      public boolean isContent(String content, int index) {
70          boolean result = false;
71          final Object call = calls.get(index);
72          if (call instanceof Content) {
73              Content contentCall = (Content) call;
74              result = content.equals(contentCall.content);
75          }
76          return result;
77      }
78      
79      public boolean isOpenElement(String name, int index) {
80          boolean result = false;
81          final Object call = calls.get(index);
82          if (call instanceof OpenElement) {
83              OpenElement openElement = (OpenElement) call;
84              result = name.equals(openElement.elementName);
85          }
86          return result;
87      }
88  
89      public boolean isAttribute(String name, String value, int index) {
90          boolean result = false;
91          final Object call = calls.get(index);
92          if (call instanceof Attribute) {
93              Attribute attribute = (Attribute) call;
94              result = name.equals(attribute.name) && value.equals(attribute.value);
95          }
96          return result;
97      }
98      
99      public class StartDocument {}
100     public class CloseDocument {}
101     public class CloseElement {}
102     public class OpenElement {
103         public final CharSequence elementName;
104         private OpenElement(CharSequence elementName) {
105             this.elementName = elementName;
106         }
107     }
108     public class Content {
109         public final CharSequence content;
110         private Content(CharSequence content) {
111             this.content = content;
112         }
113     }
114     public class Attribute {
115         public final CharSequence name;
116         public final CharSequence value;
117         private Attribute(CharSequence name, CharSequence value) {
118             this.name = name;
119             this.value = value;
120         }
121     }
122 }