View Javadoc
1   package org.junit.runners.model;
2   
3   import java.util.concurrent.TimeUnit;
4   
5   /**
6    * Exception thrown when a test fails on timeout.
7    * 
8    * @since 4.12
9    * 
10   */
11  public class TestTimedOutException extends Exception {
12  
13      private static final long serialVersionUID = 31935685163547539L;
14  
15      private final TimeUnit timeUnit;
16      private final long timeout;
17  
18      /**
19       * Creates exception with a standard message "test timed out after [timeout] [timeUnit]"
20       * 
21       * @param timeout the amount of time passed before the test was interrupted
22       * @param timeUnit the time unit for the timeout value
23       */
24      public TestTimedOutException(long timeout, TimeUnit timeUnit) {
25          super(String.format("test timed out after %d %s", 
26                  timeout, timeUnit.name().toLowerCase()));
27          this.timeUnit = timeUnit;
28          this.timeout = timeout;
29      }
30  
31      /**
32       * Gets the time passed before the test was interrupted
33       */
34      public long getTimeout() {
35          return timeout;
36      }
37  
38      /**
39       * Gets the time unit for the timeout value
40       */
41      public TimeUnit getTimeUnit() {
42          return timeUnit;
43      }
44  }