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 java.awt.Dimension; |
19 | import java.io.File; |
20 | import java.util.Map; |
21 | |
22 | import junit.framework.TestCase; |
23 | |
24 | /** |
25 | * TestCase for CreateImageInfoMapTask. |
26 | * |
27 | * @author Thomas Aglassinger |
28 | */ |
29 | public class CreateImageInfoMapTaskTest extends TestCase |
30 | { |
31 | private ImageTools imageTools; |
32 | private TestTools testTools; |
33 | |
34 | protected void setUp() |
35 | throws Exception { |
36 | super.setUp(); |
37 | testTools = TestTools.instance(); |
38 | imageTools = ImageTools.instance(); |
39 | } |
40 | |
41 | public void testCreateImageInfoTaskFromBrokenImage() |
42 | throws Exception { |
43 | File notExistentImageFile = new File("notThere.png"); |
44 | |
45 | if (notExistentImageFile.exists()) { |
46 | throw new IllegalStateException("file must be removed in order for test to work: " + notExistentImageFile); |
47 | } |
48 | File[] imageFiles = new File[]{notExistentImageFile}; |
49 | CreateImagInfoMapTask createImageInfoMapTask = new CreateImagInfoMapTask(imageFiles); |
50 | |
51 | createImageInfoMapTask.start(); |
52 | |
53 | Map imageInfoMap = createImageInfoMapTask.getImageInfoMap(); |
54 | |
55 | assertNotNull(imageInfoMap); |
56 | assertEquals(imageFiles.length, imageInfoMap.size()); |
57 | |
58 | ImageInfo imageInfo = (ImageInfo) imageInfoMap.get(notExistentImageFile); |
59 | |
60 | assertNotNull(imageInfo); |
61 | assertTrue(imageInfo.hasError()); |
62 | assertNotNull(imageInfo.getError()); |
63 | } |
64 | |
65 | public void testCreateImageInfoTaskFromProperImages() |
66 | throws Exception { |
67 | File landscapeImage = testTools.getTestFile(TestTools.TEST_IMAGE_LANDSCAPE_NAME); |
68 | File portraitImage = testTools.getTestFile(TestTools.TEST_IMAGE_PORTRAIT_NAME); |
69 | File[] imageFiles = new File[]{landscapeImage, portraitImage}; |
70 | Dimension landscapeSize = imageTools.getImageDimension(landscapeImage); |
71 | Dimension portraitSize = imageTools.getImageDimension(portraitImage); |
72 | CreateImagInfoMapTask createImageInfoMapTask = new CreateImagInfoMapTask(imageFiles); |
73 | |
74 | createImageInfoMapTask.start(); |
75 | |
76 | Map imageInfoMap = createImageInfoMapTask.getImageInfoMap(); |
77 | |
78 | assertNotNull(imageInfoMap); |
79 | assertEquals(imageFiles.length, imageInfoMap.size()); |
80 | |
81 | ImageInfo landscapeInfo = (ImageInfo) imageInfoMap.get(landscapeImage); |
82 | ImageInfo portraitInfo = (ImageInfo) imageInfoMap.get(portraitImage); |
83 | |
84 | assertFalse(landscapeInfo.hasError()); |
85 | assertFalse(portraitInfo.hasError()); |
86 | testTools.assertEquals(landscapeSize, landscapeInfo.getSize()); |
87 | testTools.assertEquals(portraitSize, portraitInfo.getSize()); |
88 | } |
89 | |
90 | protected void tearDown() |
91 | throws Exception { |
92 | super.tearDown(); |
93 | } |
94 | } |