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   */
41 (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     {
59        super.setUp();
60   
61        mUp1 = UserPassword.fromUserPassword(nullnull);
62        mUp2 = UserPassword.EMPTY_USER_PASSWORD;
63        mUp3 = UserPassword.fromUserPassword(USER, null);
64        mUp4 = UserPassword.fromUserPassword(USER, PWD);
65        mUp5 = UserPassword.fromUserPassword(USER, null);
66        mUp6 = UserPassword.fromUserPassword(USER, PWD);
67        mUp7 = UserPassword.fromUserPassword(null, PWD);
68        mUp8 = UserPassword.fromUserPassword(null, PWD);
69     }
70   
71     /**
72      * Tests the method {@link UserPassword#hashCode()}.
73      */
74     public void testHashCode ()
75     {
76        final String msqEqual = "The hash codes must be equal.";
77        final String msqUnequal = "The hash codes must be unequal.";
78   
79        // null user, null password
80        assertEquals(msqEqual, mUp1.hashCode(), mUp2.hashCode());
81 (2)      (2)assertTrue(msqUnequal, !(mUp1.hashCode() == mUp3.hashCode()));
82 (3)      (3)assertTrue(msqUnequal, !(mUp1.hashCode() == mUp4.hashCode()));
83 (4)      (4)assertTrue(msqUnequal, !(mUp1.hashCode() == mUp7.hashCode()));
84   
85        // non-null user, null password
86        assertEquals(msqEqual, mUp3.hashCode(), mUp5.hashCode());
87 (5)      (5)assertTrue(msqUnequal, !(mUp3.hashCode() == mUp1.hashCode()));
88 (6)      (6)assertTrue(msqUnequal, !(mUp3.hashCode() == mUp4.hashCode()));
89 (7)      (7)assertTrue(msqUnequal, !(mUp3.hashCode() == mUp7.hashCode()));
90   
91        // non-null user, non-null password
92        assertEquals(msqEqual, mUp4.hashCode(), mUp6.hashCode());
93 (8)      (8)assertTrue(msqUnequal, !(mUp4.hashCode() == mUp1.hashCode()));
94 (9)      (9)assertTrue(msqUnequal, !(mUp4.hashCode() == mUp3.hashCode()));
95 (10)      (10)assertTrue(msqUnequal, !(mUp4.hashCode() == mUp7.hashCode()));
96   
97        // null user, non-null password
98        assertEquals(msqEqual, mUp7.hashCode(), mUp8.hashCode());
99 (11)      (11)assertTrue(msqUnequal, !(mUp7.hashCode() == mUp1.hashCode()));
100 (12)      (12)assertTrue(msqUnequal, !(mUp7.hashCode() == mUp4.hashCode()));
101 (13)      (13)assertTrue(msqUnequal, !(mUp7.hashCode() == mUp5.hashCode()));
102     }
103   
104     /**
105      * Tests the method {@link UserPassword#equals(Object)}.
106      *
107      */
108     public void testEquals ()
109     {
110        // null user, null password
111        checkEquals(mUp1, mUp1);
112        checkEquals(mUp1, mUp2);
113        checkUnEquals(mUp1, mUp3);
114        checkUnEquals(mUp1, mUp4);
115        checkUnEquals(mUp1, mUp7);
116   
117        // non-null user, null password
118        checkEquals(mUp3, mUp3);
119        checkEquals(mUp3, mUp5);
120        checkUnEquals(mUp3, mUp1);
121        checkUnEquals(mUp3, mUp4);
122        checkUnEquals(mUp3, mUp7);
123   
124        // non-null user, non-null password
125        checkEquals(mUp4, mUp4);
126        checkEquals(mUp4, mUp6);
127        checkUnEquals(mUp4, mUp1);
128        checkUnEquals(mUp4, mUp3);
129        checkUnEquals(mUp4, mUp7);
130   
131        // null user, non-null password
132        checkEquals(mUp7, mUp7);
133        checkEquals(mUp7, mUp8);
134        checkUnEquals(mUp7, mUp1);
135        checkUnEquals(mUp7, mUp4);
136        checkUnEquals(mUp7, mUp5);
137     }
138   
139     private void checkEquals (UserPassword a, UserPassword b)
140     {
141   
142        assertEquals(
143              "The UserPassword instances must be equal. UserPassword left: "
144                 + a.toString() + " UserPassword right: " + b.toString(), a, b);
145     }
146   
147     private void checkUnEquals (UserPassword a, UserPassword b)
148     {
149        assertFalse("The UserPassword instances must be unequal. UserPassword "
150              + "left: " + a.toString() + " UserPassword right: " + b.toString(),
151                 a.equals(b));
152     }
153  }
154   
155   

Findings in this File

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)