Skip to content
Advertisement

ReaciveCrudRepository with Awaitility

writing tests and not sure how can one rewrite this code:

SomeEntity entity = Awaitility.await()
            .atMost(1, TimeUnit.SECONDS)
            .until({ -> repository.findById(id) }, { entry -> entry.isPresent() })
            .get()

to reactive one:

SomeEntity entity = Awaitility.await()
            .atMost(1, TimeUnit.SECONDS)
            .until({ -> repository.findById(id) }, { entry -> entry.???() })
            .block()

Note:

first findById() signature is: Optional findById(Long id)

second findById() signature is: Mono findById(ID id)

Advertisement

Answer

It is possible to do something like this:

Awaitility.await().atMost(1, SECONDS).until({ ->
                Transaction transaction = repository.findAll().blockFirst()
                transaction.currency == USD
                transaction.amount == 20})
Advertisement