Skip to content

yegor256/jping

Repository files navigation

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

mvn PDD status Maven Central Javadoc codecov Hits-of-Code License

JUnit5 execution condition that checks whether a connection to public Internet is available.

First, you add this to your pom.xml:

<dependency>
  <groupId>com.yegor256</groupId>
  <artifactId>jping</artifactId>
  <version>0.0.3</version>
  <scope>test</scope>
</dependency>

Then, you use it like this:

import com.yegor256.WeAreOnline;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(WeAreOnline.class)
final class MyTest {
  @Test
  void canDownloadViaHttp() throws Exception {
    new URL("https://www.google.com").openStream();
  }
}

Or if need to override default settings:

import com.yegor256.OnlineMeans;
import com.yegor256.WeAreOnline;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(WeAreOnline.class)
final class MyTest {
    @Test
    @OnlineMeans(url = "https://www.amazon.com", connectTimeout = 500, readTimeout = 1500)
    void canDownloadViaHttp() throws Exception {
        new URL("https://www.amazon.com").openStream();
    }
}

We don't want this unit test to be executed when no Internet connection is available. The WeAreOnline execution condition will prevent JUnit5 from executing the test when you are offline.

How to Contribute

Fork repository, make changes, send us a pull request. We will review your changes and apply them to the master branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build:

$ mvn clean install -Pqulice

You will need Maven 3.3+ and Java 8+.