Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For boolean properties, support "hasPropertyName(boolean expectedValue)" #125

Open
dancerjohn opened this issue May 17, 2018 · 1 comment

Comments

@dancerjohn
Copy link

Currently if a class has a boolean field / property (say hideLegend, the assertion generator produces two methods: isHideLegend() and isNotHideLegend. It would be really helpful to have an additional method hasHideLegend(boolean expectedValue). To keep with the BooleanAssert pattern, this might become hasHideLegendEqualTo(boolean) and hasHideLegendNotEqualTo(boolean). This is demonstrated by the example below:

private void testHelperMethod(MyAssertionClass instanceUnderTest, SomeInput input){
    boolean expectedHasLegend = // some code that uses input to determine expected legend;
    MyAssertionClassAssert assert = Assertions.assertThat(instanceUnderTest);

    if (expectedHadLengeng)
       assert.isHideLegend();
    else 
       assert.isNotHideLegend();
}

The above could become:

private void testHelperMethod(MyAssertionClass instanceUnderTest, SomeInput input){
    boolean expectedHasLegend = // some code that uses input to determine expected legend;
    Assertions.assertThat(instanceUnderTest)
      hasHideLegend(expectedHasLegend );
}
@joel-costigliola
Copy link
Member

This possible by changing the templates used to generate the assertions, see http://joel-costigliola.github.io/assertj/assertj-assertions-generator-maven-plugin.html#custom-templates.

In your case you would need to change these ones:

  <booleanAssertion>my_boolean_assert_template.txt</booleanAssertion>
  <booleanWrapperAssertion>my_Boolean_wrapper_assert_template.txt</booleanWrapperAssertion>

The easiest way to define your templates is to start from the existing ones available here:
https://github.com/joel-costigliola/assertj-assertions-generator/tree/master/src/main/resources/templates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants