assertj-assertions-generator icon indicating copy to clipboard operation
assertj-assertions-generator copied to clipboard

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

Open martinlau opened this issue 6 years ago • 1 comments

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>

martinlau avatar Sep 30 '19 06:09 martinlau

Thanks for reporting this ! I'm a bit afraid the generator has fallen under my radar, super busy at the moment :(

I'll try to review your PR in the next few weeks, ping me if I don't!

joel-costigliola avatar Oct 01 '19 01:10 joel-costigliola