1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.annotation

File MockDocument.java

 

Coverage histogram

../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

8
14
7
1
116
48
13
0.93
2
7
1.86

Classes

Class Line # Actions
MockDocument 37 14 0% 13 11
0.6206896362.1%
 

Contributing tests

This file is covered by 173 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.annotation;
21   
22    import java.util.ArrayList;
23    import java.util.HashMap;
24    import java.util.List;
25    import java.util.Map;
26   
27    import org.xwiki.annotation.maintainer.AnnotationState;
28   
29    /**
30    * Stores data and provides functions for manipulating mock documents loaded from test files. Use the
31    * {@link TestDocumentFactory} to load such documents from files.
32    *
33    * @see TestDocumentFactory
34    * @version $Id: b2581d990c41929007ba58a3669bcbabdf073838 $
35    * @since 2.3M1
36    */
 
37    public class MockDocument
38    {
39    /**
40    * Properties map for this test document.
41    */
42    protected Map<String, Object> properties = new HashMap<String, Object>();
43   
44    /**
45    * Sets the properties of this document.
46    *
47    * @param key the key of the property
48    * @param value the value of the property to set
49    */
 
50  643 toggle public void set(String key, Object value)
51    {
52  643 properties.put(key, value);
53    }
54   
55    /**
56    * @return the rendered content of this document, corresponding to the source as returned by
57    * {@link #getTextSource()}
58    */
 
59  62 toggle public String getRenderedContent()
60    {
61    // if not otherwise specified, the source is also the rendered content
62  62 String renderedContent = (String) properties.get("rendered");
63  62 return renderedContent != null ? renderedContent : getSource();
64    }
65   
66    /**
67    * @return the annotated HTML of this document. Used for verification purposes.
68    */
 
69  62 toggle public String getAnnotatedContent()
70    {
71  62 String annotatedContent = (String) properties.get("annotated");
72  62 return annotatedContent != null ? annotatedContent : getRenderedContent();
73    }
74   
75    /**
76    * @return the list of annotations, as specified in the corpus file, which have the safe state. For the moment, the
77    * UPDATE too.
78    */
 
79  0 toggle public List<Annotation> getValidAnnotations()
80    {
81  0 List<Annotation> safe = new ArrayList<Annotation>();
82  0 for (Annotation ann : getAnnotations()) {
83  0 if (ann.getState() == AnnotationState.SAFE || ann.getState() == AnnotationState.UPDATED) {
84  0 safe.add(ann);
85    }
86    }
87  0 return safe;
88    }
89   
90    /**
91    * @return the annotations of this document, as specified in the corpus file. Note that no filtering on the state of
92    * the annotation is made.
93    */
 
94  486 toggle @SuppressWarnings("unchecked")
95    public List<Annotation> getAnnotations()
96    {
97  486 return (List<Annotation>) properties.get("annotations");
98    }
99   
100    /**
101    * @return the source of this document, corresponding to the {@link #getTextSource()} content.
102    */
 
103  222 toggle public String getSource()
104    {
105  222 return (String) properties.get("source");
106    }
107   
108    /**
109    * @return the syntax of this document's content
110    */
 
111  297 toggle public String getSyntax()
112    {
113  297 String sourceSyntax = (String) properties.get("sourceSyntax");
114  297 return sourceSyntax == null || sourceSyntax.length() == 0 ? "xwiki/2.0" : sourceSyntax;
115    }
116    }