1/* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5package org.mockito.verification; 6 7import static org.mockito.internal.exceptions.Reporter.atMostAndNeverShouldNotBeUsedWithTimeout; 8 9import org.mockito.internal.util.Timer; 10import org.mockito.internal.verification.VerificationModeFactory; 11import org.mockito.internal.verification.VerificationOverTimeImpl; 12import org.mockito.internal.verification.VerificationWrapper; 13 14/** 15 * See the javadoc for {@link VerificationWithTimeout} 16 * <p> 17 * Typically, you won't use this class explicitly. Instead use timeout() method on Mockito class. 18 * See javadoc for {@link VerificationWithTimeout} 19 */ 20public class Timeout extends VerificationWrapper<VerificationOverTimeImpl> implements VerificationWithTimeout { 21 22 /** 23 * See the javadoc for {@link VerificationWithTimeout} 24 * <p> 25 * Typically, you won't use this class explicitly. Instead use timeout() method on Mockito class. 26 * See javadoc for {@link VerificationWithTimeout} 27 */ 28 public Timeout(long millis, VerificationMode delegate) { 29 this(10, millis, delegate); 30 } 31 32 /** 33 * See the javadoc for {@link VerificationWithTimeout} 34 */ 35 Timeout(long pollingPeriodMillis, long millis, VerificationMode delegate) { 36 this(new VerificationOverTimeImpl(pollingPeriodMillis, millis, delegate, true)); 37 } 38 39 /** 40 * See the javadoc for {@link VerificationWithTimeout} 41 */ 42 Timeout(long pollingPeriodMillis, VerificationMode delegate, Timer timer) { 43 this(new VerificationOverTimeImpl(pollingPeriodMillis, delegate, true, timer)); 44 } 45 46 Timeout(VerificationOverTimeImpl verificationOverTime) { 47 super(verificationOverTime); 48 } 49 50 @Override 51 protected VerificationMode copySelfWithNewVerificationMode(VerificationMode newVerificationMode) { 52 return new Timeout(wrappedVerification.copyWithVerificationMode(newVerificationMode)); 53 } 54 55 public VerificationMode atMost(int maxNumberOfInvocations) { 56 throw atMostAndNeverShouldNotBeUsedWithTimeout(); 57 } 58 59 public VerificationMode never() { 60 throw atMostAndNeverShouldNotBeUsedWithTimeout(); 61 } 62 63 @Override 64 public VerificationMode description(String description) { 65 return VerificationModeFactory.description(this, description); 66 } 67 68} 69