0

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!

noobie2023
  • 721
  • 8
  • 25

1 Answers1

1

This not possible with AssertJ.

Why not simply using if else?

if (number1 > number2) 
  assertThat(number3).isLessThan(number4);
else 
  assertThat(number3).isLessThan(number5);
Joel Costigliola
  • 6,308
  • 27
  • 35
  • Ah yes, you're correct. I should think out of the box. But I am also curious if there's an "assert-style" way to realize my intention. – noobie2023 Jul 24 '20 at 06:48
  • There is no elegant solution for this in AssertJ, we don't think adding such capability as the regular if-else constructs in java is still a better approach IMO. – Joel Costigliola Jul 25 '20 at 03:59