    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: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
    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(Long.MAX_VALUE, f.getFlags());
    87  	}
    88
    89  	/***
    90  	 * Test for Object clone()
    91  	 */
    92  	public void testClone() {
    93  	}
    94
    95  	/***
    96  	 * Test for boolean equals(Object)
    97  	 */
    98  	public void testEqualsObject() {
    99  	}
    100
    101 	/***
    102 	 * Test for String toString()
    103 	 */
    104 	public void testToString() {
    105 		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(
    114 			"0000000000000000000000000000000000000000000000000000000000000100",
    115 			s);
    116 	}
    117
    118 }