November 22, 2020


Mindblow: Assert nested objects with AssertJ

Use one assertion to check a deep nested object for specific values


🤯 Assert nested objects with AssertJ

AssertJ is very nice for test-driven-development or commonly testing in Java and today I figured out a mindblowing feature. And to be honest, if I had read the documentation, I would have known it already 😎

class Item {
  // ...

class Table {
  int legs;
  String color;
  List<Item> servedItems;

  // ... Ctor, Getter, Setter

Table table = new Table(4, "brown", Arrays.asList(new Item(/* ... */), new Item(/* ... */)));

    .extracting("color", "servedItems.size")
    .containsExactly("brown", 2);

In the example you can see: It's possible to access the item list in table as String in dot notation. 🤯 Nice job girls and boys from AssertJ


I am a software developer who spends most of his spare time working on open source projects. I also like taking pictures and playing table football.