CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-assertj--assertj-core

Fluent assertion library providing rich assertions for Java tests with expressive failure messages

Pending
Overview
Eval results
Files

basic-assertions.mddocs/

Basic Assertions

Basic assertions cover primitive types, objects, and fundamental assertion patterns that form the foundation of AssertJ testing.

Core Imports

import static org.assertj.core.api.Assertions.*;

Capabilities

Boolean Assertions

Assertions for boolean values and conditions.

BooleanAssert assertThat(boolean actual)
BooleanAssert assertThat(Boolean actual)

// Boolean-specific methods
BooleanAssert isTrue()
BooleanAssert isFalse()
BooleanAssert isEqualTo(boolean expected)
BooleanAssert isNotEqualTo(boolean expected)

Usage examples:

assertThat(true).isTrue();
assertThat(false).isFalse();
assertThat(user.isActive()).isTrue();
assertThat(validationResult.hasErrors()).isFalse();

Integer Assertions

Assertions for integer values with numeric comparisons.

IntegerAssert assertThat(int actual)
IntegerAssert assertThat(Integer actual)

// Integer-specific methods
IntegerAssert isPositive()
IntegerAssert isNegative()
IntegerAssert isZero()
IntegerAssert isNotZero()
IntegerAssert isEven()
IntegerAssert isOdd()
IntegerAssert isGreaterThan(int expected)
IntegerAssert isGreaterThanOrEqualTo(int expected)
IntegerAssert isLessThan(int expected)
IntegerAssert isLessThanOrEqualTo(int expected)
IntegerAssert isBetween(int start, int end)
IntegerAssert isStrictlyBetween(int start, int end)
IntegerAssert isCloseTo(int expected, Offset<Integer> offset)

Usage examples:

assertThat(42).isPositive().isEven();
assertThat(-5).isNegative().isOdd();
assertThat(score).isBetween(0, 100);
assertThat(actualValue).isCloseTo(expectedValue, offset(5));

Long Assertions

Assertions for long values with numeric comparisons.

LongAssert assertThat(long actual)
LongAssert assertThat(Long actual)

// Long-specific methods (same as Integer)
LongAssert isPositive()
LongAssert isNegative()
LongAssert isZero()
LongAssert isNotZero()
LongAssert isEven()
LongAssert isOdd()
LongAssert isGreaterThan(long expected)
LongAssert isGreaterThanOrEqualTo(long expected)
LongAssert isLessThan(long expected)
LongAssert isLessThanOrEqualTo(long expected)
LongAssert isBetween(long start, long end)
LongAssert isStrictlyBetween(long start, long end)
LongAssert isCloseTo(long expected, Offset<Long> offset)

Double and Float Assertions

Assertions for floating-point numbers with precision handling.

DoubleAssert assertThat(double actual)
DoubleAssert assertThat(Double actual)
FloatAssert assertThat(float actual)
FloatAssert assertThat(Float actual)

// Double/Float-specific methods
DoubleAssert isNaN()
DoubleAssert isNotNaN()
DoubleAssert isInfinite()
DoubleAssert isFinite()
DoubleAssert isPositive()
DoubleAssert isNegative()
DoubleAssert isZero()
DoubleAssert isNotZero()
DoubleAssert isCloseTo(double expected, Offset<Double> offset)
DoubleAssert isCloseTo(double expected, Percentage percentage)
DoubleAssert isBetween(double start, double end)
DoubleAssert isStrictlyBetween(double start, double end)

Usage examples:

assertThat(3.14159).isCloseTo(3.14, offset(0.01));
assertThat(percentage).isCloseTo(50.0, withinPercentage(5));
assertThat(Double.NaN).isNaN();
assertThat(1.0 / 0.0).isInfinite();

Character Assertions

Assertions for character values and Unicode properties.

CharacterAssert assertThat(char actual)
CharacterAssert assertThat(Character actual)

// Character-specific methods
CharacterAssert isEqualTo(char expected)
CharacterAssert isNotEqualTo(char expected)
CharacterAssert isGreaterThan(char expected)
CharacterAssert isLessThan(char expected)
CharacterAssert isUpperCase()
CharacterAssert isLowerCase()
CharacterAssert isDigit()
CharacterAssert isLetter()
CharacterAssert isLetterOrDigit()
CharacterAssert isWhitespace()

Usage examples:

assertThat('A').isUpperCase().isLetter();
assertThat('5').isDigit();
assertThat(' ').isWhitespace();
assertThat(firstChar).isGreaterThan('a').isLowerCase();

Byte and Short Assertions

Assertions for byte and short numeric types.

ByteAssert assertThat(byte actual)
ByteAssert assertThat(Byte actual)
ShortAssert assertThat(short actual) 
ShortAssert assertThat(Short actual)

// Byte/Short-specific methods (similar to Integer)
ByteAssert isPositive()
ByteAssert isNegative()
ByteAssert isZero()
ByteAssert isNotZero()
ByteAssert isGreaterThan(byte expected)
ByteAssert isLessThan(byte expected)
ByteAssert isBetween(byte start, byte end)

Object Assertions

Generic assertions for any object type.

ObjectAssert<T> assertThat(T actual)

