All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.serenitybdd.core.time.InternalSystemClock Maven / Gradle / Ivy

There is a newer version: 4.1.20
Show newest version
package net.serenitybdd.core.time;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.ZonedDateTime;

/**
 * Object that encapsulates system clock operations.
 */
public class InternalSystemClock implements SystemClock {

    private static final Logger LOGGER = LoggerFactory.getLogger(InternalSystemClock.class);

    /**
     * Pause execution for the requested delay.
     * Throws a runtime exception if something goes wrong.
     */
    public void pauseFor(final long timeInMilliseconds) {

         try {
             sleepFor(timeInMilliseconds);
         } catch (InterruptedException e) {
             LOGGER.error("Wait interrupted:" +  e.getMessage());
             throw new RuntimeException("System timer interrupted", e);
         }
    }

    protected void sleepFor(long timeInMilliseconds) throws InterruptedException {
        Thread.sleep(timeInMilliseconds);
    }

    /**
     * Find the current system time.
     */
    public ZonedDateTime getCurrentTime() {
        return ZonedDateTime.now();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy