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 @@ -16,6 +16,7 @@
package org.openrewrite.java.migrate;

import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ExpectedToFail;
import org.openrewrite.DocumentExample;
import org.openrewrite.Issue;
import org.openrewrite.java.JavaParser;
Expand Down Expand Up @@ -218,6 +219,74 @@ void test(byte[] bBytes) {
);
}

@ExpectedToFail("Import for java.util.Base64 is only added when ChangeType retypes a coder variable; without one the migrated file does not compile")
@Test
void addImportWhenNoCoderVariablePresent() {
rewriteRun(
//language=java
java(
"""
package test.sun.misc;

class Test {
String test(byte[] bBytes) {
return new BASE64Encoder().encode(bBytes);
}
}
""",
"""
package test.sun.misc;

import java.util.Base64;

class Test {
String test(byte[] bBytes) {
return Base64.getEncoder().encodeToString(bBytes);
}
}
"""
)
);
}

@ExpectedToFail("Receivers are only put back when they are identifiers; a method call receiver and its side effects are silently dropped")
@Test
void retainMethodCallReceiver() {
rewriteRun(
//language=java
java(
"""
package test.sun.misc;

class Test {
BASE64Encoder encoder() {
return new BASE64Encoder();
}

String test(byte[] bBytes) {
return encoder().encode(bBytes);
}
}
""",
"""
package test.sun.misc;

import java.util.Base64;

class Test {
Base64.Encoder encoder() {
return Base64.getEncoder();
}

String test(byte[] bBytes) {
return encoder().encodeToString(bBytes);
}
}
"""
)
);
}

@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/212")
@Test
void otherBase64() {
Expand Down
Loading