001 package org.junit.runners.model;
002
003 import java.util.concurrent.TimeUnit;
004
005 /**
006 * Exception thrown when a test fails on timeout.
007 *
008 * @since 4.12
009 *
010 */
011 public class TestTimedOutException extends Exception {
012
013 private static final long serialVersionUID = 31935685163547539L;
014
015 private final TimeUnit timeUnit;
016 private final long timeout;
017
018 /**
019 * Creates exception with a standard message "test timed out after [timeout] [timeUnit]"
020 *
021 * @param timeout the amount of time passed before the test was interrupted
022 * @param timeUnit the time unit for the timeout value
023 */
024 public TestTimedOutException(long timeout, TimeUnit timeUnit) {
025 super(String.format("test timed out after %d %s",
026 timeout, timeUnit.name().toLowerCase()));
027 this.timeUnit = timeUnit;
028 this.timeout = timeout;
029 }
030
031 /**
032 * Gets the time passed before the test was interrupted
033 */
034 public long getTimeout() {
035 return timeout;
036 }
037
038 /**
039 * Gets the time unit for the timeout value
040 */
041 public TimeUnit getTimeUnit() {
042 return timeUnit;
043 }
044 }