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

Assertion compilation fails when class has a template field #182

Open
dmitry-weirdo opened this issue Jul 13, 2021 · 0 comments
Open

Assertion compilation fails when class has a template field #182

dmitry-weirdo opened this issue Jul 13, 2021 · 0 comments

Comments

@dmitry-weirdo
Copy link

dmitry-weirdo commented Jul 13, 2021

Generations plugin versions in maven:

            <plugin>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-assertions-generator-maven-plugin</artifactId>
                <version>2.2.0</version>

Test class

package testassertj;

import lombok.Data;

@Data
public class TemplateClassField<T> {

    protected T model;
}

Generated assertion class:

package testassertj;

import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.util.Objects;

/**
 * {@link TemplateClassField} specific assertions - Generated by CustomAssertionGenerator.
 */
@javax.annotation.Generated(value="assertj-assertions-generator")
public class TemplateClassFieldAssert extends AbstractObjectAssert<TemplateClassFieldAssert, TemplateClassField> {

  /**
   * Creates a new <code>{@link TemplateClassFieldAssert}</code> to make assertions on actual TemplateClassField.
   * @param actual the TemplateClassField we want to make assertions on.
   */
  public TemplateClassFieldAssert(TemplateClassField actual) {
    super(actual, TemplateClassFieldAssert.class);
  }

  /**
   * An entry point for TemplateClassFieldAssert to follow AssertJ standard <code>assertThat()</code> statements.<br>
   * With a static import, one can write directly: <code>assertThat(myTemplateClassField)</code> and get specific assertion with code completion.
   * @param actual the TemplateClassField we want to make assertions on.
   * @return a new <code>{@link TemplateClassFieldAssert}</code>
   */
  @org.assertj.core.util.CheckReturnValue
  public static TemplateClassFieldAssert assertThat(TemplateClassField actual) {
    return new TemplateClassFieldAssert(actual);
  }

  /**
   * Verifies that the actual TemplateClassField's model is equal to the given one.
   * @param model the given model to compare the actual TemplateClassField's model to.
   * @return this assertion object.
   * @throws AssertionError - if the actual TemplateClassField's model is not equal to the given one.
   */
  public TemplateClassFieldAssert hasModel(T model) {
    // check that actual TemplateClassField we want to make assertions on is not null.
    isNotNull();

    // overrides the default error message with a more explicit one
    String assertjErrorMessage = "\nExpecting model of:\n  <%s>\nto be:\n  <%s>\nbut was:\n  <%s>";

    // null safe check
    T actualModel = actual.getModel();
    if (!Objects.areEqual(actualModel, model)) {
      failWithMessage(assertjErrorMessage, actual, model, actualModel);
    }

    // return the current assertion for method chaining
    return this;
  }

}

Compilation fails on public TemplateClassFieldAssert hasModel(T model) { method:

[ERROR] /C:/java/myproject/target/generated-test-sources/assertj-assertions/testassertj/TemplateClassFieldAssert.java:[37,44] cannot find symbol
[ERROR]   symbol:   class T
[ERROR]   location: class testassertj.TemplateClassFieldAssert

Expected behaviour:
Generated assert class is also <T> templated, so that hasModel(T model) compiles successfully.

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

1 participant