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

File EscapingError.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

6
38
6
1
146
67
13
0.34
6.33
6
2.17

Classes

Class Line # Actions
EscapingError 33 38 0% 13 50
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.test.escaping.framework;
21   
22    import java.util.List;
23   
24    import org.xwiki.validator.ValidationError;
25   
26   
27    /**
28    * Error thrown in various escaping tests. Can handle a list of validation errors.
29    *
30    * @version $Id: 509216031dddde6dad9c3c5a3389342df98957f5 $
31    * @since 2.5M1
32    */
 
33    public class EscapingError extends AssertionError
34    {
35    /** Serial version ID. */
36    private static final long serialVersionUID = 7784831403359592333L;
37   
38    /**
39    * Create new EscapingError.
40    *
41    * @param message error message
42    */
 
43  0 toggle public EscapingError(String message)
44    {
45  0 super(message);
46    }
47   
48    /**
49    * Create new EscapingError.
50    *
51    * @param cause error cause
52    */
 
53  0 toggle public EscapingError(Throwable cause)
54    {
55  0 super(cause);
56    }
57   
58    /**
59    * Create new EscapingError listing a list of validation errors.
60    *
61    * @param message error message
62    * @param fileName file name that was tested
63    * @param url URL to reproduce
64    * @param errors list of validation errors
65    */
 
66  0 toggle public EscapingError(String message, String fileName, String url, List<ValidationError> errors)
67    {
68  0 super(formatMessage(message, fileName, url, errors));
69    }
70   
71    /**
72    * Create new EscapingError listing a list of escaping errors.
73    *
74    * @param message error message
75    * @param errors list of escaping errors
76    */
 
77  0 toggle public EscapingError(String message, List<EscapingError> errors)
78    {
79  0 super(formatMessageList(message, errors));
80    }
81   
82    /**
83    * Compose a nice error message from the given list of validation errors.
84    *
85    * @param message error description
86    * @param fileName file name that was tested
87    * @param url URL to reproduce
88    * @param errors list of validation errors
89    * @return formatted message
90    */
 
91  0 toggle public static final String formatMessage(String message, String fileName, String url, List<ValidationError> errors)
92    {
93  0 StringBuilder result = new StringBuilder(message == null ? "" : message);
94  0 result.append("\n Tested file: ").append(fileName);
95  0 result.append("\n URL: ").append(url);
96   
97  0 if (errors == null || errors.size() == 0) {
98  0 result.append('\n');
99  0 return result.toString();
100    }
101  0 StringBuilder fatalBuilder = new StringBuilder();
102  0 StringBuilder errorBuilder = new StringBuilder();
103  0 StringBuilder warningBuilder = new StringBuilder();
104  0 final String format = "\n line %4d column %3d %s";
105  0 for (ValidationError error : errors) {
106  0 String str = String.format(format, error.getLine(), error.getColumn(), error.toString());
107  0 switch (error.getType()) {
108  0 case FATAL:
109  0 fatalBuilder.append(str);
110  0 break;
111  0 case ERROR:
112  0 errorBuilder.append(str);
113  0 break;
114  0 case WARNING:
115  0 warningBuilder.append(str);
116  0 break;
117  0 default:
118  0 throw new RuntimeException("Should not happen: Error type = " + error.getType());
119    }
120    }
121  0 result.append("\n List of validation errors:");
122  0 result.append(fatalBuilder);
123  0 result.append(errorBuilder);
124  0 result.append(warningBuilder);
125  0 result.append('\n');
126  0 return result.toString();
127    }
128   
129    /**
130    * Compose a nice error message from the given list of escaping errors. Each escaping error might
131    * contain a list of validation errors.
132    *
133    * @param message error description
134    * @param errors list of escaping errors
135    * @return formatted message
136    */
 
137  0 toggle public static String formatMessageList(String message, List<EscapingError> errors)
138    {
139  0 StringBuilder result = new StringBuilder(message == null ? "" : message + "\n");
140  0 for (EscapingError error : errors) {
141  0 result.append(error.getMessage());
142    }
143  0 return result.toString();
144    }
145    }
146