org.assertj.swing.timing.Pause Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of assertj-swing Show documentation
Show all versions of assertj-swing Show documentation
Fluent interface for functional GUI testing
/**
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2015 the original author or authors.
*/
package org.assertj.swing.timing;
import static org.assertj.core.util.Preconditions.checkNotNull;
import static org.assertj.core.util.Preconditions.checkNotNullOrEmpty;
import static org.assertj.swing.timing.Timeout.timeout;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.annotation.Nonnull;
import org.assertj.core.presentation.StandardRepresentation;
import org.assertj.swing.exception.WaitTimedOutError;
/**
* Waits for period of time or for a particular condition to be satisfied.
*
* @author Alex Ruiz
* @author Yvonne Wang
*/
public final class Pause {
private static final Timeout DEFAULT_TIMEOUT = timeout();
private static final int SLEEP_INTERVAL = 10;
private static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool();
/**
* Waits until the given condition is satisfied.
*
* @param condition the condition to verify.
* @throws NullPointerException if the given condition is {@code null}.
* @throws WaitTimedOutError if the wait times out (more than 30 seconds).
*/
public static void pause(@Nonnull Condition condition) {
pause(condition, DEFAULT_TIMEOUT);
}
/**
* Waits until the given condition is satisfied.
*
* @param condition the condition to verify.
* @param timeout the timeout.
* @throws NullPointerException if the given timeout is {@code null}.
* @throws NullPointerException if the given condition is {@code null}.
* @throws WaitTimedOutError if the wait times out.
*/
public static void pause(@Nonnull Condition condition, @Nonnull Timeout timeout) {
checkNotNull(timeout);
pause(condition, timeout.duration());
}
/**
* Waits until the given condition is satisfied.
*
* @param condition the condition to verify.
* @param timeout the timeout (in milliseconds.)
* @throws NullPointerException if the given condition is {@code null}.
* @throws WaitTimedOutError if the wait times out.
*/
public static void pause(@Nonnull final Condition condition, final long timeout) {
checkNotNull(condition);
try {
Callable