| 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.common; |
| 17 | |
| 18 | import java.io.ByteArrayOutputStream; |
| 19 | import java.io.IOException; |
| 20 | import java.io.PrintStream; |
| 21 | import java.util.Calendar; |
| 22 | import java.util.GregorianCalendar; |
| 23 | |
| 24 | import net.sf.jomic.tools.TestTools; |
| 25 | |
| 26 | import com.martiansoftware.jsap.JSAPResult; |
| 27 | |
| 28 | import junit.framework.TestCase; |
| 29 | |
| 30 | /** |
| 31 | * @author Thomas Aglassinger |
| 32 | */ |
| 33 | public class JomicJSAPTest extends TestCase |
| 34 | { |
| 35 | |
| 36 | private JomicJSAP jsap; |
| 37 | private TestTools testTools; |
| 38 | |
| 39 | /* |
| 40 | * @see TestCase#setUp() |
| 41 | */ |
| 42 | protected void setUp() |
| 43 | throws Exception { |
| 44 | super.setUp(); |
| 45 | testTools = TestTools.instance(); |
| 46 | jsap = new JomicJSAP(); |
| 47 | } |
| 48 | |
| 49 | public void testErrorMutexOptions() { |
| 50 | JSAPResult options = jsap.parse("--help test.cbz"); |
| 51 | |
| 52 | assertFalse(options.success()); |
| 53 | } |
| 54 | |
| 55 | public void testNoOptions() { |
| 56 | JSAPResult options = jsap.parse(""); |
| 57 | |
| 58 | assertTrue(options.success()); |
| 59 | options = jsap.parse(new String[]{}); |
| 60 | assertTrue(options.success()); |
| 61 | } |
| 62 | |
| 63 | public void testOpenFile() { |
| 64 | JSAPResult options = jsap.parse(testTools.getTestComicFile().getAbsolutePath()); |
| 65 | |
| 66 | assertTrue(options.success()); |
| 67 | } |
| 68 | |
| 69 | public void testPrintHelp() { |
| 70 | jsap.printHelp(System.out); |
| 71 | } |
| 72 | |
| 73 | public void testPrintLicense() |
| 74 | throws IOException { |
| 75 | ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); |
| 76 | |
| 77 | try { |
| 78 | PrintStream printStream = new PrintStream(byteStream); |
| 79 | |
| 80 | try { |
| 81 | jsap.printLicense(printStream); |
| 82 | |
| 83 | String licenseText = byteStream.toString(); |
| 84 | int currentYear = new GregorianCalendar().get(Calendar.YEAR); |
| 85 | int currentYearIndexInLicense = licenseText.indexOf(Integer.toString(currentYear)); |
| 86 | |
| 87 | assertTrue("license must contain current year: " + currentYear, currentYearIndexInLicense >= 0); |
| 88 | } finally { |
| 89 | printStream.close(); |
| 90 | } |
| 91 | } finally { |
| 92 | byteStream.close(); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | public void testPrintVersion() { |
| 97 | jsap.printVersion(System.out); |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * @see TestCase#tearDown() |
| 102 | */ |
| 103 | protected void tearDown() |
| 104 | throws Exception { |
| 105 | jsap = null; |
| 106 | testTools = null; |
| 107 | super.tearDown(); |
| 108 | } |
| 109 | |
| 110 | } |