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

COVERAGE SUMMARY FOR SOURCE FILE [NumberedNameTest.java]

nameclass, %method, %block, %line, %
NumberedNameTest.java100% (1/1)100% (12/12)84%  (271/321)89%  (53.4/60)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NumberedNameTest100% (1/1)100% (12/12)84%  (271/321)89%  (53.4/60)
testBrokenNumberedName (String): void 100% (1/1)33%  (9/27)57%  (4/7)
<static initializer> 100% (1/1)68%  (17/25)70%  (1.4/2)
testNumberedName (String, String, String, String, String): void 100% (1/1)70%  (46/66)77%  (8.5/11)
testUsesPotentiallyMoronicNumbering (String, boolean): void 100% (1/1)89%  (33/37)88%  (3.5/4)
NumberedNameTest (): void 100% (1/1)100% (3/3)100% (1/1)
setUp (): void 100% (1/1)100% (6/6)100% (3/3)
tearDown (): void 100% (1/1)100% (6/6)100% (3/3)
testApiDocumentationExamples (): void 100% (1/1)100% (22/22)100% (4/4)
testBrokenNumberedName (): void 100% (1/1)100% (7/7)100% (3/3)
testDoublePages (): void 100% (1/1)100% (43/43)100% (7/7)
testSplitComicImageName (): void 100% (1/1)100% (50/50)100% (8/8)
testUsesPotentiallyMoronicNumbering (): void 100% (1/1)100% (29/29)100% (8/8)

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 junit.framework.TestCase;
19import net.sf.wraplog.Logger;
20 
21/**
22 *  TestCase for NumberedName.
23 *
24 * @author    Thomas Aglassinger
25 */
26public class NumberedNameTest extends TestCase
27{
28    private static Logger logger = Logger.getLogger(NumberedNameTest.class);
29    private StringTools stringTools;
30 
31    protected void setUp()
32        throws Exception {
33        super.setUp();
34        stringTools = StringTools.instance();
35    }
36 
37    public void testApiDocumentationExamples() {
38        testNumberedName("images/hugo00title.png", "images/", "hugo00title", "", ".png");
39        testNumberedName("images/hugo12.png", "images/", "hugo", "12", ".png");
40        testNumberedName("images/hugo12-13.png", "images/", "hugo", "12-13", ".png");
41    }
42 
43    public void testBrokenNumberedName() {
44        testBrokenNumberedName("n");
45        testBrokenNumberedName("n/");
46    }
47 
48    public void testDoublePages() {
49        testNumberedName("p/n1-2.s", "p/", "n", "1-2", ".s");
50        testNumberedName("p/n1+2.s", "p/", "n", "1+2", ".s");
51        testNumberedName("p/n1_2.s", "p/", "n", "1_2", ".s");
52        testNumberedName("p/n2-1.s", "p/", "n", "2-1", ".s");
53 
54        testNumberedName("p/n1 2.s", "p/", "n1 ", "2", ".s");
55        testNumberedName("p/n4+2.s", "p/", "n4+", "2", ".s");
56    }
57 
58    public void testSplitComicImageName() {
59        // Abbreviations used here: p=path, n=name-prefix, s=suffix. Note that it is important to
60        // prefer single-letter test data because they make it easier to find off-by-one errors and
61        // ArrayIndexOutOfBoundsExceptions.
62        testNumberedName("p/n1.s", "p/", "n", "1", ".s");
63        testNumberedName("path/name0023.suffix", "path/", "name", "0023", ".suffix");
64        testNumberedName("p/r/s/t/n1.s", "p/r/s/t/", "n", "1", ".s");
65        testNumberedName("n1.s", "", "n", "1", ".s");
66        testNumberedName(".s", "", "", "", ".s");
67        testNumberedName("n.", "", "n", "", ".");
68        testNumberedName(".", "", "", "", ".");
69    }
70 
71    public void testUsesPotentiallyMoronicNumbering() {
72        testUsesPotentiallyMoronicNumbering("p/n1.s", false);
73        testUsesPotentiallyMoronicNumbering("p/n01.s", true);
74        testUsesPotentiallyMoronicNumbering("p/n0910.s", true);
75        testUsesPotentiallyMoronicNumbering("p/n0911.s", false);
76        testUsesPotentiallyMoronicNumbering("p/n09+10.s", false);
77        testUsesPotentiallyMoronicNumbering(".s", false);
78 
79        // Explaination: prefix="n9+", page="10"
80        testUsesPotentiallyMoronicNumbering("p/n9+10.s", true);
81    }
82 
83    protected void tearDown()
84        throws Exception {
85        stringTools = null;
86        super.tearDown();
87    }
88 
89    private void testBrokenNumberedName(String fileName) {
90        try {
91            new NumberedName(fileName);
92            fail("file name must result in IllegalArgumentException: "
93                    + stringTools.sourced(fileName));
94        } catch (IllegalArgumentException error) {
95            if (logger.isDebugEnabled()) {
96                logger.debug("ignoring expected exception", error);
97            }
98        }
99    }
100 
101    private void testNumberedName(
102            String source, String expectedPath, String expectedPrefix, String expectedPage, String expectedSuffix) {
103        assert source != null;
104        assert expectedPath != null;
105        assert expectedPrefix != null;
106        assert expectedPage != null;
107        assert expectedSuffix != null;
108        NumberedName actual = new NumberedName(source);
109 
110        assertEquals("path", expectedPath, actual.getPath());
111        assertEquals("prefix", expectedPrefix, actual.getPrefix());
112        assertEquals("page", expectedPage, actual.getPage());
113        assertEquals("suffix", expectedSuffix, actual.getSuffix());
114    }
115 
116    private void testUsesPotentiallyMoronicNumbering(String source, boolean expected) {
117        assert source != null;
118        NumberedName numberedName = new NumberedName(source);
119 
120        assertEquals("usesPotentiallyMoronicNumbering for " + stringTools.sourced(source)
121                + " yielding " + stringTools.sourced(numberedName.getPage()),
122                expected, numberedName.usesPotentiallyMoronicNumbering());
123    }
124}

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