@Test
public void testFlagGetterSetter() throws Exception
{
AbstractKerberosFlags akf = new AbstractKerberosFlags()
{
private static final long serialVersionUID = 1L;
};
// MAX_VALUE is not a real ticket flag and will cause an IndexOutOfBoundsException,
// so skip this
TicketFlag[] ticketFlags = new TicketFlag[TicketFlag.values().length - 1];
int i = 0;
int flagsValue = 0;
for ( TicketFlag tf : TicketFlag.values() )
{
if ( tf != TicketFlag.MAX_VALUE )
{
ticketFlags[i] = tf;
}
i++;
}
boolean setFlag = true;
for ( TicketFlag ticketFlag : ticketFlags )
{
// Only set every 2nd ticket flag
if ( setFlag )
{
akf.setFlag( ticketFlag.getValue() );
flagsValue += ( 1 << ( 31 - ticketFlag.getValue() ) );
}
setFlag = !setFlag;
}
setFlag = true;
for ( TicketFlag ticketFlag : ticketFlags )
{
// Only every 2nd ticket flag is set
if ( setFlag )
{
assertTrue( "isFlagSet(TicketFlag): " + ticketFlag.toString(), akf.isFlagSet( ticketFlag ) );
assertTrue( "isFlagSet(int): " + ticketFlag.toString(), akf.isFlagSet( ticketFlag.getValue() ) );
assertTrue( "isFlagSet(int,int): " + ticketFlag.toString(),
AbstractKerberosFlags.isFlagSet( flagsValue, ticketFlag.getValue() ) );
}
else
{
assertFalse( "isFlagSet(TicketFlag): " + ticketFlag.toString(), akf.isFlagSet( ticketFlag ) );
assertFalse( "isFlagSet(int): " + ticketFlag.toString(), akf.isFlagSet( ticketFlag.getValue() ) );
assertFalse( "isFlagSet(int,int): " + ticketFlag.toString(),
AbstractKerberosFlags.isFlagSet( flagsValue, ticketFlag.getValue() ) );
}
setFlag = !setFlag;