Skip to content

add properties ${propertySimpleType} and ${propertyAssertType} so we can generate nicer navigation assertion methods #67

Description

@jstrachan

there's a back ground issue from our project here:
fabric8io/fabric8#5925

the general idea is we want to generate helper methods in the generated Assert classes to aid navigation through deeply nested models. The background is the Kubernetes model is very deeply nested.

For a complex model where you want to write assertions like:

assertThat(foo.getBar().getThing()).isNotNull()

the problem is the getBar() could return null as could the getThing().

So we wanna do this instead...

assertThat(foo).bar().thing().isNotNull();

where each property method bar() and thing() are kinda like the hasBar() function thats generated OOTB, only it returns the assertThat() of the value. So the last assertion - .isNotNull() could be anything really; isEqualTo() or whatever.

e.g. we generate functions like this:

class FooAssert ... {

   public BarAssert bar() {
      isNotNull();

      return (BarAssert) assertThat(actual.getBar()).describedAs(toString() + ".bar");
  }
}

I've managed to implement the above in our project using the extensible templates (thanks for that!) - but to do so I needed to add the above 2 properties to the templates. Actually as of writing only the 2nd one is required but figured I may as well submit a PR for both ;)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions