简体   繁体   中英

How to assert on a map value object member?

Given are a map like this:

Map<String, BestClass> myMap = new HashMap<>();

and a class BestClass like this:

class BestClass{
    int a;
    int b;
}

Now, this map is being populated during the program process.

Is there a clean way, not including looping over the map keys , to assert that, for example, none of the b values of the map object values are 0?

Something like that?

assertThat(list)
    .extracting("BestClass")
    .contains(entry("foo1", "bar1"), entry("foo2", "bar2"));

I found a way. If you have any better - please suggest.

assertThat(myMap.values()).extracting(BestClass::getB).noneMatch(0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM