/assertions

⚡️ Assertions for java programming

Primary LanguageJava

⚡️ Assertions

Assertions for java programming.

build Codacy Badge codecov

Getting started

Maven

<dependency>
    <groupId>io.github.ones1kk</groupId>
    <artifactId>assertions</artifactId>
    <version>0.0.6</version>
</dependency>

Gradle

implementation group: 'io.github', name: 'assertions', version: '0.0.6'

Gradle(short)

implementation 'io.github.ones1kk:assertions:0.0.6'

Overview

  • Verifies assertions for JDK types.(Class, Lang type of Java, Collection, Array(1D), File, URL ...)
  • Provides assertions in the form of method chaining.
  • Overrides error message by writing custom description.(For using 'as()' method)

Example

List<String> list = Arrays.asList("A", "a", "B", "b", "C", "2");

List<String> expected = singletonList("a");

Asserts.that(list)
    // First off, it can be described as combining 2 step assertion.
    .as("The given 'list' should not be empty and not be null.")
    // The given 'list' should not be empty, assertion will verify it's empty or not.
    .isNotEmpty()
    // The given 'list' should not be null, assertion will verify it's null or not.
    .isNotNull()
    // If the verification of the above assertion is passed,
    // User can define new description for new step.
    // Also can put parameters into description with braces.
    .as("The given 'list' should contain one of '{}'.", "1, 2, or 3")
    // The given 'list' should contain any of the arguments.
    .containsAny("1", "2", "3")
    // Also, all of the arguments should be contained in given 'list'.
    .containsAll("a", "b")
    // Write description again.
    .as("The given 'list' shouldn't contain null.")
    // The given 'list' shouldn't contain null.
    .doesNotContainNull()
    // The all of elements in 'list' should match all the provided predicate.
    .allMatch(str -> str.length() > 0)
    // Write description again.
    .as("The size of given 'list' should be larger than 'expected'.")
    // The size of given 'list' should be larger than the size of given the size of 'expected'.
    .isLargerThan(expected);         

Inspired

AssertJ - Fluent assertions java library