Skip to content
Merged
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 @@ -738,4 +738,92 @@ public int frobnicator() {
""")
.doTest();
}

@Test
public void overriddenMethod_visibleFromSubclass_noFinding() {
helper
.addSourceLines(
"Test.java",
"""
class Test {
private interface Frobnicator {
int frobnicate();
}

public class Impl implements Frobnicator {
@Override
public int frobnicate() {
return 0;
}
}
}
""")
.doTest();
}

@Test
public void overriddenMethod_notVisibleOutside() {
// Note that while the finding is correct here, the fix is not by itself: the method and all its
// overrides could be removed.
refactoringHelper
.addInputLines(
"Test.java",
"""
class Test {
private interface Frobnicator {
// BUG: Diagnostic contains:
int frobnicate();
}

private class Impl implements Frobnicator {
@Override
public int frobnicate() {
return 0;
}
}
}
""")
.addOutputLines(
"Test.java",
"""
class Test {
private interface Frobnicator {}

private class Impl implements Frobnicator {
@Override
public int frobnicate() {
return 0;
}
}
}
""")
.allowBreakingChanges()
.doTest();
}

@Test
public void overriddenMethod_notVisibleOutside_butUsed() {
helper
.addSourceLines(
"Test.java",
"""
class Test {
private interface Frobnicator {
int frobnicate();
}

private class Impl implements Frobnicator {
@Override
public int frobnicate() {
return 0;
}
}

void f(Frobnicator f) {
var unused = f.frobnicate();
}
}
""")
.doTest();
}
}
Loading