Project Report: fawkez

Packagesummary org.jcoderz.commons.connector

org.jcoderz.commons.connector.UserPasswordTest

LineHitsNoteSource
1  /*
2   * $Id: UserPasswordTest.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, 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.connector;
34  
35  import junit.framework.TestCase;
36  
37  /**
38   * Tests the class {@link org.jcoderz.commons.connector.UserPassword}.
39   *
40   */
41100(1)public class UserPasswordTest
42        extends TestCase
43  {
44     private static final String USER = "anton";
45     private static final String PWD = "tirol";
46     private UserPassword mUp1;
47     private UserPassword mUp2;
48     private UserPassword mUp3;
49     private UserPassword mUp4;
50     private UserPassword mUp5;
51     private UserPassword mUp6;
52     private UserPassword mUp7;
53     private UserPassword mUp8;
54  
55     /** {@inheritDoc} */
56     public void setUp ()
57           throws Exception
58     {
59100       super.setUp();
60  
61100       mUp1 = UserPassword.fromUserPassword(null, null);
62100       mUp2 = UserPassword.EMPTY_USER_PASSWORD;
63100       mUp3 = UserPassword.fromUserPassword(USER, null);
64100       mUp4 = UserPassword.fromUserPassword(USER, PWD);
65100       mUp5 = UserPassword.fromUserPassword(USER, null);
66100       mUp6 = UserPassword.fromUserPassword(USER, PWD);
67100       mUp7 = UserPassword.fromUserPassword(null, PWD);
68100       mUp8 = UserPassword.fromUserPassword(null, PWD);
69100    }
70  
71     /**
72      * Tests the method {@link UserPassword#hashCode()}.
73      */
74     public void testHashCode ()
75     {
76100       final String msqEqual = "The hash codes must be equal.";
77100       final String msqUnequal = "The hash codes must be unequal.";
78  
79        // null user, null password
80100       assertEquals(msqEqual, mUp1.hashCode(), mUp2.hashCode());
8175(2)      assertTrue(msqUnequal, !(mUp1.hashCode() == mUp3.hashCode()));
8275(3)      assertTrue(msqUnequal, !(mUp1.hashCode() == mUp4.hashCode()));
8375(4)      assertTrue(msqUnequal, !(mUp1.hashCode() == mUp7.hashCode()));
84  
85        // non-null user, null password
86100       assertEquals(msqEqual, mUp3.hashCode(), mUp5.hashCode());
8775(5)      assertTrue(msqUnequal, !(mUp3.hashCode() == mUp1.hashCode()));
8875(6)      assertTrue(msqUnequal, !(mUp3.hashCode() == mUp4.hashCode()));
8975(7)      assertTrue(msqUnequal, !(mUp3.hashCode() == mUp7.hashCode()));
90  
91        // non-null user, non-null password
92100       assertEquals(msqEqual, mUp4.hashCode(), mUp6.hashCode());
9375(8)      assertTrue(msqUnequal, !(mUp4.hashCode() == mUp1.hashCode()));
9475(9)      assertTrue(msqUnequal, !(mUp4.hashCode() == mUp3.hashCode()));
9575(10)      assertTrue(msqUnequal, !(mUp4.hashCode() == mUp7.hashCode()));
96  
97        // null user, non-null password
98100       assertEquals(msqEqual, mUp7.hashCode(), mUp8.hashCode());
9975(11)      assertTrue(msqUnequal, !(mUp7.hashCode() == mUp1.hashCode()));
10075(12)      assertTrue(msqUnequal, !(mUp7.hashCode() == mUp4.hashCode()));
10175(13)      assertTrue(msqUnequal, !(mUp7.hashCode() == mUp5.hashCode()));
102100    }
103  
104     /**
105      * Tests the method {@link UserPassword#equals(Object)}.
106      *
107      */
108     public void testEquals ()
109     {
110        // null user, null password
111100       checkEquals(mUp1, mUp1);
112100       checkEquals(mUp1, mUp2);
113100       checkUnEquals(mUp1, mUp3);
114100       checkUnEquals(mUp1, mUp4);
115100       checkUnEquals(mUp1, mUp7);
116  
117        // non-null user, null password
118100       checkEquals(mUp3, mUp3);
119100       checkEquals(mUp3, mUp5);
120100       checkUnEquals(mUp3, mUp1);
121100       checkUnEquals(mUp3, mUp4);
122100       checkUnEquals(mUp3, mUp7);
123  
124        // non-null user, non-null password
125100       checkEquals(mUp4, mUp4);
126100       checkEquals(mUp4, mUp6);
127100       checkUnEquals(mUp4, mUp1);
128100       checkUnEquals(mUp4, mUp3);
129100       checkUnEquals(mUp4, mUp7);
130  
131        // null user, non-null password
132100       checkEquals(mUp7, mUp7);
133100       checkEquals(mUp7, mUp8);
134100       checkUnEquals(mUp7, mUp1);
135100       checkUnEquals(mUp7, mUp4);
136100       checkUnEquals(mUp7, mUp5);
137100    }
138  
139     private void checkEquals (UserPassword a, UserPassword b)
140     {
141  
142100       assertEquals(
143              "The UserPassword instances must be equal. UserPassword left: "
144                 + a.toString() + " UserPassword right: " + b.toString(), a, b);
145100    }
146  
147     private void checkUnEquals (UserPassword a, UserPassword b)
148     {
149100       assertFalse("The UserPassword instances must be unequal. UserPassword "
150              + "left: " + a.toString() + " UserPassword right: " + b.toString(),
151                 a.equals(b));
152100    }
153  }
154  

Findings in this File

i (14) UserPasswordTest.mUp1 not initialized in constructor (test code)
i (15) UserPasswordTest.mUp2 not initialized in constructor (test code)
i (16) UserPasswordTest.mUp3 not initialized in constructor (test code)
i (17) UserPasswordTest.mUp4 not initialized in constructor (test code)
i (18) UserPasswordTest.mUp5 not initialized in constructor (test code)
i (19) UserPasswordTest.mUp6 not initialized in constructor (test code)
i (20) UserPasswordTest.mUp7 not initialized in constructor (test code)
i (21) UserPasswordTest.mUp8 not initialized in constructor (test code)
c (1) 41 : 0 Type Javadoc comment is missing an @author tag.
c (2) 81 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (3) 82 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (4) 83 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (5) 87 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (6) 88 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (7) 89 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (8) 93 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (9) 94 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (10) 95 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (11) 99 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (12) 100 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)
c (13) 101 : 7 assertTrue(!expr) can be replaced by assertFalse(expr)