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

PreferAssertj iterable-map fix retains map type parameters #1071

Merged
merged 4 commits into from
Nov 27, 2019
Merged
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 @@ -465,9 +465,13 @@ private Description withAssertThat(
String actualArgumentString = argSource(tree, state, actualIndex);
ExpressionTree actualArgument = tree.getArguments().get(actualIndex);
if (isIterableMap(actualArgument, state)) {
actualArgumentString = String.format("(%s<?, ?>) %s",
SuggestedFixes.qualifyType(state, fix, "java.util.Map"),
actualArgumentString);
String qualifiedMap = SuggestedFixes.prettyType(
state,
fix,
state.getTypes().asSuper(
ASTHelpers.getType(actualArgument),
state.getSymbolFromString("java.util.Map")));
actualArgumentString = String.format("(%s) %s", qualifiedMap, actualArgumentString);
}
assertThat.accept(qualified + '(' + actualArgumentString + ')', fix);
return buildDescription(tree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -946,11 +946,11 @@ public void fix_assert_iterableMap() {
"class Test {",
" interface IMap<K, V> extends Map<K, V>, Iterable<Map.Entry<K, V>> {}",
" <K, V> void foo(IMap<K, V> expected, IMap<K, V> actual) {",
" assertThat((Map<?, ?>) actual).isEqualTo(expected);",
" assertThat((Map<?, ?>) actual).isEqualTo(expected);",
" assertThat((Map<?, ?>) actual).describedAs(\"desc\").isEqualTo(expected);",
" assertThat((Map<?, ?>) actual).isNull();",
" assertThat((Map<?, ?>) actual).describedAs(\"desc\").isNull();",
" assertThat((Map<K, V>) actual).isEqualTo(expected);",
" assertThat((Map<K, V>) actual).isEqualTo(expected);",
" assertThat((Map<K, V>) actual).describedAs(\"desc\").isEqualTo(expected);",
" assertThat((Map<K, V>) actual).isNull();",
" assertThat((Map<K, V>) actual).describedAs(\"desc\").isNull();",
" }",
"}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1071.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: PreferAssertj iterable-map fix retains map type parameters
links:
- https://github.com/palantir/gradle-baseline/pull/1071