View Javadoc

1   package com.atlassian.pageobjects.elements.query;
2   
3   /**
4    * Strategies for handling expired timeouts of the {@link TimedQuery}.
5    *
6    */
7   public interface ExpirationHandler
8   {
9   
10      /**
11       * Handle timeout expiration for given query.
12       *
13       * @param <T> type of the query result
14       * @param query timed query, whose timeout has expired
15       * @param currentValue current evaluation of the query
16       * @param timeout timeout of the query
17       * @return result value to be returned by the query ater the timeout expiration
18       */
19      <T> T expired(TimedQuery<T> query, T currentValue, long timeout);
20  
21  
22      
23      public static final ExpirationHandler RETURN_CURRENT = new ExpirationHandler()
24      {
25          public <T> T expired(TimedQuery<T> query, T currentValue, long timeout)
26          {
27              return currentValue;
28          }
29      };
30  
31      public static final ExpirationHandler RETURN_NULL = new ExpirationHandler()
32      {
33          public <T> T expired(TimedQuery<T> query, T currentValue, long timeout)
34          {
35              return null;
36          }
37      };
38  
39      public static final ExpirationHandler THROW_ASSERTION_ERROR = new ExpirationHandler()
40      {
41          public <T> T expired(TimedQuery<T> query, T currentValue, long timeout)
42          {
43              throw new AssertionError("Timeout <" + timeout + "> expired for: " + query);
44          }
45      };
46  
47      public static final ExpirationHandler THROW_ILLEGAL_STATE = new ExpirationHandler()
48      {
49          public <T> T expired(TimedQuery<T> query, T currentValue, long timeout)
50          {
51              throw new IllegalStateException("Timeout <" + timeout + "> expired for: " + query);
52          }
53      };
54  
55  }