Skip to content

Commit

Permalink
Add loggable exception assert for no args (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 authored Nov 9, 2021
1 parent fc7c8f2 commit 797cb7a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-607.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: feature
feature:
description: '`LoggableExceptionAssert` now contains a `hasNoArgs` method for asserting
that an exception has no args.'
links:
- https://github.com/palantir/safe-logging/pull/607
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private LoggableExceptionAssert(T actual) {
}

/**
* Verifies that the actual group contains exactly the given values and nothing else, <b>in any order</b>.<br>
* Verifies that the actual exception contains exactly the given args and nothing else, <b>in any order</b>.<br>
*
* @param args the given arguments.
* @return {@code this} assertion object
Expand Down Expand Up @@ -68,7 +68,7 @@ public LoggableExceptionAssert<T> hasArgs(Arg<?>... args) {
}

/**
* Verifies that the actual group contains the given values, in any order.
* Verifies that the actual exception contains the given args, in any order.
*
* @param args the given arguments.
* @return {@code this} assertion object
Expand All @@ -85,6 +85,16 @@ public LoggableExceptionAssert<T> containsArgs(Arg<?>... args) {
return this;
}

/**
* Verifies that the actual exception does not contain any args.
*/
public LoggableExceptionAssert<T> hasNoArgs() {
isNotNull();

argsAssert.isEmpty();
return this;
}

public LoggableExceptionAssert<T> hasLogMessage(String logMessage) {
isNotNull();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ public void testIllegalArgumentException(LoggableExceptionAssert<SafeIllegalArgu
}

public void testNullPointerException(LoggableExceptionAssert<SafeNullPointerException> assertion) {
assertion.isInstanceOf(SafeNullPointerException.class).hasMessage("").hasExactlyArgs();
assertion
.isInstanceOf(SafeNullPointerException.class)
.hasMessage("")
.hasExactlyArgs()
.hasNoArgs();
}

public void testIllegalStateException(LoggableExceptionAssert<SafeIllegalStateException> assertion) {
assertion.isInstanceOf(SafeIllegalStateException.class).hasMessage("").hasExactlyArgs();
assertion
.isInstanceOf(SafeIllegalStateException.class)
.hasMessage("")
.hasExactlyArgs()
.hasNoArgs();
}

public void testLoggableException(LoggableExceptionAssert<LoggableException> assertion) {
Expand Down

0 comments on commit 797cb7a

Please sign in to comment.