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 09:19:05 -0500 (dom, 06 mar 2011) $:
26   * Revision: $LastChangedRevision: 1910 $:
27   * URL:      $HeadURL: https://zemucan.svn.sourceforge.net/svnroot/zemucan/branches/zemucan_v1/source-code/executerImpl/src/test/java/name/angoca/zemucan/tools/messages/executer/ExecuterMessagesTest.java $:
28   */
29  package name.angoca.zemucan.tools.messages.executer;
30  
31  import java.io.IOException;
32  
33  import name.angoca.zemucan.executer.api.ExecutingCommandException;
34  import name.angoca.zemucan.executer.impl.CommandNotFoundException;
35  import name.angoca.zemucan.tools.test.RandomTestRunner;
36  
37  import org.junit.Assert;
38  import org.junit.Test;
39  import org.junit.runner.RunWith;
40  
41  /**
42   * Set of test for the translation files for the executer part.
43   * <p>
44   * <b>Control Version</b>
45   * <p>
46   * <ul>
47   * <li>1.0.0 Class creation.</li>
48   * <li>1.1.0 More tests.</li>
49   * <li>1.1.1 Message.</li>
50   * <li>1.1.2 Test getters.</li>
51   * </ul>
52   *
53   * @author Andres Gomez Casanova <a
54   *         href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
55   * @version 1.1.2 2009-11-15
56   */
57  @RunWith(RandomTestRunner.class)
58  public class ExecuterMessagesTest {
59      /**
60       * Private constructor.
61       */
62      public ExecuterMessagesTest() {
63          // Nothing.
64      }
65  
66      /**
67       * Tests the message of the CommandNotFoundException.
68       */
69      @Test
70      public final void testCommandNotFoundException() {
71          final String expectedCommand = "db2 create database"; //$NON-NLS-1$
72          final CommandNotFoundException exception = new CommandNotFoundException(
73                  expectedCommand);
74  
75          final String actual = exception.getMessage();
76  
77          final String expected = "EXEC1 - Command not found: " + expectedCommand; //$NON-NLS-1$
78  
79          Assert.assertEquals("CommandNotFoundException", expected, actual); //$NON-NLS-1$
80  
81          final String actualCommand = exception.getCommand();
82  
83          Assert.assertEquals("CommandNotFoundException getCommand", //$NON-NLS-1$
84                  expectedCommand, actualCommand);
85      }
86  
87      /**
88       * Tests that the exception has to receive a not null parameter.
89       */
90      @Test(expected = AssertionError.class)
91      public final void testCommandNotFoundExceptionNull() {
92          new CommandNotFoundException(null);
93      }
94  
95      /**
96       * Tests the message of the ExecutingCommandException.
97       */
98      @Test
99      public final void testExecutingCommandException() {
100         final IOException io = new IOException();
101         final Exception exception = new ExecutingCommandException(io);
102 
103         final String actual = exception.getMessage();
104 
105         final String expected = "EXEC2 - There was a problem while executing the command."; //$NON-NLS-1$
106 
107         Assert.assertEquals("ExecutingCommandException", expected, actual); //$NON-NLS-1$
108     }
109 
110     /**
111      * Tests that the exception has to receive a not null parameter.
112      */
113     @Test(expected = AssertionError.class)
114     public final void testExecutingCommandExceptionNull() {
115         new ExecutingCommandException(null);
116     }
117 }