package org.apache.testlet;

/**
 */
public class TimeBombTestCase
    extends DecoratorTestCase
{
    private long m_maxElaspedTime;

    public TimeBombTestCase( final TestCase testCase, final long maxElaspedTime )
    {
        this( null, testCase, maxElaspedTime );
    }

    public TimeBombTestCase( final String name, final TestCase testCase, final long maxElaspedTime )
    {
        super( name, testCase );
        m_maxElaspedTime = maxElaspedTime;
    }

    public void runTest()
        throws Throwable
    {
        final long startTime = System.currentTimeMillis();
        super.runTest();
        final long endTime = System.currentTimeMillis();
        final long elaspedTime = endTime - startTime;

        if ( elaspedTime > m_maxElaspedTime )
        {
            throw new TestFailedException( "Maximum elasped time exceeded!" +
                  " Expected " + m_maxElaspedTime + "ms, but was " + elaspedTime + "ms." );
        }
    }
}
