Skip to content

Commit

Permalink
Don't return a value from assertNotNull
Browse files Browse the repository at this point in the history
Because of kotlin smart casts, there is no need to return a
non-nullable value from `assertNotNull` methods

Issue: junit-team#1866
  • Loading branch information
awelless committed Aug 25, 2023
1 parent 19922d6 commit eccb259
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,12 @@ fun assertNull(actual: Any?, messageSupplier: () -> String) {
* @see Assertions.assertNotNull
*/
@API(since = "5.10", status = EXPERIMENTAL)
fun <T> assertNotNull(actual: T?): T {
fun assertNotNull(actual: Any?) {
contract {
returns() implies (actual != null)
}

Assertions.assertNotNull(actual)
return actual!!
}

/**
Expand All @@ -201,13 +200,12 @@ fun <T> assertNotNull(actual: T?): T {
* @see Assertions.assertNotNull
*/
@API(since = "5.10", status = EXPERIMENTAL)
fun <T> assertNotNull(actual: T?, message: String): T {
fun assertNotNull(actual: Any?, message: String) {
contract {
returns() implies (actual != null)
}

Assertions.assertNotNull(actual, message)
return actual!!
}

/**
Expand All @@ -223,15 +221,14 @@ fun <T> assertNotNull(actual: T?, message: String): T {
* @see Assertions.assertNotNull
*/
@API(since = "5.10", status = EXPERIMENTAL)
fun <T> assertNotNull(actual: T?, messageSupplier: () -> String): T {
fun assertNotNull(actual: Any?, messageSupplier: () -> String) {
contract {
returns() implies (actual != null)

callsInPlace(messageSupplier, AT_MOST_ONCE)
}

Assertions.assertNotNull(actual, messageSupplier)
return actual!!
}

/**
Expand Down

0 comments on commit eccb259

Please sign in to comment.