Project Report: fawkez

Packagesummary org.jcoderz.commons.types

org.jcoderz.commons.types.StrongTypesTest

LineHitsNoteSource
1  /*
2   * $Id: StrongTypesTest.java 1547 2009-08-03 20:42:16Z amandel $
3   *
4   * Copyright 2008, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.types;
34  
35  import junit.framework.TestCase;
36  
37  import org.jcoderz.commons.ArgumentMaxLengthViolationException;
38  import org.jcoderz.commons.ArgumentMaxValueViolationException;
39  import org.jcoderz.commons.ArgumentMinLengthViolationException;
40  import org.jcoderz.commons.ArgumentMinValueViolationException;
41  import org.jcoderz.commons.config.ConfigurationKey;
42  import org.jcoderz.commons.test.RestrictedLong;
43  
44  /**
45   * Test the generated Strong Types.
46   * @author Andreas Mandel
47   */
48100 public class StrongTypesTest
49      extends TestCase
50  {
51      private static final int LONG_STRING_LENGTH = 2048;
52      private static final String LONG_STRING;
53  
54      static
55      {
56100         final StringBuffer sb = new StringBuffer();
57100         for (int i = 0; i < LONG_STRING_LENGTH; i++)
58          {
59100            sb.append(' ');
60          }
61100         LONG_STRING = sb.toString();
62100     }
63  
64      /**
65       * Testing the max length restriction in generated String types.
66       */
67      public void testToLong ()
68      {
69          try
70          {
710(1)            final ConfigurationKey key
72                  = ConfigurationKey.fromString(LONG_STRING.substring(0,
73                      ConfigurationKey.MAX_LENGTH + 1));
740(2)            fail("Expected exception!");
75          }
76100         catch (ArgumentMaxLengthViolationException ex)
77          {
78              // expected;
790         }
80100     }
81  
82      /**
83       * Testing the min length restriction in generated String types.
84       */
85      public void testToShort ()
86      {
87          try
88          {
890(3)            final ConfigurationKey key
90                  = ConfigurationKey.fromString("");
910             fail("Expected exception!");
92          }
93100         catch (ArgumentMinLengthViolationException ex)
94          {
95              // expected;
960         }
97100     }
98  
99      /**
100       * Testing the max value restriction in generated Long types.
101       */
102      public void testToHigh ()
103      {
104          try
105          {
1060(4)            final RestrictedLong lg
107                  = RestrictedLong.fromLong(RestrictedLong.MAX_VALUE + 1);
1080             fail("Expected exception!");
109          }
110100         catch (ArgumentMaxValueViolationException ex)
111          {
112              // expected;
1130         }
114100     }
115  
116      /**
117       * Testing the min value restriction in generated Long types.
118       */
119      public void testToLow ()
120      {
121          try
122          {
1230(5)            final RestrictedLong lg
124                  = RestrictedLong.fromLong(RestrictedLong.MIN_VALUE - 1);
1250             fail("Expected exception!");
126          }
127100         catch (ArgumentMinValueViolationException ex)
128          {
129              // expected;
1300         }
131100     }
132  
133      /**
134       * Test method for comparison.
135       */
136      public void testComparison ()
137      {
138100         assertEquals("Comparing equal values", 0,
139              RestrictedLong.fromString("15")
140              .compareTo(RestrictedLong.fromString("15")));
14175         assertTrue("Comparing different values",
142              RestrictedLong.fromString("15")
143                  .compareTo(RestrictedLong.fromString("21")) < 0);
14475         assertTrue("Comparing different values",
145              RestrictedLong.fromString("21")
146                  .compareTo(RestrictedLong.fromString("15")) > 0);
147100     }
148  
149      /** Test for enumeration implements tag. */
150      public void testImplementsTaggedColor ()
151      {
15271         assertTrue("TaggedColor should implement Tagger interface",
153              TestTaggerInterface.class.isAssignableFrom(TaggedColor.class));
154100     }
155      
156      /** Test for restricted string implements tag. */
157      public void testImplementsTaggedFooString ()
158      {
15971         assertTrue("TaggedFooString should implement Tagger interface",
160              TestTaggerInterface.class.isAssignableFrom(TaggedFooString.class));
161100     }
162  
163      /** Test for value objects implements tag. */
164      public void testImplementsTaggedValueObject ()
165      {
16671         assertTrue(
167              "TaggedSampleValueObject should implement Tagger interface",
168              TestTaggerInterface.class.isAssignableFrom(
169                  TaggedSampleValueObject.class));
17071         assertTrue(
171              "TaggedPlainSampleValueObject should implement Tagger interface",
172              TestTaggerInterface.class.isAssignableFrom(
173                  TaggedPlainSampleValueObject.class));
17471         assertTrue(
175 (6)            "TaggedSerializableSampleValueObject " +
176              "should implement Tagger interface",
177              TestTaggerInterface.class.isAssignableFrom(
178                  TaggedSerializableSampleValueObject.class));
179100     }
180  }

Findings in this File

i (1) 71 : 0 Dead store to key in org.jcoderz.commons.types.StrongTypesTest.testToLong() (test code)
i (2) 74 : 18 The String literal "Expected exception!" appears 4 times in this file; the first occurrence is on line 74 (test code)
i (3) 89 : 0 Dead store to key in org.jcoderz.commons.types.StrongTypesTest.testToShort() (test code)
i (4) 106 : 0 Dead store to lg in org.jcoderz.commons.types.StrongTypesTest.testToHigh() (test code)
i (5) 123 : 0 Dead store to lg in org.jcoderz.commons.types.StrongTypesTest.testToLow() (test code)
c (6) 175 : 52 '+' should be on a new line.