Skip to content
Draft
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 @@ -15,6 +15,7 @@
*/
package org.openrewrite.java.testing.junit5;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.InMemoryExecutionContext;
Expand Down Expand Up @@ -262,4 +263,72 @@ void test() {
"""
));
}

@Disabled("The migrated unqualified call binds to an assertInstanceOf declared in the class instead of JUnit's, per JLS 6.5.7.1")
@Test
void qualifyWhenAssertInstanceOfDeclaredInClass() {
//language=java
rewriteRun(
java(
"""
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

class ATest {
static void assertInstanceOf(Class<?> type, Object value) {
throw new AssertionError("wrong owner");
}

@Test
void test() {
Object obj = "example";
assertTrue(obj instanceof String);
}
}
""",
"""
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class ATest {
static void assertInstanceOf(Class<?> type, Object value) {
throw new AssertionError("wrong owner");
}

@Test
void test() {
Object obj = "example";
Assertions.assertInstanceOf(String.class, obj);
}
}
"""
));
}

@Disabled("The recipe drops the getAssertions() receiver expression, so its side effects are lost from the migrated code")
@Test
void noChangeWhenInstanceReceiverHasSideEffect() {
//language=java
rewriteRun(
java(
"""
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class ATest {
Assertions getAssertions() {
System.out.println("side effect");
return null;
}

@Test
void test() {
Object obj = "example";
getAssertions().assertTrue(obj instanceof String);
}
}
"""
));
}
}
Loading