Graphene Implementation 1.0.0.CR3

org.jboss.arquillian.ajocado.waiting
Class DefaultWaiting<T extends Waiting<T>>

java.lang.Object
  extended by org.jboss.arquillian.ajocado.waiting.DefaultWaiting<T>
Type Parameters:
T - the end implementation of DefaultWaiting as the return type for setter methods
All Implemented Interfaces:
Cloneable, Waiting<T>
Direct Known Subclasses:
DefaultAjaxWaiting, DefaultSeleniumWaiting

public abstract class DefaultWaiting<T extends Waiting<T>>
extends Object
implements Waiting<T>, Cloneable

Abstract implementation of immutable class with purpose of waiting with customizable timeout, interval, and failure behaviour and delay on start of waiting.

Version:
$Revision$
Author:
Lukas Fryc

Constructor Summary
DefaultWaiting()
           
 
Method Summary
 T dontFail()
          Sets no failure after waiting timeout.
protected  void fail()
          Tries to fail by throwing 'failure' throwable.
 T failWith(CharSequence failureMessage, Object... arguments)
           Returns preset instance of waiting with given failure message parametrized by given objects.
 T failWith(Exception exception)
           Returns Waiting object initialized with given exception.
protected  long getInterval()
          Returns the interval set for this object.
protected  long getTimeout()
          Returns the timeout set for this object.
 T interval(long interval)
          Returns instance of waiting with same properties like this object and interval set to given interval.
protected  boolean isDelayed()
          Returns if this waiting's start is delayed.
 T noDelay()
          Sets no delay between start of waiting and first test for conditions.
 T timeout(long timeout)
          Returns instance of waiting with same properties like this object and timeout set to given timeout.
 void waitForTimeout()
          Waits for predefined amount of time (see Waiting.timeout(long)).
 T withDelay(boolean isDelayed)
           Set if testing condition should be delayed of one interval after the start of waiting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultWaiting

public DefaultWaiting()
Method Detail

getInterval

protected long getInterval()
Returns the interval set for this object.

Returns:
the set interval

getTimeout

protected long getTimeout()
Returns the timeout set for this object.

Returns:
the timeout set for this object

isDelayed

protected boolean isDelayed()
Returns if this waiting's start is delayed.

Returns:
if this waiting's start is delayed

interval

public T interval(long interval)
Description copied from interface: Waiting
Returns instance of waiting with same properties like this object and interval set to given interval.

Specified by:
interval in interface Waiting<T extends Waiting<T>>
Parameters:
interval - in milliseconds that will be preset to returned instance of Waiting
Returns:
Waiting instance configured with given interval

timeout

public T timeout(long timeout)
Description copied from interface: Waiting
Returns instance of waiting with same properties like this object and timeout set to given timeout.

Specified by:
timeout in interface Waiting<T extends Waiting<T>>
Parameters:
timeout - in milliseconds that will be preset to returned instance of Waiting
Returns:
Waiting instance configured with given timeout

failWith

public T failWith(Exception exception)
Description copied from interface: Waiting

Returns Waiting object initialized with given exception.

If the exception is instance of RuntimeException, it will be thrown in case of waiting timed out.

If the exception isn't instance of RuntimeException, the WaitingTimeoutException will be thrown with cause preset to the given Throwable.

If failure is set to null, timeout will not result to failure!

Specified by:
failWith in interface Waiting<T extends Waiting<T>>
Parameters:
exception - the instance of RuntimeException to be thrown or any other Exception when the WaitTimeoutException should be thrown with this exception as cause
Returns:
Waiting instance configured with given exception as cause of waiting timeout

failWith

public T failWith(CharSequence failureMessage,
                  Object... arguments)
Description copied from interface: Waiting

Returns preset instance of waiting with given failure message parametrized by given objects.

To parametrize failure message, the SimplifiedFormat.format(String, Object...) will be used.

If failure is set to null, timeout will not result to failure!

Specified by:
failWith in interface Waiting<T extends Waiting<T>>
Parameters:
failureMessage - character sequence that will be used as message of exception thrown in case of waiting timeout or null if waiting timeout shouldn't result to failure
arguments - arguments to failureMessage which will be use in parametrization of failureMessage
Returns:
Waiting instance initialized with given failureMessage and arguments

dontFail

public T dontFail()
Description copied from interface: Waiting
Sets no failure after waiting timeout. Waiting timeout with this preset don't result to failure!

Specified by:
dontFail in interface Waiting<T extends Waiting<T>>
Returns:
Waiting instance initialized with no failure

noDelay

public T noDelay()
Description copied from interface: Waiting
Sets no delay between start of waiting and first test for conditions.

Specified by:
noDelay in interface Waiting<T extends Waiting<T>>
Returns:
Waiting instance initialized with no delay

withDelay

public T withDelay(boolean isDelayed)
Description copied from interface: Waiting

Set if testing condition should be delayed of one interval after the start of waiting.

The length of delay is one interval (see Waiting.interval(long)).

Specified by:
withDelay in interface Waiting<T extends Waiting<T>>
Parameters:
isDelayed - true if start of condition testing should be delayed; false otherwise
Returns:
Waiting instance initialized with the delay before start of testing conditions if isDelayed is set to true; with no delay otherwise

waitForTimeout

public void waitForTimeout()
Description copied from interface: Waiting
Waits for predefined amount of time (see Waiting.timeout(long)).

Specified by:
waitForTimeout in interface Waiting<T extends Waiting<T>>

fail

protected void fail()
Tries to fail by throwing 'failure' throwable. If failure is instance of RuntimeException, will be directly thrown. Otherwise will be failure clothe to RuntimeException. If failure is null, method wont fail.


Graphene Implementation 1.0.0.CR3

Copyright © 2012 JBoss by Red Hat. All Rights Reserved.