Skip to content

Commit

Permalink
Renamed isNotPresent to isEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
evant committed Sep 13, 2021
1 parent 9e75a5e commit 0867d3d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added
- Added `startsWith` and `endsWith` for `List`.
- Added `Optional<>.isPresent()`, `Optional<>.isNotPresent()`, `Optional<>.hasValue()`
- Added `Optional<>.isPresent()`, `Optional<>.isEmpty()`, `Optional<>.hasValue()`
- Added expanded set up apple targets for kotlin native.

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions assertk/src/jvmMain/kotlin/assertk/assertions/optional.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.util.*

/**
* Asserts that optional's value is present
* @see isNotPresent
* @see isEmpty
*/
fun <T> Assert<Optional<T>>.isPresent(): Assert<T> {
return transform { optional ->
Expand All @@ -22,7 +22,7 @@ fun <T> Assert<Optional<T>>.isPresent(): Assert<T> {
* Asserts optional's value is not present.
* @see isPresent
*/
fun Assert<Optional<*>>.isNotPresent() {
fun Assert<Optional<*>>.isEmpty() {
given { actual ->
if (!actual.isPresent) return
expected("optional to be empty but was:${show(actual.get())}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import assertk.all
import assertk.assertAll
import assertk.assertThat
import assertk.assertions.*
import com.willowtreeapps.opentest4k.AssertionFailedError
import org.junit.Test
import java.time.LocalDate
import java.time.Month
import java.util.*
import kotlin.random.Random
import kotlin.test.assertEquals
import kotlin.test.assertFails

Expand All @@ -30,13 +28,13 @@ internal class OptionalTest {
)
}

@Test fun isNotPresent_passes() {
assertThat(Optional.empty<Any>()).isNotPresent()
@Test fun isEmpty_passes() {
assertThat(Optional.empty<Any>()).isEmpty()
}

@Test fun isNotPresent_fails() {
@Test fun isEmpty_fails() {
val error = assertFails {
assertThat(Optional.of("test")).isNotPresent()
assertThat(Optional.of("test")).isEmpty()
}
assertEquals(
"expected optional to be empty but was:<\"test\">",
Expand Down Expand Up @@ -90,7 +88,7 @@ internal class OptionalTest {

// Asserting against findPersonById in data access logic:
assertAll {
assertThat(findPersonById(0)).isNotPresent()
assertThat(findPersonById(0)).isEmpty()
assertThat(findPersonById(personId)).isPresent().all {
prop(Person::id).isEqualTo(personId)
prop(Person::name).isEqualTo(personName)
Expand Down

0 comments on commit 0867d3d

Please sign in to comment.