1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 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/>. |
16 | package net.sf.jomic.tools; |
17 | |
18 | import junit.framework.TestCase; |
19 | |
20 | /** |
21 | * TestCase for NumeredNameComparator. |
22 | * |
23 | * @author Thomas Aglassinger |
24 | */ |
25 | public class NumberedNameComparatorTest extends TestCase |
26 | { |
27 | private StringTools stringTools; |
28 | |
29 | protected void setUp() |
30 | throws Exception { |
31 | super.setUp(); |
32 | stringTools = StringTools.instance(); |
33 | TestTools.instance(); |
34 | } |
35 | |
36 | public void testComparator() { |
37 | testComparator("p/n1.s", "p/n1.s", 0, 0); |
38 | testComparator("p/n1.s", "p/n2.s", -1, -1); |
39 | testComparator("p/n2.s", "p/n1.s", 1, 1); |
40 | } |
41 | |
42 | protected void tearDown() |
43 | throws Exception { |
44 | stringTools = null; |
45 | super.tearDown(); |
46 | } |
47 | |
48 | private void testComparator(String some, String other, boolean demoronized, int expected) { |
49 | NumberedName someName = new NumberedName(some); |
50 | NumberedName otherName = new NumberedName(other); |
51 | NumberedNameComparator comparator = new NumberedNameComparator(demoronized); |
52 | int actual = comparator.compare(someName, otherName); |
53 | |
54 | assertEquals("some=" + stringTools.sourced(some) + ", other=" + stringTools.sourced(other), |
55 | expected, actual); |
56 | } |
57 | |
58 | private void testComparator(String some, String other, int expectedNonDemoronized, int expectedDemoronized) { |
59 | testComparator(some, other, false, expectedNonDemoronized); |
60 | testComparator(some, other, false, expectedDemoronized); |
61 | } |
62 | } |