final MBeanInfo mbeanInfo = getTestMBeanInfo();
final MBeanOperationInfo[] operationInfos = mbeanInfo.getOperations();
final CoverageInfoImpl impl = create( mbeanInfo );
assert( mbeanInfo == impl.getMBeanInfo() );
//--------------------------------------------------------------------
// verify that operationWasInvoked() works
for( final MBeanOperationInfo operationInfo : operationInfos )
{
final String name = operationInfo.getName();
final String[] sig = JMXUtil.getSignature( operationInfo.getSignature() );
impl.operationWasInvoked( name, sig );
}
assert( impl.getOperationCoverage() == 100 ) :
"Expected coverage of 100%, got " + impl.getOperationCoverage();
assert( impl.getUnknownOperations().size() == 0 );
assert( impl.getOperationsNotInvoked().size() == 0 );
assert( impl.getInvocationFailures().size() == 0 );
impl.toString( true );
impl.toString( false );
//--------------------------------------------------------------------
// verify that markAsInvoked() works
final Set<String> invoked = impl.getOperationsInvoked();
impl.clear();
for( final String op : invoked )
{
impl.markAsInvoked( op );
}
assert( impl.getOperationCoverage() == 100 ) :
"Expected coverage of 100%, got " + impl.getOperationCoverage();
assert( impl.getUnknownOperations().size() == 0 );
assert( impl.getOperationsNotInvoked().size() == 0 );
assert( impl.getInvocationFailures().size() == 0 );
final String DUMMY_OPERATION = "dummyOperationName";
impl.operationWasInvoked( DUMMY_OPERATION, null );
impl.operationWasInvoked( DUMMY_OPERATION, null );
assert( impl.getUnknownOperations().size() == 1 );
impl.toString( true );
impl.toString( false );
//--------------------------------------------------------------------
// verify that failures are tracked correctly
impl.clear();
for( final MBeanOperationInfo operationInfo : operationInfos )
{
final String name = operationInfo.getName();
final String[] sig = JMXUtil.getSignature( operationInfo.getSignature() );
impl.operationWasInvoked( name, sig );
impl.operationFailed( name, sig );
}
assert( impl.getOperationCoverage() == 100 ) :
"Expected coverage of 100%, got " + impl.getOperationCoverage();
assert( impl.getUnknownOperations().size() == 0 );
assert( impl.getOperationsNotInvoked().size() == 0 );
assert( impl.getOperationsInvoked().size() == operationInfos.length );
assert( impl.getInvocationFailures().size() == operationInfos.length );
impl.toString( true );
impl.toString( false );
//--------------------------------------------------------------------
// verify that we can't call operationFailed() on an illegal operation
try
{
impl.operationFailed( "foo", null );
assert( false ) : "expected failure when calling operationFailed()";
}
catch( IllegalArgumentException e )
{
}
impl.toString( true );
impl.toString( false );
impl.toString();