Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #133 - Support interface types in parameterised types #134

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ public static String getTypeDeclaration(TypeToken<?> type) {
String name = typeVariable.getName();
name = removeAll(name, "capture#\\d+-of\\s+");
name = removeAll(name, " class");
name = removeAll(name, " interface");
typeDeclaration.append(name);
} else if (!isJavaLangType(type)) {
// it's a normal class but not in java.lang => add the package name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Player {
private List<int[]> points = new ArrayList<>();
private String[] previousTeamNames = {};
public List<? extends Team> previousTeams = new ArrayList<>();
private List<? extends CharSequence> previousNames = new ArrayList<>();

private boolean bad;

Expand Down Expand Up @@ -198,6 +199,10 @@ public float getSize() {
return size;
}

public List<? extends CharSequence> getPreviousNames() {
return previousNames;
}

@Override
public String toString() {
return format("%s[%s %s, team=%s]", getClass().getSimpleName(), name.getFirst(), name.getLast(), team);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void should_build_player_class_description() throws Exception {
assertThat(classDescription.getFullyQualifiedClassName()).isEqualTo("org.assertj.assertions.generator.data.nba.Player");
assertThat(classDescription.getFullyQualifiedOuterClassName()).isEqualTo("org.assertj.assertions.generator.data.nba.Player");
assertThat(classDescription.getFullyQualifiedClassNameWithoutGenerics()).isEqualTo(classDescription.getFullyQualifiedClassName());
assertThat(classDescription.getGettersDescriptions()).hasSize(19);
assertThat(classDescription.getGettersDescriptions()).hasSize(20);
assertThat(classDescription.getAssertClassName()).isEqualTo("PlayerAssert");
assertThat(classDescription.getAssertClassFilename()).isEqualTo("PlayerAssert.java");
assertThat(classDescription.getFullyQualifiedAssertClassName()).isEqualTo("org.assertj.assertions.generator.data.nba.PlayerAssert");
Expand Down
153 changes: 153 additions & 0 deletions src/test/resources/AbstractPlayerAssert.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,159 @@ public abstract class AbstractPlayerAssert<S extends AbstractPlayerAssert<S, A>,
return myself;
}

/**
* Verifies that the actual Player's previousNames contains the given java.lang.CharSequence elements.
* @param previousNames the given elements that should be contained in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames does not contain all given java.lang.CharSequence elements.
*/
public S hasPreviousNames(java.lang.CharSequence... previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence varargs is not null.
if (previousNames == null) failWithMessage("Expecting previousNames 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.getPreviousNames(), previousNames);

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player's previousNames contains the given java.lang.CharSequence elements in Collection.
* @param previousNames the given elements that should be contained in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames does not contain all given java.lang.CharSequence elements.
*/
public S hasPreviousNames(java.util.Collection<? extends java.lang.CharSequence> previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence collection is not null.
if (previousNames == null) {
failWithMessage("Expecting previousNames parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}

// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContains(info, actual.getPreviousNames(), previousNames.toArray());

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player's previousNames contains <b>only</b> the given java.lang.CharSequence elements and nothing else in whatever order.
* @param previousNames the given elements that should be contained in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames does not contain all given java.lang.CharSequence elements.
*/
public S hasOnlyPreviousNames(java.lang.CharSequence... previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence varargs is not null.
if (previousNames == null) failWithMessage("Expecting previousNames parameter not to be null.");

// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContainsOnly(info, actual.getPreviousNames(), previousNames);

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player's previousNames contains <b>only</b> the given java.lang.CharSequence elements in Collection and nothing else in whatever order.
* @param previousNames the given elements that should be contained in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames does not contain all given java.lang.CharSequence elements.
*/
public S hasOnlyPreviousNames(java.util.Collection<? extends java.lang.CharSequence> previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence collection is not null.
if (previousNames == null) {
failWithMessage("Expecting previousNames parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}

// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContainsOnly(info, actual.getPreviousNames(), previousNames.toArray());

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player's previousNames does not contain the given java.lang.CharSequence elements.
*
* @param previousNames the given elements that should not be in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames contains any given java.lang.CharSequence elements.
*/
public S doesNotHavePreviousNames(java.lang.CharSequence... previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence varargs is not null.
if (previousNames == null) failWithMessage("Expecting previousNames parameter not to be null.");

// check with standard error message (use overridingErrorMessage before contains to set your own message).
Iterables.instance().assertDoesNotContain(info, actual.getPreviousNames(), previousNames);

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player's previousNames does not contain the given java.lang.CharSequence elements in Collection.
*
* @param previousNames the given elements that should not be in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames contains any given java.lang.CharSequence elements.
*/
public S doesNotHavePreviousNames(java.util.Collection<? extends java.lang.CharSequence> previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence collection is not null.
if (previousNames == null) {
failWithMessage("Expecting previousNames parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}

// check with standard error message (use overridingErrorMessage before contains to set your own message).
Iterables.instance().assertDoesNotContain(info, actual.getPreviousNames(), previousNames.toArray());

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player has no previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames is not empty.
*/
public S hasNoPreviousNames() {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// we override the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting :\n <%s>\nnot to have previousNames but had :\n <%s>";

// check
if (actual.getPreviousNames().iterator().hasNext()) {
failWithMessage(assertjErrorMessage, actual, actual.getPreviousNames());
}

// return the current assertion for method chaining
return myself;
}


/**
* Verifies that the actual Player's previousTeamNames contains the given String elements.
* @param previousTeamNames the given elements that should be contained in actual Player's previousTeamNames.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,159 @@ public abstract class AbstractPlayerAssert<S extends AbstractPlayerAssert<S, A>,
return myself;
}

/**
* Verifies that the actual Player's previousNames contains the given java.lang.CharSequence elements.
* @param previousNames the given elements that should be contained in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames does not contain all given java.lang.CharSequence elements.
*/
public S hasPreviousNames(java.lang.CharSequence... previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence varargs is not null.
if (previousNames == null) failWithMessage("Expecting previousNames 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.getPreviousNames(), previousNames);

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player's previousNames contains the given java.lang.CharSequence elements in Collection.
* @param previousNames the given elements that should be contained in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames does not contain all given java.lang.CharSequence elements.
*/
public S hasPreviousNames(java.util.Collection<? extends java.lang.CharSequence> previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence collection is not null.
if (previousNames == null) {
failWithMessage("Expecting previousNames parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}

// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContains(info, actual.getPreviousNames(), previousNames.toArray());

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player's previousNames contains <b>only</b> the given java.lang.CharSequence elements and nothing else in whatever order.
* @param previousNames the given elements that should be contained in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames does not contain all given java.lang.CharSequence elements.
*/
public S hasOnlyPreviousNames(java.lang.CharSequence... previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence varargs is not null.
if (previousNames == null) failWithMessage("Expecting previousNames parameter not to be null.");

// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContainsOnly(info, actual.getPreviousNames(), previousNames);

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player's previousNames contains <b>only</b> the given java.lang.CharSequence elements in Collection and nothing else in whatever order.
* @param previousNames the given elements that should be contained in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames does not contain all given java.lang.CharSequence elements.
*/
public S hasOnlyPreviousNames(java.util.Collection<? extends java.lang.CharSequence> previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence collection is not null.
if (previousNames == null) {
failWithMessage("Expecting previousNames parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}

// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContainsOnly(info, actual.getPreviousNames(), previousNames.toArray());

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player's previousNames does not contain the given java.lang.CharSequence elements.
*
* @param previousNames the given elements that should not be in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames contains any given java.lang.CharSequence elements.
*/
public S doesNotHavePreviousNames(java.lang.CharSequence... previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence varargs is not null.
if (previousNames == null) failWithMessage("Expecting previousNames parameter not to be null.");

// check with standard error message (use overridingErrorMessage before contains to set your own message).
Iterables.instance().assertDoesNotContain(info, actual.getPreviousNames(), previousNames);

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player's previousNames does not contain the given java.lang.CharSequence elements in Collection.
*
* @param previousNames the given elements that should not be in actual Player's previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames contains any given java.lang.CharSequence elements.
*/
public S doesNotHavePreviousNames(java.util.Collection<? extends java.lang.CharSequence> previousNames) {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// check that given java.lang.CharSequence collection is not null.
if (previousNames == null) {
failWithMessage("Expecting previousNames parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}

// check with standard error message (use overridingErrorMessage before contains to set your own message).
Iterables.instance().assertDoesNotContain(info, actual.getPreviousNames(), previousNames.toArray());

// return the current assertion for method chaining
return myself;
}

/**
* Verifies that the actual Player has no previousNames.
* @return this assertion object.
* @throws AssertionError if the actual Player's previousNames is not empty.
*/
public S hasNoPreviousNames() {
// check that actual Player we want to make assertions on is not null.
isNotNull();

// we override the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting :\n <%s>\nnot to have previousNames but had :\n <%s>";

// check
if (actual.getPreviousNames().iterator().hasNext()) {
failWithMessage(assertjErrorMessage, actual, actual.getPreviousNames());
}

// return the current assertion for method chaining
return myself;
}


/**
* Verifies that the actual Player's previousTeamNames contains the given String elements.
* @param previousTeamNames the given elements that should be contained in actual Player's previousTeamNames.
Expand Down
Loading