Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
73   166   13   5,62
0   105   0,18   13
13     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  FileMetaDataTest       Line # 43 73 0% 13 0 100% 1.0
 
  (26)
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble.domain;
33   
34    import junit.framework.TestCase;
35   
36    import java.util.Date;
37   
38    /**
39    * Tests for the FileMetaData class.
40    *
41    * @author Simon Brown
42    */
 
43    public class FileMetaDataTest extends TestCase {
44   
45    private FileMetaData file;
46   
 
47  2 toggle public void testConstructionOfRootFile() {
48  2 file = new FileMetaData(null, null);
49  2 assertEquals("/", file.getPath());
50  2 assertEquals("", file.getName());
51   
52  2 file = new FileMetaData(null, "");
53  2 assertEquals("/", file.getPath());
54  2 assertEquals("", file.getName());
55   
56  2 file = new FileMetaData(null, "/");
57  2 assertEquals("/", file.getPath());
58  2 assertEquals("", file.getName());
59    }
60   
 
61  2 toggle public void testConstructionOfDirectory() {
62  2 file = new FileMetaData(null, "/directory");
63  2 assertEquals("/", file.getPath());
64  2 assertEquals("directory", file.getName());
65   
66  2 file = new FileMetaData(null, "/directory/");
67  2 assertEquals("/", file.getPath());
68  2 assertEquals("directory", file.getName());
69    }
70   
 
71  2 toggle public void testConstructionOfSubDirectory() {
72  2 file = new FileMetaData(null, "/directory/subdirectory");
73  2 assertEquals("/directory", file.getPath());
74  2 assertEquals("subdirectory", file.getName());
75   
76  2 file = new FileMetaData(null, "/directory/subdirectory/");
77  2 assertEquals("/directory", file.getPath());
78  2 assertEquals("subdirectory", file.getName());
79    }
80   
 
81  2 toggle public void testDirectoriesAreNotEditable() {
82  2 file = new FileMetaData(null, "/directory");
83  2 assertFalse(file.isEditable());
84    }
85   
 
86  2 toggle public void testTextFilesAreEditable() {
87  2 file = new FileMetaData(null, "/somefile.txt");
88  2 assertTrue(file.isEditable());
89  2 file = new FileMetaData(null, "/somefile.jsp");
90  2 assertTrue(file.isEditable());
91  2 file = new FileMetaData(null, "/somefile.jspf");
92  2 assertTrue(file.isEditable());
93  2 file = new FileMetaData(null, "/somefile.html");
94  2 assertTrue(file.isEditable());
95  2 file = new FileMetaData(null, "/somefile.htm");
96  2 assertTrue(file.isEditable());
97  2 file = new FileMetaData(null, "/somefile.css");
98  2 assertTrue(file.isEditable());
99  2 file = new FileMetaData(null, "/somefile.xml");
100  2 assertTrue(file.isEditable());
101    }
102   
 
103  2 toggle public void testBinaryFilesAreNotEditable() {
104  2 file = new FileMetaData(null, "/somefile.gif");
105  2 assertFalse(file.isEditable());
106  2 file = new FileMetaData(null, "/somefile.jpg");
107  2 assertFalse(file.isEditable());
108  2 file = new FileMetaData(null, "/somefile.png");
109  2 assertFalse(file.isEditable());
110  2 file = new FileMetaData(null, "/somefile.zip");
111  2 assertFalse(file.isEditable());
112    }
113   
 
114  2 toggle public void testAllDirectoriesAreNotEditable() {
115  2 file = new FileMetaData(null, "/somedirectory");
116  2 file.setDirectory(true);
117  2 assertFalse(file.isEditable());
118    }
119   
 
120  2 toggle public void testName() {
121  2 file = new FileMetaData(null, "/");
122  2 file.setName("somename");
123  2 assertEquals("somename", file.getName());
124    }
125   
 
126  2 toggle public void testLastModifiedDate() {
127  2 Date date = new Date();
128  2 file = new FileMetaData(null, "/");
129  2 file.setLastModified(date);
130  2 assertEquals(date, file.getLastModified());
131    }
132   
 
133  2 toggle public void testDirectory() {
134  2 file = new FileMetaData(null, "/");
135  2 file.setDirectory(true);
136  2 assertTrue(file.isDirectory());
137   
138  2 file.setDirectory(false);
139  2 assertFalse(file.isDirectory());
140    }
141   
 
142  2 toggle public void testAbsolutePath() {
143  2 file = new FileMetaData(null, "/somedirectory/somefile.gif");
144  2 assertEquals("/somedirectory/somefile.gif", file.getAbsolutePath());
145    }
146   
 
147  2 toggle public void testUrl() {
148  2 file = new FileMetaData(null, "/somefile.txt");
149  2 file.setType(FileMetaData.BLOG_IMAGE);
150  2 assertEquals("images/somefile.txt", file.getUrl());
151   
152  2 file.setType(FileMetaData.BLOG_FILE);
153  2 assertEquals("files/somefile.txt", file.getUrl());
154   
155  2 file.setType(FileMetaData.THEME_FILE);
156  2 assertEquals("theme/somefile.txt", file.getUrl());
157    }
158   
 
159  2 toggle public void testSize() {
160  2 file = new FileMetaData(null, "/");
161  2 file.setSize(123456789);
162  2 assertEquals(123456789, file.getSize());
163  2 assertEquals(123456789/1024, file.getSizeInKB(), 1.0);
164    }
165   
166    }