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

Add testcase to validate switch cases in SystemErrToLogging #197

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Changes from 1 commit
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 @@ -49,7 +49,7 @@ void useSlf4j() {
class Test {
int n;
Logger logger;

void test() {
try {
} catch(Throwable t) {
Expand All @@ -64,7 +64,7 @@ void test() {
class Test {
int n;
Logger logger;

void test() {
try {
} catch(Throwable t) {
Expand Down Expand Up @@ -97,10 +97,10 @@ void test() {
"""
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class Test {
private static final Logger LOGGER = LoggerFactory.getLogger(Test.class);

void test() {
try {
} catch(Throwable t) {
Expand Down Expand Up @@ -143,7 +143,7 @@ void inRunnable() {
import org.slf4j.Logger;
class Test {
Logger logger;

void test() {
Runnable r = () -> System.err.println("single");
}
Expand All @@ -153,7 +153,7 @@ void test() {
import org.slf4j.Logger;
class Test {
Logger logger;

void test() {
Runnable r = () -> logger.error("single");
}
Expand All @@ -176,7 +176,7 @@ void supportLombokLogAnnotations() {
@Slf4j
class Test {
int n;

void test() {
try {
} catch(Throwable t) {
Expand All @@ -191,7 +191,7 @@ void test() {
@Slf4j
class Test {
int n;

void test() {
try {
} catch(Throwable t) {
Expand All @@ -203,4 +203,66 @@ void test() {
)
);
}

@Test
void replaceSystemErr() {
rewriteRun(
spec -> spec.recipe(new SystemErrToLogging(false, "logger", "SLF4J")),
//language=java
java(
"""
public class A {
org.slf4j.Logger logger = null;

public void m() {
int cnt = 1;
String name = "";
switch (cnt) {
case 1:
java.util.List<Integer> numbers = new java.util.ArrayList<>();
numbers.forEach(o -> System.err.println(String.valueOf(o)));
break;
case 2:
break;
case 3:
break;
default:
break;
}
}

public String m2(String s1) {
return null;
}
}
""",
"""
public class A {
org.slf4j.Logger logger = null;

public void m() {
int cnt = 1;
String name = "";
switch (cnt) {
case 1:
java.util.List<Integer> numbers = new java.util.ArrayList<>();
numbers.forEach(o -> logger.error(String.valueOf(o)));
break;
case 2:
break;
case 3:
break;
default:
break;
}
}

public String m2(String s1) {
return null;
}
}
"""
));
}

}
Loading