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

io.immutables.that.Assert Maven / Gradle / Ivy

The newest version!
package io.immutables.that;

import io.immutables.meta.Null;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
 * {@code Assert.that}: Minimalistic, extensible and attentive to details assertions.
 */
public final class Assert {
	private Assert() {}

	/**
	 * @return that condition
	 */
	public static That.AssertedCondition that() {
		class Tested implements That.AssertedCondition {}
		return new Tested();
	}

	/**
	 * @param actualRuns runnable or lambda
	 * @return that runnable
	 */
	public static That.AssertedRunnable that(CanThrow actualRuns) {
		class Tested extends That.What
				implements That.AssertedRunnable {}
		return new Tested().set(actualRuns);
	}

	public interface CanThrow {
		void run() throws Exception;
	}

	/**
	 * @param  actual object type
	 * @param actual object
	 * @return that object
	 */
	public static  That.AssertedObject that(@Null T actual) {
		class Tested extends That.What> implements That.AssertedObject {}
		return new Tested().set(actual);
	}

	/**
	 * @param  actual object type
	 * @param actual optional object
	 * @return that optional
	 */
	public static  That.AssertedOptional that(@Null java.util.Optional actual) {
		class Tested extends That.What, That.AssertedOptional> implements That.AssertedOptional {}
		return new Tested().set(actual);
	}

	/**
	 * @param  actual element type
	 * @param actual iterable object
	 * @return that iterable
	 */
	public static  That.AssertedIterable that(@Null Iterable actual) {
		class Tested extends That.What, That.AssertedIterable> implements That.AssertedIterable {}
		return new Tested().set(actual);
	}

	/**
	 * @param  actual element type
	 * @param actual stream object
	 * @return that iterable
	 */
	public static  That.AssertedIterable that(@Null java.util.stream.Stream actual) {
		class Tested extends That.What, That.AssertedIterable> implements That.AssertedIterable {}
		return new Tested().set(actual.collect(Collectors.toList()));
	}

	/**
	 * @param  actual component type
	 * @param actual array object
	 * @return that iterable
	 */
	@SafeVarargs
	public static  That.AssertedIterable that(T... actual) {
		class Tested extends That.What, That.AssertedIterable> implements That.AssertedIterable {}
		return new Tested().set(Arrays.asList(actual));
	}

	/**
	 * @param actual array object
	 * @return that iterable
	 */
	public static That.AssertedIterable that(int[] actual) {
		class Tested extends That.What,
				That.AssertedIterable> implements That.AssertedIterable {}
		return new Tested().set(Arrays.stream(actual).boxed().toList());
	}

	/**
	 * @param actual array object
	 * @return that iterable
	 */
	public static That.AssertedIterable that(long[] actual) {
		class Tested extends That.What,
				That.AssertedIterable> implements That.AssertedIterable {}
		return new Tested().set(Arrays.stream(actual).boxed().toList());
	}

	/**
	 * @param actual array object
	 * @return that iterable
	 */
	public static That.AssertedIterable that(double[] actual) {
		class Tested extends That.What,
				That.AssertedIterable> implements That.AssertedIterable {}
		return new Tested().set(Arrays.stream(actual).boxed().toList());
	}

	/**
	 * @param actual long value or null
	 * @return that double
	 */
	public static That.AssertedString that(@Null String actual) {
		class Tested extends That.What implements That.AssertedString {}
		return new Tested().set(actual);
	}

	/**
	 * @param actual long value or null
	 * @return that double
	 */
	public static That.AssertedBoolean that(@Null Boolean actual) {
		class Tested extends That.What implements That.AssertedBoolean {}
		return new Tested().set(actual);
	}

	/**
	 * @param actual long value or null
	 * @return that double
	 */
	public static That.AssertedDouble that(@Null Double actual) {
		class Tested extends That.What implements That.AssertedDouble {}
		return new Tested().set(actual);
	}

	/**
	 * @param actual long value or null
	 * @return that long
	 */
	public static That.AssertedLong that(@Null Long actual) {
		class Tested extends That.What implements That.AssertedLong {}
		return new Tested().set(actual);
	}

	/**
	 * @param actual int value or null
	 * @return that integer
	 */
	public static That.AssertedInt that(@Null Integer actual) {
		class Tested extends That.What implements That.AssertedInt {}
		return new Tested().set(actual);
	}

	/**
	 * @param actual short value or null
	 * @return that integer
	 */
	public static That.AssertedInt that(@Null Short actual) {
		return that(actual == null ? null : actual.intValue());
	}

	/**
	 * @param actual character value or null
	 * @return that integer
	 */
	public static That.AssertedInt that(@Null Character actual) {
		return that(actual == null ? null : (int) actual);
	}

	/**
	 * @param actual float value or null
	 * @return that double
	 */
	public static That.AssertedDouble that(@Null Float actual) {
		return that(actual == null ? null : actual.doubleValue());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy