View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.validator.util;
18  
19  import junit.framework.TestCase;
20  
21  /**
22   * Test the Flags class.
23   *
24   * @version $Revision$
25   */
26  public class FlagsTest extends TestCase {
27  
28      /**
29       * Declare some flags for testing.
30       */
31      private static final long LONG_FLAG = 1;
32      private static final long LONG_FLAG_2 = 2;
33      private static final int INT_FLAG = 4;
34  
35      /**
36       * Constructor for FlagsTest.
37       */
38      public FlagsTest(String name) {
39          super(name);
40      }
41  
42      public void testHashCode() {
43          Flags f = new Flags(45);
44          assertEquals(f.hashCode(), 45);
45      }
46  
47      public void testGetFlags() {
48          Flags f = new Flags(45);
49          assertEquals(f.getFlags(), 45);
50      }
51  
52      public void testIsOnOff() {
53          Flags f = new Flags();
54          f.turnOn(LONG_FLAG);
55          f.turnOn(INT_FLAG);
56          assertTrue(f.isOn(LONG_FLAG));
57          assertTrue(!f.isOff(LONG_FLAG));
58  
59          assertTrue(f.isOn(INT_FLAG));
60          assertTrue(!f.isOff(INT_FLAG));
61  
62          assertTrue(f.isOff(LONG_FLAG_2));
63      }
64  
65      public void testTurnOnOff() {
66      }
67  
68      public void testTurnOff() {
69      }
70  
71      public void testTurnOffAll() {
72          Flags f = new Flags(98432);
73          f.turnOffAll();
74          assertEquals(0, f.getFlags());
75      }
76      
77      public void testClear() {
78          Flags f = new Flags(98432);
79          f.clear();
80          assertEquals(0, f.getFlags());
81      }
82  
83      public void testTurnOnAll() {
84          Flags f = new Flags();
85          f.turnOnAll();
86          assertEquals(~0, f.getFlags());
87      }
88  
89      public void testIsOn_isFalseWhenNotAllFlagsInArgumentAreOn() {
90          Flags first = new Flags(1);
91          long firstAndSecond = 3;
92          
93          assertFalse(first.isOn(firstAndSecond)); 
94      }
95  
96      public void testIsOn_isTrueWhenHighOrderBitIsSetAndQueried() {
97          Flags allOn = new Flags(~0);
98          long highOrderBit = 0x8000000000000000L;
99          
100         assertTrue(allOn.isOn(highOrderBit));
101     }
102 
103     /**
104      * Test for Object clone()
105      */
106     public void testClone() {
107     }
108 
109     /**
110      * Test for boolean equals(Object)
111      */
112     public void testEqualsObject() {
113     }
114 
115     /**
116      * Test for String toString()
117      */
118     public void testToString() {
119         Flags f = new Flags();
120         String s = f.toString();
121         assertEquals(64, s.length());
122 
123         f.turnOn(INT_FLAG);
124         s = f.toString();
125         assertEquals(64, s.length());
126 
127         assertEquals(
128             "0000000000000000000000000000000000000000000000000000000000000100",
129             s);
130     }
131 
132 }