hasXXX assertions generate invalid code when XXX is an Iterable of an interface type.

Open
#133 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
tooling

Research direction

Start at org.assertj.assertions.generator.util.ClassUtil#getTypeDeclaration and compare its handling of captured class and interface bounds. Reproduce the generated AbstractBlahAssert for a List; done means hasSequences uses valid Java without the "interface" keyword.

Written by the indexing model from the issue text.

Description

Given a class:

public class Blah {
    private List<CharSequence> sequences;
    public List<CharSequence> getSequences() { return sequences; }
}

the AbstractBlahAssert is generated with code such as:

 public S hasSequences(interface java.lang.CharSequence... sequences) { ... }

(note the "interface" keyword in there.)

This is the result of org.assertj.assertions.generator.util.ClassUtil#getTypeDeclaration correctly handling situations where the contained type is a class:

String name = typeVariable.getName(); // capture#1-of ? extends class java.lang.String
name = removeAll(name, "capture#\\d+-of\\s+"); // extends class java.lang.String
name = removeAll(name, " class"); // extends java.lang.String
typeDeclaration.append(name); // List<? extends java.lang.String>

But not when it's an interface:

String name = typeVariable.getName(); // capture#1-of ? extends interface java.lang.CharSequence
name = removeAll(name, "capture#\\d+-of\\s+"); // extends interface java.lang.CharSequence
name = removeAll(name, " class"); // extends interface java.lang.CharSequence
typeDeclaration.append(name); // List<? extends interface java.lang.CharSequence>
Dominant language
Java
Stars
72
Forks
47
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from assertj/assertj-generator

All issues in assertj/assertj-generator

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.