Assert
Overview
Module
- package:
org.eclipse.dirigible.sdk.junit - source: junit/Assert.java
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 messageoverload for richer failure output. - Symmetric API:
assertTrue/assertFalse,assertEquals/assertNotEquals,assertNull/assertNotNull,fail.
Example Usage
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.
javapublic static void assertTrue(boolean condition);
Parameter Type Description conditionbooleanThe condition that must be true.Returns
- Type:
void
assertTrue() with message
Throws AssertionError with the supplied message if the condition is false.
javapublic static void assertTrue(String message, boolean condition);
Parameter Type Description messageStringThe failure message. conditionbooleanThe condition that must be true.Returns
- Type:
void
assertFalse()
Throws AssertionError if the condition is true.
javapublic static void assertFalse(boolean condition);
Parameter Type Description conditionbooleanThe condition that must be false.Returns
- Type:
void
assertFalse() with message
Throws AssertionError with the supplied message if the condition is true.
javapublic static void assertFalse(String message, boolean condition);
Parameter Type Description 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).
javapublic static void assertEquals(Object expected, Object actual);
Parameter Type Description 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.
javapublic static void assertEquals(String message, Object expected, Object actual);
Parameter Type Description 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).
javapublic static void assertNotEquals(Object unexpected, Object actual);
Parameter Type Description unexpectedObjectThe value that actualmust not equal.actualObjectThe actual value. Returns
- Type:
void
assertNotEquals() with message
Throws AssertionError with the supplied message if unexpected and actual are equal.
javapublic static void assertNotEquals(String message, Object unexpected, Object actual);
Parameter Type Description messageStringThe failure message prefix. unexpectedObjectThe value that actualmust not equal.actualObjectThe actual value. Returns
- Type:
void
assertNull()
Throws AssertionError if value is non-null.
javapublic static void assertNull(Object value);
Parameter Type Description valueObjectThe value that must be null.Returns
- Type:
void
assertNotNull()
Throws AssertionError if value is null.
javapublic static void assertNotNull(Object value);
Parameter Type Description valueObjectThe value that must be non-null. Returns
- Type:
void
fail()
Unconditionally throws AssertionError. Use to mark an unreachable branch or a pending test.
javapublic static void fail();Returns
- Type:
void
fail() with message
Unconditionally throws AssertionError with the supplied message.
javapublic static void fail(String message);
Parameter Type Description messageStringThe failure message. Returns
- Type:
void