View Javadoc

1   /*
2    * Zemucan: A Syntax Assistant for DB2
3    * Copyright (C) 2009, 2010 Andres Gomez Casanova
4    *
5    * This file is part of Zemucan.
6    *
7    * Zemucan is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as published by
9    * the Free Software Foundation; either version 3 of the License, or
10   * (at your option) any later version.
11   *
12   * Zemucan is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public License
18   * along with this library; if not, see <http://www.gnu.org/licenses/>.
19   *
20   * Contact:
21   * a n g o c a  at  y a h o o  dot  c o m
22   * Cra. 45 No 61 - 31, Bogota, Colombia.
23   *
24   * Author:   $LastChangedBy: angoca $:
25   * Date:     $LastChangedDate: 2011-03-06 10:15:32 -0500 (dom, 06 mar 2011) $:
26   * Revision: $LastChangedRevision: 1913 $:
27   * URL:      $HeadURL: https://zemucan.svn.sourceforge.net/svnroot/zemucan/branches/zemucan_v1/source-code/main/src/test/java/name/angoca/zemucan/main/MainTest.java $:
28   */
29  package name.angoca.zemucan.main;
30  
31  import name.angoca.zemucan.AbstractZemucanException;
32  import name.angoca.zemucan.tools.configurator.Configurator;
33  import name.angoca.zemucan.tools.test.RandomTestRunner;
34  import name.angoca.zemucan.ui.api.AbstractInterfaceController;
35  import name.angoca.zemucan.ui.api.InputReaderException;
36  import name.angoca.zemucan.ui.impl.jline.ImplementationJlineInterfaceController;
37  import name.angoca.zemucan.ui.impl.system.ImplementationSystemInterfaceController;
38  
39  import org.junit.Assert;
40  import org.junit.Test;
41  import org.junit.runner.RunWith;
42  
43  /**
44   * This executes the main in other way.
45   * <p>
46   * <b>Control Version</b>
47   * <p>
48   * <ul>
49   * <li>0.0.1 Class creation.</li>
50   * <li>0.0.2 final.</li>
51   * <li>1.0.0 Moved to version 1.</li>
52   * <li>1.0.1 Types for implementations.</li>
53   * <li>1.1.0 Tests other methods.</li>
54   * </ul>
55   *
56   * @author Andres Gomez Casanova <a
57   *         href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
58   * @version 1.1.0 2009-11-22
59   */
60  @RunWith(RandomTestRunner.class)
61  public final class MainTest {
62  
63      /**
64       * Tests that a controller cannot be null.
65       *
66       * @throws InputReaderException
67       *             Never.
68       */
69      @Test(expected = AssertionError.class)
70      public void testControllerNull() throws InputReaderException {
71          Main.getInterfaceControllerType(null);
72      }
73  
74      /**
75       * Tests that a element of controller cannot be null.
76       *
77       * @throws InputReaderException
78       *             Never.
79       */
80      @Test(expected = AssertionError.class)
81      public void testControllerNull1() throws InputReaderException {
82          final String[] args = new String[] { null };
83          Main.getInterfaceControllerType(args);
84      }
85  
86      /**
87       * Tests that the controller is System.
88       */
89      @Test
90      public void testGetControllerDefault() {
91          final String[] args = new String[] {};
92          final int actual = Main.getInterfaceControllerType(args);
93          final int expected = Main.ID_JLINE;
94          Assert.assertEquals("Interface controller type", expected, //$NON-NLS-1$
95                  actual);
96      }
97  
98      /**
99       * Tests that the controller is System.
100      */
101     @Test
102     public void testGetControllerJline() {
103         final String[] args = new String[] { Main.VALUE_JLINE };
104         final int actual = Main.getInterfaceControllerType(args);
105         final int expected = Main.ID_JLINE;
106         Assert.assertEquals("Interface controller type", expected, //$NON-NLS-1$
107                 actual);
108     }
109 
110     /**
111      * Tests that the controller is Other.
112      */
113     @Test
114     public void testGetControllerOther() {
115         final String[] args = new String[] { "Other" }; //$NON-NLS-1$
116         final int actual = Main.getInterfaceControllerType(args);
117         final int expected = Main.ID_JLINE;
118         Assert.assertEquals("Interface controller type", expected, //$NON-NLS-1$
119                 actual);
120     }
121 
122     /**
123      * Tests that the controller is System.
124      */
125     @Test
126     public void testGetControllerSystem() {
127         final String[] args = new String[] { Main.VALUE_SYSTEM };
128         final int actual = Main.getInterfaceControllerType(args);
129         final int expected = Main.ID_SYSTEM;
130         Assert.assertEquals("Interface controller type", expected, //$NON-NLS-1$
131                 actual);
132     }
133 
134     /**
135      * Test for coverage, just default.
136      *
137      * @throws AbstractZemucanException
138      */
139     @Test
140     public void testMainParamEmpty() throws AbstractZemucanException {
141     }
142 
143     /**
144      * Tests for coverage, just to evaluate the -h parameter value.
145      *
146      * @throws AbstractZemucanException
147      */
148     @Test
149     public void testMainParamH() throws AbstractZemucanException {
150         final String[] args = new String[] { "-h" };
151         new Main(args);
152     }
153 
154     /**
155      * Tests for coverage, just to evaluate the --help parameter value.
156      *
157      * @throws AbstractZemucanException
158      */
159     @Test
160     public void testMainParamHelp() throws AbstractZemucanException {
161         final String[] args = new String[] { "--help" };
162         new Main(args);
163     }
164 
165     /**
166      * Tests for coverage, just to evaluate the VALUE_SYSTEM parameter value.
167      *
168      * @throws AbstractZemucanException
169      */
170     @Test
171     public void testMainParamJline() throws AbstractZemucanException {
172     }
173 
174     /**
175      * Test for coverage, array null.
176      *
177      * @throws AbstractZemucanException
178      */
179     @Test(expected = AssertionError.class)
180     public void testMainParamNull1() throws AbstractZemucanException {
181         new Main(null);
182     }
183 
184     /**
185      * Test for coverage, null in array.
186      *
187      * @throws AbstractZemucanException
188      */
189     @Test(expected = AssertionError.class)
190     public void testMainParamNull2() throws AbstractZemucanException {
191         final String[] args = new String[] { null };
192         new Main(args);
193     }
194 
195     /**
196      * Tests for coverage, just to evaluate the /h parameter value.
197      *
198      * @throws AbstractZemucanException
199      */
200     @Test
201     public void testMainParamSlashH() throws AbstractZemucanException {
202         final String[] args = new String[] { "/h" };
203         new Main(args);
204     }
205 
206     /**
207      * Tests for coverage, just to evaluate the VALUE_SYSTEM parameter value.
208      *
209      * @throws AbstractZemucanException
210      */
211     @Test
212     public void testMainParamSystem() throws AbstractZemucanException {
213     }
214 
215     /**
216      * Prepares the controller with Jline.
217      *
218      * @throws AbstractZemucanException
219      *             Never.
220      */
221     @Test
222     public void testPrepareJline() throws AbstractZemucanException {
223         final int type = Main.ID_JLINE;
224 
225         final AbstractInterfaceController controller = Main.prepare(type);
226         Assert.assertTrue("Interface jline", //$NON-NLS-1$
227                 controller instanceof ImplementationJlineInterfaceController);
228     }
229 
230     /**
231      * Tests that a there is not prompt property. Just for coverage.
232      *
233      * @throws InputReaderException
234      *             Never.
235      */
236     @Test
237     public void testPrepareNoPrompt() throws InputReaderException {
238         Configurator.getInstance().deleteProperty(Main.PROMPT_PROPERTY);
239         Main.prepare(Main.ID_SYSTEM);
240     }
241 
242     /**
243      * Tests that a type cannot be -1.
244      *
245      * @throws InputReaderException
246      *             Never.
247      */
248     @Test(expected = AssertionError.class)
249     public void testPrepareNull() throws InputReaderException {
250         Main.prepare(-1);
251     }
252 
253     /**
254      * Prepares the controller with System.
255      *
256      * @throws AbstractZemucanException
257      *             Never.
258      */
259     @Test
260     public void testPrepareSystem() throws AbstractZemucanException {
261         final int type = Main.ID_SYSTEM;
262 
263         final AbstractInterfaceController controller = Main.prepare(type);
264         Assert.assertTrue("Interface system", //$NON-NLS-1$
265                 controller instanceof ImplementationSystemInterfaceController);
266     }
267 }