Skip to content

Tag: assertj

Java does not catch exception

I am trying to implement lambda expression for constructor. My constructor can throw an IllegalArgumentException. I tried different ways. First way is just calling lambda expression: It works perfectly fine, I can catch Exception and then parse it. The problem occurs when I try to use my own interface: and th…

Ignoring only embedded member in AssertJ

I have two classes to test with JUnit/Mockito: Then in my test class, using AssertJ: The problem is that the name sk is in both classes, and I need to ignore it only in ClassA, not in ClassB. Is this possible in AssertJ? Answer According to the ignoringFields javadoc: Nested fields can be specified like this:…

How to perform deeper matching of keys and values with assertj

Say I have a class like this: And later, a Map Using assertj, what is the best way to test that characterAges includes the “Frodo” character? For the age, I can do: And I know I could do: But then I lose my fluency. What I really want it something like this: Or even better, so that I can make