You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generated assertions do not preserve generic types #92
What about passing generic parameters through? For instance given the following inputs, the current generator actually generates code that won't compile:
package com.api.dto;
import java.util.List;
public abstract class PagedResultApi<T> extends BaseApi {
public int pageNumber;
public int pageSize;
public int total;
public List<T> entities;
public PagedResultApi() {
}
}
Assertions are generated for entities that take an argument of type T, but T is not defined anywhere. For this case, defaulting to Object or even omitting the property entirely would be better than generating something we can't compile.
@javax.annotation.Generated(value="assertj-assertions-generator")
public abstract class AbstractPagedResultApiAssert<S extends AbstractPagedResultApiAssert<S, A>, A extends PagedResultApi> extends AbstractBaseApiAssert<S, A> {
// snip
/**
* Verifies that the actual PagedResultApi's entities contains the given T elements.
* @param entities the given elements that should be contained in actual PagedResultApi's entities.
* @return this assertion object.
* @throws AssertionError if the actual PagedResultApi's entities does not contain all given T elements.
*/
public S hasEntities(T... entities) {
// check that actual PagedResultApi we want to make assertions on is not null.
isNotNull();
// check that given T varargs is not null.
if (entities == null) failWithMessage("Expecting entities parameter not to be null.");
// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContains(info, actual.entities, entities);
// return the current assertion for method chaining
return myself;
}
Activity
joel-costigliola commentedon Dec 5, 2016
True, this requires the generator to be migrated to Java 8 in order to properly introspect Optional fields.
Initial work in adding full types to generation
Completed adding type-safety and introspection capabilities
Added type-safety and introspection capabilities
joel-costigliola commentedon Aug 28, 2017
Adding generic support is really complicated because generic bounds (
super,extends), @Nava2 and I have given it a fair try but there were some cases difficult to support (although I was able to generate properlyOptionalassertions), anyone interested can see the work in branch https://github.com/joel-costigliola/assertj-assertions-generator/tree/generics-supportjcogilvie commentedon Oct 23, 2017
What about passing generic parameters through? For instance given the following inputs, the current generator actually generates code that won't compile:
Assertions are generated for
entitiesthat take an argument of type T, but T is not defined anywhere. For this case, defaulting to Object or even omitting the property entirely would be better than generating something we can't compile.joel-costigliola commentedon Oct 23, 2017
At this point without generic support, what we can try is to replace the generic parameter by
Objectbut I'm not sure it is going to work.