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

File FileAssert.java

 

Coverage histogram

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

Code metrics

2
19
5
1
95
48
6
0.32
3.8
5
1.2

Classes

Class Line # Actions
FileAssert 36 19 0% 6 26
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.filter.test.internal;
21   
22    import java.io.File;
23    import java.io.IOException;
24    import java.util.HashMap;
25    import java.util.Map;
26   
27    import org.apache.commons.io.FileUtils;
28    import org.apache.commons.io.FilenameUtils;
29   
30    /**
31    * Files related test tools.
32    *
33    * @version $Id: 2347ede772ccd799a938e066976211d6c96cea72 $
34    * @since 6.2M1
35    */
 
36    public final class FileAssert
37    {
38    private final static Map<String, FileAssertComparator> COMPARATORS = new HashMap<String, FileAssertComparator>();
39   
40    private final static DefaultFileAssertComparator DEFAULT_COMPARATOR = new DefaultFileAssertComparator();
41   
 
42  0 toggle static {
43  0 StringFileAssertComparator stringFileAssertComparator = new StringFileAssertComparator();
44   
45  0 COMPARATORS.put("txt", stringFileAssertComparator);
46  0 COMPARATORS.put("xml", stringFileAssertComparator);
47  0 COMPARATORS.put("properties", stringFileAssertComparator);
48   
49  0 ZIPFileAssertComparator zipFileAssertComparator = new ZIPFileAssertComparator();
50   
51  0 COMPARATORS.put("xar", zipFileAssertComparator);
52  0 COMPARATORS.put("jar", zipFileAssertComparator);
53  0 COMPARATORS.put("zip", zipFileAssertComparator);
54    }
55   
 
56  0 toggle private FileAssert()
57    {
58    }
59   
 
60  0 toggle public static FileAssertComparator getComparator(String filename)
61    {
62  0 String extension = FilenameUtils.getExtension(filename);
63   
64  0 FileAssertComparator comparator = COMPARATORS.get(extension);
65  0 if (comparator == null) {
66  0 comparator = DEFAULT_COMPARATOR;
67    }
68   
69  0 return comparator;
70    }
71   
72    /**
73    * Asserts that two files are equal. If they are not, an {@link AssertionError} without a message is thrown.
74    */
 
75  0 toggle public static void assertEquals(File expected, byte[] actual) throws IOException
76    {
77  0 File actualFile = File.createTempFile(expected.getName(), ".actual");
78   
79  0 try {
80  0 FileUtils.writeByteArrayToFile(actualFile, actual);
81   
82  0 assertEquals(expected, actualFile);
83    } finally {
84  0 actualFile.delete();
85    }
86    }
87   
88    /**
89    * Asserts that two ZIP files are equal. If they are not, an {@link AssertionError} without a message is thrown.
90    */
 
91  0 toggle public static void assertEquals(File expected, File actual) throws IOException
92    {
93  0 getComparator(expected.getName()).assertEquals(null, expected, actual);
94    }
95    }