@Test
public void testDestroyEnvironment() throws Exception
{

    EnvironmentDestructionWorkflow environmentDestructionWorkflow = mock( EnvironmentDestructionWorkflow.class );
    doReturn( environmentDestructionWorkflow ).when( environmentManager )
                                              .getEnvironmentDestructionWorkflow( environment, trackerOperation );
    doNothing().when( environmentManager ).registerActiveWorkflow( environment, environmentDestructionWorkflow );
    environmentManager.destroyEnvironment( TestHelper.ENV_ID, false );
    verify( environmentDestructionWorkflow ).join();
    //-----
    doReturn( true ).when( environmentDestructionWorkflow ).isFailed();
    try
    {
        environmentManager.destroyEnvironment( TestHelper.ENV_ID, false );
        fail( "Expected EnvironmentModificationException" );
    }
    catch ( EnvironmentDestructionException e )
    {
    }
    //-----
    doReturn( EnvironmentStatus.UNDER_MODIFICATION ).when( environment ).getStatus();
    try
    {
        environmentManager.destroyEnvironment( TestHelper.ENV_ID, false );
        fail( "Expected EnvironmentModificationException" );
    }
    catch ( EnvironmentDestructionException e )
    {
    }
    //-----
    doReturn( bzrEnvironment ).when( environmentManager ).loadEnvironment( TestHelper.ENV_ID );
    environmentManager.destroyEnvironment( TestHelper.ENV_ID, false );
    verify( environmentAdapter ).removeEnvironment( bzrEnvironment );
}