// Object methods
ObjectAssert<T> isEqualTo(Object expected)
ObjectAssert<T> isNotEqualTo(Object expected)
ObjectAssert<T> isNull()
ObjectAssert<T> isNotNull()
ObjectAssert<T> isSameAs(Object expected)
ObjectAssert<T> isNotSameAs(Object expected)
ObjectAssert<T> isInstanceOf(Class<?> type)
ObjectAssert<T> isNotInstanceOf(Class<?> type)
ObjectAssert<T> isInstanceOfAny(Class<?>... types)
ObjectAssert<T> isExactlyInstanceOf(Class<?> type)
ObjectAssert<T> isIn(Object... values)
ObjectAssert<T> isIn(Iterable<?> values)
ObjectAssert<T> isNotIn(Object... values)
ObjectAssert<T> isNotIn(Iterable<?> values)
ObjectAssert<T> hasToString(String expected)
ObjectAssert<T> hasHashCode(int expected)

Usage examples:

assertThat(user).isNotNull().isInstanceOf(User.class);
assertThat(result).isSameAs(expectedInstance);
assertThat(status).isIn("ACTIVE", "PENDING", "INACTIVE");
assertThat(person).hasToString("Person{name='John', age=30}");

Class Assertions

Assertions for Class objects and type information.

ClassAssert assertThat(Class<?> actual)

// Class-specific methods
ClassAssert isAssignableFrom(Class<?> other)
ClassAssert isNotAssignableFrom(Class<?> other)
ClassAssert isAnnotation()
ClassAssert isNotAnnotation()
ClassAssert isInterface()
ClassAssert isNotInterface()
ClassAssert isFinal()
ClassAssert isNotFinal()
ClassAssert isAbstract()
ClassAssert isNotAbstract()
ClassAssert hasAnnotation(Class<? extends Annotation> annotation)
ClassAssert hasAnnotations(Class<? extends Annotation>... annotations)

Usage examples:

assertThat(ArrayList.class).isAssignableFrom(List.class);
assertThat(MyInterface.class).isInterface();
assertThat(MyEntity.class).hasAnnotation(Entity.class);

BigDecimal and BigInteger Assertions

Assertions for high-precision numeric types.

BigDecimalAssert assertThat(BigDecimal actual)
BigIntegerAssert assertThat(BigInteger actual)

// BigDecimal methods
BigDecimalAssert isCloseTo(BigDecimal expected, Offset<BigDecimal> offset)
BigDecimalAssert isCloseTo(BigDecimal expected, Percentage percentage)
BigDecimalAssert isZero()
BigDecimalAssert isNotZero()
BigDecimalAssert isPositive()
BigDecimalAssert isNegative()
BigDecimalAssert isBetween(BigDecimal start, BigDecimal end)

// BigInteger methods  
BigIntegerAssert isPositive()
BigIntegerAssert isNegative()
BigIntegerAssert isZero()
BigIntegerAssert isNotZero()
BigIntegerAssert isEven()
BigIntegerAssert isOdd()

Usage examples:

assertThat(new BigDecimal("3.14159"))
    .isCloseTo(new BigDecimal("3.14"), offset(new BigDecimal("0.01")));
    
assertThat(BigInteger.valueOf(1000000)).isPositive().isEven();

Common Assertion Patterns

All assertion types support these common methods:

// Description and context
AbstractAssert<SELF, ACTUAL> as(String description)
AbstractAssert<SELF, ACTUAL> as(String description, Object... args)
AbstractAssert<SELF, ACTUAL> describedAs(String description)
AbstractAssert<SELF, ACTUAL> describedAs(String description, Object... args)

// Custom validation
AbstractAssert<SELF, ACTUAL> satisfies(Consumer<ACTUAL> requirements)
AbstractAssert<SELF, ACTUAL> satisfiesAnyOf(Consumer<ACTUAL>... requirements)

// Failure control
AbstractAssert<SELF, ACTUAL> overridingErrorMessage(String newErrorMessage)
AbstractAssert<SELF, ACTUAL> withFailMessage(String failureMessage)

Usage examples:

assertThat(score)
    .as("User's final exam score")
    .isBetween(0, 100);
    
assertThat(user)
    .satisfies(u -> {
        assertThat(u.getName()).isNotBlank();
        assertThat(u.getAge()).isGreaterThan(0);
    });

Types

// Numeric offset for comparisons
class Offset<T extends Number> {
    static Offset<Double> offset(Double value)
    static Offset<Float> offset(Float value)
    static Offset<Integer> offset(Integer value)
    static Offset<Long> offset(Long value)
    static Offset<BigDecimal> offset(BigDecimal value)
}

// Percentage for comparisons
class Percentage {
    static Percentage withPercentage(Double percentage)
    static Percentage withPercentage(Integer percentage)
}

// Consumer interface for custom validation
interface Consumer<T> {
    void accept(T t);
}

Install with Tessl CLI

npx tessl i tessl/maven-org-assertj--assertj-core

docs

advanced.md

basic-assertions.md

collections.md

conditions.md

dates-times.md

exceptions.md

index.md

soft-assertions.md

strings.md

tile.json