Package io.jpostman.junit
Class JUnitAssertions<T extends JUnitAssertions<T>>
- java.lang.Object
-
- io.jpostman.junit.JUnitAssertions<T>
-
- All Implemented Interfaces:
JPostmanAssertions<JUnitContext,T>
- Direct Known Subclasses:
JUnitSoftAssertions
public class JUnitAssertions<T extends JUnitAssertions<T>> extends Object implements JPostmanAssertions<JUnitContext,T>
Fluent JUnit assertions with optional secure log output.Hard assertions run immediately. Soft assertions override the assertion execution hook and verify collected failures later.
-
-
Field Summary
Fields Modifier and Type Field Description protected JUnitContextcontextprotected booleanincludeLogprotected booleanstatusCodeAsserted
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <V> TallMatch(String path, Class<V> type, BiPredicate<V,Integer> predicate, String message)Asserts that every value returned by the response path matches the predicate.TallMatch(String path, BiPredicate<Object,Integer> predicate, String message)Asserts that every numeric value returned by the response path matches the predicate.TallMatch(String path, Predicate<Number> predicate, String message)Asserts that every numeric value returned by the response path matches the predicate.protected TassertWithLog(Runnable assertion)Executes an assertion and wraps failures with optional secure log context.JUnitContextcontext()Returns the owning context for continuing the fluent chain.Texists(String path)Asserts that the current secure response contains the given path.Texists(String path, String message)Asserts that the current secure response contains the given path.TisEqual(Object actual, Object expected)Asserts that the actual value is equal to the expected value.TisEqual(Object actual, Object expected, String message)Asserts that the actual value is equal to the expected value.TisFalse(boolean condition)Asserts that the condition is false.TisFalse(boolean condition, String message)Asserts that the condition is false.TisNotEqual(Object actual, Object expected)Asserts that the actual value is not equal to the expected value.TisNotEqual(Object actual, Object expected, String message)Asserts that the actual value is not equal to the expected value.TisNotNull(Object value)Asserts that the value is not null.TisNotNull(Object value, String message)Asserts that the value is not null.TisNull(Object value)Asserts that the value is null.TisNull(Object value, String message)Asserts that the value is null.TisTrue(boolean condition)Asserts that the condition is true.TisTrue(boolean condition, String message)Asserts that the condition is true.TnotExists(String path)Asserts that the current secure response does not contain the given path.TnotExists(String path, String message)Asserts that the current secure response does not contain the given path.TpathEquals(String path, Object expected)Asserts that the value at the given response path is equal to the expected value.TpathEquals(String path, Object expected, String message)Asserts that the value at the given response path is equal to the expected value.TpathNotNull(String path)Asserts that the value at the given response path is not null.TpathNotNull(String path, String message)Asserts that the value at the given response path is not null.protected Tself()TstatusCode(int expected)Asserts that the current secure response has the expected status code.TstatusCode(int expected, String message)Asserts that the current secure response has the expected status code.JUnitContextverify()Verifies status code200and returns the test context.JUnitContextverify(int statusCode)Verifies the expected status code and returns the test context.protected AssertionErrorwrap(AssertionError error)Wraps an assertion error with optional secure log context.
-
-
-
Field Detail
-
context
protected final JUnitContext context
-
includeLog
protected final boolean includeLog
-
statusCodeAsserted
protected boolean statusCodeAsserted
-
-
Method Detail
-
self
protected T self()
-
context
public JUnitContext context()
Returns the owning context for continuing the fluent chain.- Specified by:
contextin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Returns:
- owning JUnit context
-
isEqual
public T isEqual(Object actual, Object expected)
Asserts that the actual value is equal to the expected value.- Specified by:
isEqualin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
actual- the actual valueexpected- the expected value- Returns:
- this assertion helper
-
isEqual
public T isEqual(Object actual, Object expected, String message)
Asserts that the actual value is equal to the expected value.- Specified by:
isEqualin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
actual- the actual valueexpected- the expected valuemessage- custom failure message- Returns:
- this assertion helper
-
isNotEqual
public T isNotEqual(Object actual, Object expected)
Asserts that the actual value is not equal to the expected value.- Specified by:
isNotEqualin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
actual- the actual valueexpected- the expected value- Returns:
- this assertion helper
-
isNotEqual
public T isNotEqual(Object actual, Object expected, String message)
Asserts that the actual value is not equal to the expected value.- Specified by:
isNotEqualin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
actual- the actual valueexpected- the expected valuemessage- custom failure message- Returns:
- this assertion helper
-
isTrue
public T isTrue(boolean condition)
Asserts that the condition is true.- Specified by:
isTruein interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
condition- the condition to check- Returns:
- this assertion helper
-
isTrue
public T isTrue(boolean condition, String message)
Asserts that the condition is true.- Specified by:
isTruein interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
condition- the condition to checkmessage- custom failure message- Returns:
- this assertion helper
-
isFalse
public T isFalse(boolean condition)
Asserts that the condition is false.- Specified by:
isFalsein interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
condition- the condition to check- Returns:
- this assertion helper
-
isFalse
public T isFalse(boolean condition, String message)
Asserts that the condition is false.- Specified by:
isFalsein interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
condition- the condition to checkmessage- custom failure message- Returns:
- this assertion helper
-
isNull
public T isNull(Object value)
Asserts that the value is null.- Specified by:
isNullin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
value- the value to check- Returns:
- this assertion helper
-
isNull
public T isNull(Object value, String message)
Asserts that the value is null.- Specified by:
isNullin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
value- the value to checkmessage- custom failure message- Returns:
- this assertion helper
-
isNotNull
public T isNotNull(Object value)
Asserts that the value is not null.- Specified by:
isNotNullin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
value- the value to check- Returns:
- this assertion helper
-
isNotNull
public T isNotNull(Object value, String message)
Asserts that the value is not null.- Specified by:
isNotNullin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
value- the value to checkmessage- custom failure message- Returns:
- this assertion helper
-
statusCode
public T statusCode(int expected)
Asserts that the current secure response has the expected status code.- Specified by:
statusCodein interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
expected- the expected status code- Returns:
- this assertion helper
-
statusCode
public T statusCode(int expected, String message)
Asserts that the current secure response has the expected status code.- Specified by:
statusCodein interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
expected- the expected status codemessage- custom failure message- Returns:
- this assertion helper
-
exists
public T exists(String path)
Asserts that the current secure response contains the given path.- Specified by:
existsin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
path- the response path to check- Returns:
- this assertion helper
-
exists
public T exists(String path, String message)
Asserts that the current secure response contains the given path.- Specified by:
existsin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
path- the response path to checkmessage- custom failure message- Returns:
- this assertion helper
-
notExists
public T notExists(String path)
Asserts that the current secure response does not contain the given path.- Specified by:
notExistsin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
path- the response path to check- Returns:
- this assertion helper
-
notExists
public T notExists(String path, String message)
Asserts that the current secure response does not contain the given path.- Specified by:
notExistsin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
path- the response path to checkmessage- custom failure message- Returns:
- this assertion helper
-
pathEquals
public T pathEquals(String path, Object expected)
Asserts that the value at the given response path is equal to the expected value.- Specified by:
pathEqualsin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
path- the response path to checkexpected- the expected value- Returns:
- this assertion helper
-
pathEquals
public T pathEquals(String path, Object expected, String message)
Asserts that the value at the given response path is equal to the expected value.- Specified by:
pathEqualsin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
path- the response path to checkexpected- the expected valuemessage- custom failure message- Returns:
- this assertion helper
-
pathNotNull
public T pathNotNull(String path)
Asserts that the value at the given response path is not null.- Specified by:
pathNotNullin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
path- the response path to check- Returns:
- this assertion helper
-
pathNotNull
public T pathNotNull(String path, String message)
Asserts that the value at the given response path is not null.- Specified by:
pathNotNullin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
path- the response path to checkmessage- custom failure message- Returns:
- this assertion helper
-
allMatch
public T allMatch(String path, Predicate<Number> predicate, String message)
Asserts that every numeric value returned by the response path matches the predicate.- Specified by:
allMatchin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
path- response path that resolves to a list of numeric valuespredicate- predicate applied to each valuemessage- custom failure message. Use {} for the value.- Returns:
- this assertion helper
-
allMatch
public T allMatch(String path, BiPredicate<Object,Integer> predicate, String message)
Asserts that every numeric value returned by the response path matches the predicate.- Specified by:
allMatchin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
path- response path that resolves to a list of numeric valuespredicate- predicate applied to each value and indexmessage- custom failure message. Use {} placeholders for value and index.- Returns:
- this assertion helper
-
allMatch
public <V> T allMatch(String path, Class<V> type, BiPredicate<V,Integer> predicate, String message)
Asserts that every value returned by the response path matches the predicate.- Specified by:
allMatchin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Type Parameters:
V- expected value type- Parameters:
path- response path that resolves to a list of valuestype- expected value typepredicate- predicate applied to each value and indexmessage- custom failure message. Use {} placeholders for value and index.- Returns:
- this assertion helper
-
verify
public JUnitContext verify()
Verifies status code200and returns the test context.This allows assertion chains to finish back on the context.
- Specified by:
verifyin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Returns:
- current test context
-
verify
public JUnitContext verify(int statusCode)
Verifies the expected status code and returns the test context.In hard mode, this fails immediately on status code mismatch. In soft mode, collected soft assertions are verified and the expected status code is added only when no status code assertion was already collected.
- Specified by:
verifyin interfaceJPostmanAssertions<JUnitContext,T extends JUnitAssertions<T>>- Parameters:
statusCode- expected status code- Returns:
- current test context
-
assertWithLog
protected T assertWithLog(Runnable assertion)
Executes an assertion and wraps failures with optional secure log context.- Parameters:
assertion- assertion to execute- Returns:
- this assertion helper
-
wrap
protected AssertionError wrap(AssertionError error)
Wraps an assertion error with optional secure log context.- Parameters:
error- original assertion error- Returns:
- wrapped assertion error
-
-