Home > Net >  How to assert on a map value object member?
How to assert on a map value object member?

Time:01-24

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?

CodePudding user response:

Something like that?

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

CodePudding user response:

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

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