@Test
public void testDestroyContainer() throws Exception
{

    ContainerDestructionWorkflow containerDestructionWorkflow = mock( ContainerDestructionWorkflow.class );
    doReturn( containerDestructionWorkflow ).when( environmentManager )
                                            .getContainerDestructionWorkflow( environment, environmentContainer,
                                                    trackerOperation );
    doNothing().when( environmentManager ).registerActiveWorkflow( environment, containerDestructionWorkflow );
    environmentManager.destroyContainer( TestHelper.ENV_ID, TestHelper.CONTAINER_ID, false );
    verify( containerDestructionWorkflow ).join();
    //-----
    doReturn( true ).when( containerDestructionWorkflow ).isFailed();
    try
    {
        environmentManager.destroyContainer( TestHelper.ENV_ID, TestHelper.CONTAINER_ID, false );
        fail( "Expected EnvironmentModificationException" );
    }
    catch ( EnvironmentModificationException e )
    {
    }
    //-----
    doThrow( new ContainerHostNotFoundException( "" ) ).when( environment )
                                                       .getContainerHostById( TestHelper.CONTAINER_ID );
    try
    {
        environmentManager.destroyContainer( TestHelper.ENV_ID, TestHelper.CONTAINER_ID, false );
        fail( "Expected EnvironmentModificationException" );
    }
    catch ( EnvironmentModificationException e )
    {
    }
    //-----
    doReturn( EnvironmentStatus.UNDER_MODIFICATION ).when( environment ).getStatus();
    try
    {
        environmentManager.destroyContainer( TestHelper.ENV_ID, TestHelper.CONTAINER_ID, false );
        fail( "Expected EnvironmentModificationException" );
    }
    catch ( EnvironmentModificationException e )
    {
    }
    //-----
    doReturn( bzrEnvironment ).when( environmentManager ).loadEnvironment( TestHelper.ENV_ID );
    environmentManager.destroyContainer( TestHelper.ENV_ID, TestHelper.CONTAINER_ID, false );
    verify( environmentAdapter ).destroyContainer( bzrEnvironment, TestHelper.CONTAINER_ID );
}