Skip to content

Assert

Overview

Module

xUnit-style assertion helpers that throw AssertionError on failure, so they integrate with every JVM test runner without further wiring (JUnit 5, TestNG, Spock, plain @Test methods invoked from a controller). Suitable for smoke tests and ad-hoc verification scripts written as plain Java client code inside Dirigible.

Lightweight helper — not a JUnit replacement

For full-blown test suites — fixtures, parameterised tests, lifecycle hooks, parallel execution — pull JUnit Jupiter into the project and use org.junit.jupiter.api.Assertions directly. This class deliberately covers only the small overlap appropriate for in-platform smoke tests.

Key Features

  • No runner required: Each helper throws plain AssertionError, so it works inside a controller, a scheduled job, a script, or any test runner.
  • Optional message: Every helper has a one-arg form and a String message overload for richer failure output.
  • Symmetric API: assertTrue / assertFalse, assertEquals / assertNotEquals, assertNull / assertNotNull, fail.

Example Usage

java
import static org.eclipse.dirigible.sdk.junit.Assert.*;

public class Smoke {

    public static void run() {
        assertEquals("answer is 42", 42, compute());

        String token = login("admin", "pwd");
        assertNotNull(token);

        Result result = fetch(token);
        assertTrue("result should be ok", result.isOk());
    }
}

Methods

assertTrue()

Throws AssertionError if the condition is false.

java
public static void assertTrue(boolean condition);
ParameterTypeDescription
conditionbooleanThe condition that must be true.

Returns

  • Type: void

assertTrue() with message

Throws AssertionError with the supplied message if the condition is false.

java
public static void assertTrue(String message, boolean condition);
ParameterTypeDescription
messageStringThe failure message.
conditionbooleanThe condition that must be true.

Returns

  • Type: void

assertFalse()

Throws AssertionError if the condition is true.

java
public static void assertFalse(boolean condition);
ParameterTypeDescription
conditionbooleanThe condition that must be false.

Returns

  • Type: void

assertFalse() with message

Throws AssertionError with the supplied message if the condition is true.

java
public static void assertFalse(String message, boolean condition);
ParameterTypeDescription
messageStringThe failure message.
conditionbooleanThe condition that must be false.

Returns

  • Type: void

assertEquals()

Throws AssertionError if expected and actual are not equal (uses Objects.equals, so two nulls compare equal).

java
public static void assertEquals(Object expected, Object actual);
ParameterTypeDescription
expectedObjectThe expected value.
actualObjectThe actual value.

Returns

  • Type: void

assertEquals() with message

Throws AssertionError with the supplied message if expected and actual are not equal.

java
public static void assertEquals(String message, Object expected, Object actual);
ParameterTypeDescription
messageStringThe failure message prefix.
expectedObjectThe expected value.
actualObjectThe actual value.

Returns

  • Type: void

assertNotEquals()

Throws AssertionError if unexpected and actual are equal (uses Objects.equals).

java
public static void assertNotEquals(Object unexpected, Object actual);
ParameterTypeDescription
unexpectedObjectThe value that actual must not equal.
actualObjectThe actual value.

Returns

  • Type: void

assertNotEquals() with message

Throws AssertionError with the supplied message if unexpected and actual are equal.

java
public static void assertNotEquals(String message, Object unexpected, Object actual);
ParameterTypeDescription
messageStringThe failure message prefix.
unexpectedObjectThe value that actual must not equal.
actualObjectThe actual value.

Returns

  • Type: void

assertNull()

Throws AssertionError if value is non-null.

java
public static void assertNull(Object value);
ParameterTypeDescription
valueObjectThe value that must be null.

Returns

  • Type: void

assertNotNull()

Throws AssertionError if value is null.

java
public static void assertNotNull(Object value);
ParameterTypeDescription
valueObjectThe value that must be non-null.

Returns

  • Type: void

fail()

Unconditionally throws AssertionError. Use to mark an unreachable branch or a pending test.

java
public static void fail();

Returns

  • Type: void

fail() with message

Unconditionally throws AssertionError with the supplied message.

java
public static void fail(String message);
ParameterTypeDescription
messageStringThe failure message.

Returns

  • Type: void

Released under the EPL-2.0 License.