Assertion compilation fails when class has a template field
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 50/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- java
- Domain
- build-system, testing
Research direction
Reproduce the failure with the shown Maven plugin configuration and TemplateClassField example, then inspect the generator path that creates the assertion class and its method signatures. Done means the generated assertion preserves the type parameter, the hasModel(T model) method compiles, and a regression test covers the template field case.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Java
- Stars
- 72
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from assertj/assertj-generator
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
assertj/assertj-generator#278 ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
assertj/assertj-generator#220 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
assertj/assertj-generator#219 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
assertj/assertj-generator#204 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
assertj/assertj-generator#197 · 7 comments ·
All issues in assertj/assertj-generator
Similar issues
-
certification
Difficulty 1/5 Under an hour Newbie friendliness 80/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
[BUG] ECR GetAuthorizationToken returns a proxyEndpoint for the default region, not the request's Openbug ecr
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Needs: Triage Type: Feature request
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
AntennaPod/AntennaPod#8794 ·
-
agentic-workflows
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
github/copilot-sdk#2760 ·