Skip to content

Commit

Permalink
Remove unnecessary ternary after replacements (#36)
Browse files Browse the repository at this point in the history
* Remove unnecessary ternary after replacements

* Fix return type
  • Loading branch information
timtebeek authored Oct 27, 2024
1 parent 6f90bd4 commit 905e79f
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,43 @@ void bar() {
)
);
}

@Test
void removeUnnecessaryTernary() {
rewriteRun(
spec -> spec.recipe(new RemoveBooleanFlag("com.acme.bank.CustomLaunchDarklyWrapper featureFlagEnabled(String, boolean)", "flag-key-123abc", true)),
// language=java
java(
"""
package com.acme.bank;
public class CustomLaunchDarklyWrapper {
public boolean featureFlagEnabled(String key, boolean fallback) {
return fallback;
}
}
""",
SourceSpec::skip
),
// language=java
java(
"""
import com.acme.bank.CustomLaunchDarklyWrapper;
class Foo {
private CustomLaunchDarklyWrapper wrapper = new CustomLaunchDarklyWrapper();
String bar() {
return wrapper.featureFlagEnabled("flag-key-123abc", false) ? "Feature is on" : "Feature is off";
}
}
""",
"""
class Foo {
String bar() {
return "Feature is on";
}
}
"""
)
);
}
}

0 comments on commit 905e79f

Please sign in to comment.