Skip to content
Open
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 @@ -123,6 +123,10 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation methodInvocat
if (!chainedAssertMatcher.matches(assertThatArg)) {
return mi;
}
// Parameterized toString overloads have no equivalent hasToString assertion.
if ("toString".equals(chainedAssertion) && !(assertThatArg.getArguments().get(0) instanceof J.Empty)) {
return mi;
}

// Extract the actual argument for the new assertThat call
Expression actual = assertThatArg.getSelect() != null ? assertThatArg.getSelect() : assertThatArg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,24 @@ void testMethod(Object argument) {
);
}
}

@Test
void doesNotRewriteParameterizedByteArrayOutputStreamToString() {
rewriteRun(
java(
"""
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;

import static org.assertj.core.api.Assertions.assertThat;

class Test {
void verify(ByteArrayOutputStream stdout, String expected) {
assertThat(stdout.toString(StandardCharsets.UTF_8)).isEqualTo(expected);
}
}
"""
)
);
}
}
Loading