Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Assertion compilation fails when class has a template field

未关闭
#182 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
50/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
java

调研方向

使用所示的 Maven 插件配置和 TemplateClassField 示例复现故障,然后检查创建断言类及其方法签名的生成器路径。完成的标准是生成的断言保留类型参数,hasModel(T model) 方法能够编译,并且回归测试覆盖模板字段场景。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Java
星标
72
派生
47
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

assertj/assertj-generator 的其他 Issue

查看 assertj/assertj-generator 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。