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

COVERAGE SUMMARY FOR SOURCE FILE [ExtractZipTaskTest.java]

nameclass, %method, %block, %line, %
ExtractZipTaskTest.java100% (1/1)100% (5/5)67%  (136/203)74%  (29.6/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ExtractZipTaskTest100% (1/1)100% (5/5)67%  (136/203)74%  (29.6/40)
testExtractInternalError (): void 100% (1/1)21%  (16/76)30%  (4.2/14)
testExtract (): void 100% (1/1)92%  (80/87)96%  (14.4/15)
ExtractZipTaskTest (): void 100% (1/1)100% (3/3)100% (1/1)
setUp (): void 100% (1/1)100% (34/34)100% (8/8)
tearDown (): void 100% (1/1)100% (3/3)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.tools;
17 
18import java.io.File;
19import java.util.zip.ZipException;
20 
21import junit.framework.TestCase;
22import net.sf.wraplog.Logger;
23 
24/**
25 *  TestCase for ExtractZipTask.
26 *
27 * @author    Thomas Aglassinger
28 */
29public class ExtractZipTaskTest extends TestCase
30{
31    private FileTools fileTools;
32    private ImageTools imageTools;
33    private Logger logger;
34    private ProgressFrame progressFrame;
35    private TestTools testTools;
36 
37    protected void setUp()
38        throws Exception {
39        super.setUp();
40        testTools = TestTools.instance();
41        logger = Logger.getLogger(ExtractZipTaskTest.class);
42        fileTools = FileTools.instance();
43        imageTools = ImageTools.instance();
44        progressFrame = new ProgressFrame();
45        progressFrame.setTitle(getClass().getName());
46    }
47 
48    public void testExtract()
49        throws Exception {
50        String method = "testExtract";
51        File zipFile = testTools.getTestFile(TestTools.THREE_PAGE_COMIC);
52        File targetFolder = testTools.getCleanTestOutputFolder(getClass().getName() + "." + method);
53 
54        progressFrame.setVisible(true);
55        progressFrame.setNote(method);
56 
57        Task extractZipTask = new ExtractZipTask(zipFile, targetFolder);
58 
59        try {
60            extractZipTask.start();
61            assertTrue(targetFolder.exists());
62 
63            File[] imageFiles = fileTools.listFilesRecursively(targetFolder);
64 
65            assertEquals("number of files extracted to " + targetFolder, 3, imageFiles.length);
66            // Make sure the extracted images can be read.
67            for (int i = 0; i < imageFiles.length; i += 1) {
68                imageTools.readImage(imageFiles[i]);
69            }
70        } finally {
71            progressFrame.setVisible(false);
72        }
73    }
74 
75    public void testExtractInternalError()
76        throws Exception {
77        String method = "testExtractInternalError";
78        File zipFile = testTools.getTestFile(TestTools.TEST_COMIC_INTERNAL_ERROR);
79        File targetFolder = testTools.getCleanTestOutputFolder(getClass().getName() + "." + method);
80 
81        progressFrame.setVisible(true);
82        progressFrame.setNote(method);
83 
84        Task extractZipTask = new ExtractZipTask(zipFile, targetFolder);
85 
86        try {
87            extractZipTask.start();
88            fail("broken archive must cause error: " + zipFile);
89        } catch (ZipException error) {
90            if (logger.isDebugEnabled()) {
91                logger.debug("ignoring expected error", error);
92            }
93        } finally {
94            progressFrame.setVisible(false);
95        }
96    }
97 
98    protected void tearDown()
99        throws Exception {
100        super.tearDown();
101    }
102}

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