How to check boolean getter with AssertJ?
Asked Answered
V

2

7

It looks very cool

assertThat(yoda).is(jedi);

until you don't know what is yoda and jedi. But suppose

yoda instanceof Person

where

interface Person {
    boolean isJedi();
}

Then how actually check isJedi with AssertJ?

In conventional JUnit I would write

assertTrue( yoda.isJedi() );

but what in AssertJ?

Vend answered 30/8, 2016 at 13:1 Comment(0)
U
15
assertThat(yoda.isJedi()).isTrue()
Uranology answered 30/8, 2016 at 13:11 Comment(2)
Great! But why examples demonstrate different? May be I can rapidly compose Condition for yoda somehow?Vend
Conditions are used to express more complex checks that you want to reuse, in your case it is a simple boolean check that is (hopefully) already supported.Ogg
P
1

assertThat(yoda.isJedi()).isEqualTo(true);

Politian answered 9/3, 2023 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.