noobie2023
noobie2023

Reputation: 783

How to write conditional "assertThat" using assertj.core.api.Assertions?

Hey guys I have the following code:

# number 1, 2, 3 are all "long" type
Assertions.assertThat(number1).isGreaterThan(number2),
Assertions.assertThat(number3).isLessThan(number4)

And I want to achieve something like:

if Assertions.assertThat(number1).isGreaterThan(number2) success, 
then skip:
   Assertions.assertThat(number3).isLessThan(number4)
else evaluate:
   Assertions.assertThat(number3).isLessThan(number4)

How can I write the code for this idea? Thanks!

Upvotes: 0

Views: 1639

Answers (1)

Joel Costigliola
Joel Costigliola

Reputation: 7066

This not possible with AssertJ.

Why not simply using if else?

if (number1 > number2) 
  assertThat(number3).isLessThan(number4);
else 
  assertThat(number3).isLessThan(number5);

Upvotes: 1

Related Questions