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 static org.junit.jupiter.api.Assertions.assertEquals;
20  import static org.junit.jupiter.api.Assertions.assertFalse;
21  import static org.junit.jupiter.api.Assertions.assertTrue;
22  
23  import org.junit.jupiter.api.Test;
24  
25  /**
26   * Test the Flags class.
27   */
28  public class FlagsTest {
29  
30      /**
31       * Declare some flags for testing.
32       */
33      private static final long LONG_FLAG = 1;
34      private static final long LONG_FLAG_2 = 2;
35      private static final int INT_FLAG = 4;
36  
37      @Test
38      public void testClear() {
39          final Flags f = new Flags(98432);
40          f.clear();
41          assertEquals(0, f.getFlags());
42      }
43  
44      /**
45       * Test for Object clone()
46       */
47      @Test
48      public void testClone() {
49      }
50  
51      /**
52       * Test for boolean equals(Object)
53       */
54      @Test
55      public void testEqualsObject() {
56      }
57  
58      @Test
59      public void testGetFlags() {
60          final Flags f = new Flags(45);
61          assertEquals(f.getFlags(), 45);
62      }
63  
64      @Test
65      public void testHashCode() {
66          final Flags f = new Flags(45);
67          assertEquals(f.hashCode(), 45);
68      }
69  
70      @Test
71      public void testIsOn_isFalseWhenNotAllFlagsInArgumentAreOn() {
72          final Flags first = new Flags(1);
73          final long firstAndSecond = 3;
74  
75          assertFalse(first.isOn(firstAndSecond));
76      }
77  
78      @Test
79      public void testIsOn_isTrueWhenHighOrderBitIsSetAndQueried() {
80          final Flags allOn = new Flags(~0);
81          final long highOrderBit = 0x8000000000000000L;
82  
83          assertTrue(allOn.isOn(highOrderBit));
84      }
85  
86      @Test
87      public void testIsOnOff() {
88          final Flags f = new Flags();
89          f.turnOn(LONG_FLAG);
90          f.turnOn(INT_FLAG);
91          assertTrue(f.isOn(LONG_FLAG));
92          assertTrue(!f.isOff(LONG_FLAG));
93  
94          assertTrue(f.isOn(INT_FLAG));
95          assertTrue(!f.isOff(INT_FLAG));
96  
97          assertTrue(f.isOff(LONG_FLAG_2));
98      }
99  
100     /**
101      * Test for String toString()
102      */
103     @Test
104     public void testToString() {
105         final Flags f = new Flags();
106         String s = f.toString();
107         assertEquals(64, s.length());
108 
109         f.turnOn(INT_FLAG);
110         s = f.toString();
111         assertEquals(64, s.length());
112 
113         assertEquals("0000000000000000000000000000000000000000000000000000000000000100", s);
114     }
115 
116     @Test
117     public void testTurnOff() {
118     }
119 
120     @Test
121     public void testTurnOffAll() {
122         final Flags f = new Flags(98432);
123         f.turnOffAll();
124         assertEquals(0, f.getFlags());
125     }
126 
127     @Test
128     public void testTurnOnAll() {
129         final Flags f = new Flags();
130         f.turnOnAll();
131         assertEquals(~0, f.getFlags());
132     }
133 
134     @Test
135     public void testTurnOnOff() {
136     }
137 
138 }