1   /*
2    * db2sa: DB2 Syntax Assistant
3    * Copyright (C) Andres Gomez Casanova
4    *
5    * This file is part of db2sa.
6    *
7    * db2sa 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   * db2sa 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: 2009-07-26 04:10:26 +0200 (Sun, 26 Jul 2009) $:
26   * Revision: $LastChangedRevision: 459 $:
27   * URL:      $HeadURL: https://db2sa.svn.sourceforge.net/svnroot/db2sa/branches/db2sa_beta/source-code/src/test/java/name/angoca/db2sa/core/syntax/graph/EndingTokenTest.java $:
28   */
29  package name.angoca.db2sa.core.syntax.graph;
30  
31  import org.junit.Assert;
32  import org.junit.Test;
33  
34  /**
35   * These are the tests for the EndingToken class. TODO a.equals(b) ==
36   * b.equals(a))<br/>
37   * TODO token.equals(token) == true (simétrica x=x, reflexiva x=y&& y==x,
38   * transitiva x==y, y==z, x==z, consistente (varias veces)x==y, x==y, TODO
39   * x.hashcode() == x.hashcode(), produce el mismo resutlado con diferentes
40   * llamados. x.equals(null)==false <b>Control Version</b><br />
41   * <ul>
42   * <li>0.0.1 Class creation.</li>
43   * <li>0.0.2 Recommendations from PMD.</li>
44   * <li>0.0.3 Organized.</li>
45   * <li>0.1.0 jUnit 4 annotations.</li>
46   * <li>0.1.1 Messages for the tests.</li>
47   * <li>0.1.2 final.</li>
48   * <li>1.0.0 Moved to version 1.</li>
49   * </ul>
50   * 
51   * @author Andres Gomez Casanova <a
52   *         href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
53   * @version 1.0.0 2009-07-19
54   */
55  public final class EndingTokenTest {
56      /**
57       * Default constructor.
58       */
59      public EndingTokenTest() {
60          // Nothing.
61      }
62  
63      /**
64       * Test that the hash code is different to hashCode of StartingNode.
65       */
66      @Test
67      public final void testDifferentStartingNodeHashCode() {
68          final EndingToken actual = new EndingToken();
69          final StartingToken notExpected = new StartingToken();
70  
71          Assert.assertFalse(
72                  "EndingNode has a hashcode different to StartingNode", //$NON-NLS-1$
73                  notExpected.hashCode() == actual.hashCode());
74      }
75  
76      /**
77       * Test that the hash code is different to 1, 0 and -1.
78       */
79      @Test
80      public final void testDifferentZeroHashCode() {
81          final EndingToken actual = new EndingToken();
82  
83          Assert.assertTrue("HashCode different to 1", //$NON-NLS-1$
84                  1 != actual.hashCode());
85          Assert.assertTrue("HashCode different to 0", //$NON-NLS-1$
86                  0 != actual.hashCode());
87          Assert.assertTrue("HashCode different to -1", //$NON-NLS-1$
88                  -1 != actual.hashCode());
89      }
90  
91      /**
92       * Test the equals method with a graph token reserved.
93       */
94      @Test
95      public final void testEqualsTokenNotReserved() {
96          final String token = "EndingToken"; //$NON-NLS-1$
97  
98          final EndingToken actual = new EndingToken();
99          final GraphToken expected = new GraphToken(token, false);
100 
101         Assert.assertFalse(
102                 "Equals between EndingToken and a non reserved GraphToken", //$NON-NLS-1$
103                 actual.equals(expected));
104     }
105 
106     /**
107      * Test the equals method with a graph token reserved.
108      */
109     @Test
110     public final void testEqualsTokenReserved() {
111         final String token = "EndingToken"; //$NON-NLS-1$
112 
113         final EndingToken actual = new EndingToken();
114         final GraphToken expected = new GraphToken(token, true);
115 
116         Assert.assertFalse(
117                 "Equals between EndingToken and a reserved GraphToken", //$NON-NLS-1$
118                 actual.equals(expected));
119     }
120 
121     /**
122      * Test the equals method to a null.
123      */
124     @Test
125     public final void testNullEqualsObject() {
126         final EndingToken actual = new EndingToken();
127 
128         final EndingToken nullObject = null;
129 
130         final boolean condition = actual.equals(nullObject);
131 
132         Assert.assertFalse("Equals in EndingNode with null", condition); //$NON-NLS-1$
133     }
134 
135     /**
136      * Test the equals method to a different type of object.
137      */
138     @Test
139     public final void testOtherTypeEqualsObject() {
140         final EndingToken actual = new EndingToken();
141         final StartingToken other = new StartingToken();
142 
143         Assert.assertFalse("Equals between EndingToken and StartingNode", //$NON-NLS-1$
144                 actual.equals(other));
145     }
146 
147     /**
148      * Test the equals method to the same object.
149      */
150     @Test
151     public final void testSameEqualsObject() {
152         final EndingToken actual = new EndingToken();
153         final EndingToken expected = new EndingToken();
154 
155         Assert.assertTrue("Two EndingNode are equals", //$NON-NLS-1$
156                 actual.equals(expected));
157     }
158 
159     /**
160      * Test that the hash code is the same.
161      */
162     @Test
163     public final void testSameHashCode() {
164         final EndingToken actual = new EndingToken();
165         final EndingToken expected = new EndingToken();
166 
167         Assert.assertEquals(
168                 "Two endingNode have the prodcue the same hashcode.", //$NON-NLS-1$
169                 expected.hashCode(), actual.hashCode());
170     }
171 
172     /**
173      * Test the toString method.
174      */
175     @Test
176     public final void testToString() {
177         final EndingToken actual = new EndingToken();
178         final String expected = "{END NODE}"; //$NON-NLS-1$
179 
180         Assert.assertEquals("Description of an endingnode", expected, //$NON-NLS-1$
181                 actual.toString());
182     }
183 }