EMMA Coverage Report (generated Sun Apr 20 22:38:01 CEST 2008)
[all classes][net.sf.jomic.comic]

COVERAGE SUMMARY FOR SOURCE FILE [ComicModelTest.java]

nameclass, %method, %block, %line, %
ComicModelTest.java100% (1/1)100% (8/8)96%  (142/148)99%  (38.8/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ComicModelTest100% (1/1)100% (8/8)96%  (142/148)99%  (38.8/39)
setUp (): void 100% (1/1)88%  (38/43)98%  (7.8/8)
testGetContents (): void 100% (1/1)94%  (16/17)99%  (3.9/4)
ComicModelTest (): void 100% (1/1)100% (3/3)100% (1/1)
tearDown (): void 100% (1/1)100% (22/22)100% (7/7)
testCreate (): void 100% (1/1)100% (8/8)100% (2/2)
testReExtract (): void 100% (1/1)100% (47/47)100% (13/13)
testUnrar (): void 100% (1/1)100% (4/4)100% (2/2)
testUnzip (): void 100% (1/1)100% (4/4)100% (2/2)

1// Jomic - a viewer for comic book archives.
2// Copyright (C) 2004-2008 Thomas Aglassinger
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16package net.sf.jomic.comic;
17 
18import java.io.File;
19import java.io.IOException;
20 
21import net.sf.jomic.tools.FileTools;
22import net.sf.jomic.tools.TestTools;
23import net.sf.wraplog.Logger;
24 
25/**
26 *  TestCase for ComicModel.
27 *
28 * @author    Thomas Aglassinger
29 */
30public class ComicModelTest extends AbstractComicArchiveTest
31{
32    private File cacheDir;
33    private ComicCache comicCache;
34    private FileTools fileTools;
35    private Logger logger;
36 
37    protected void setUp()
38        throws Exception {
39        super.setUp();
40        logger = Logger.getLogger(ComicModelTest.class);
41        fileTools = FileTools.instance();
42        cacheDir = File.createTempFile(ComicModelTest.class.getName(), ".tmp");
43        fileTools.delete(cacheDir);
44        comicCache = ComicCache.instance();
45        comicCache.setUp(cacheDir);
46    }
47 
48    public final void testCreate()
49        throws Exception {
50        new ComicModel(getTestTools().getTestComicFile());
51    }
52 
53    public final void testGetContents()
54        throws Exception {
55        ComicModel model = new ComicModel(getTestTools().getTestComicFile());
56 
57        assertTrue(model.getImageCount() > 0);
58 
59        model.dispose();
60    }
61 
62    public final void testReExtract()
63        throws IOException, InterruptedException {
64        // Extract the test comic.
65        File testComicFile = getTestTools().getTestComicFile();
66        ComicModel comicModel = new ComicModel(testComicFile);
67        File archiveCacheDir = comicModel.getCacheDir();
68        File[] allImageFiles = fileTools.listFilesRecursively(archiveCacheDir);
69        File someFile = allImageFiles[allImageFiles.length / 2];
70 
71        // Close the comic but leave it in the cache.
72        comicModel.dispose();
73 
74        // Be nasty and invalidate the cache by removing an image from it.
75        assertTrue(someFile.exists());
76        fileTools.delete(someFile);
77        assertFalse(someFile.exists());
78 
79        // Re-open the comic.
80        ComicModel againComicModel = new ComicModel(testComicFile);
81 
82        // Ensure that the missing file was detected, and the comic re-extracted.
83        assertTrue(someFile.exists());
84 
85        againComicModel.dispose();
86    }
87 
88    public final void testUnrar()
89        throws Exception {
90        testExtract("test.cbr");
91    }
92 
93    public final void testUnzip()
94        throws Exception {
95        testExtract(TestTools.HUGO_COMIC);
96    }
97 
98    protected void tearDown()
99        throws Exception {
100        if (cacheDir != null) {
101            if (comicCache != null) {
102                comicCache.dispose();
103            }
104            fileTools.attemptToDeleteAll(cacheDir, logger);
105            fileTools = null;
106        }
107        super.tearDown();
108    }
109}

[all classes][net.sf.jomic.comic]
EMMA 2.0.4217 (C) Vladimir Roubtsov