Files
zzet--gortex/internal/resolver/java_selector_receiver_test.go
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

34 lines
2.0 KiB
Go

package resolver
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/zzet/gortex/internal/graph"
)
// A selector call `testee.triggerException()` whose method name collides with a
// method in the caller's OWN class must bind to the receiver's type, not the
// same-named enclosing-class method — even when the receiver's type lives in a
// sibling Maven directory the import-reachability filter would otherwise drop.
func TestResolveMethodCall_ReceiverTypeBeatsEnclosingClass(t *testing.T) {
g := graph.New()
mainF := "src/main/java/org/example/system/CrashController.java"
testF := "src/test/java/org/example/system/CrashControllerTests.java"
g.AddNode(&graph.Node{ID: mainF, Kind: graph.KindFile, Name: "CrashController.java", FilePath: mainF, Language: "java"})
g.AddNode(&graph.Node{ID: testF, Kind: graph.KindFile, Name: "CrashControllerTests.java", FilePath: testF, Language: "java"})
// The production method the receiver-typed call should bind to.
g.AddNode(&graph.Node{ID: mainF + "::CrashController.triggerException", Kind: graph.KindMethod, Name: "triggerException", FilePath: mainF, Language: "java", Meta: map[string]any{"receiver": "CrashController", "scope_class": "CrashController"}})
// A same-named method in the caller's own class — the wrong target.
g.AddNode(&graph.Node{ID: testF + "::CrashControllerTests.triggerException", Kind: graph.KindMethod, Name: "triggerException", FilePath: testF, Language: "java", Meta: map[string]any{"receiver": "CrashControllerTests", "scope_class": "CrashControllerTests"}})
// `testee.triggerException()` from the test method of the same name.
edge := &graph.Edge{From: testF + "::CrashControllerTests.triggerException", To: "unresolved::*.triggerException", Kind: graph.EdgeCalls, FilePath: testF, Line: 37, Meta: map[string]any{"receiver_type": "CrashController"}}
g.AddEdge(edge)
New(g).ResolveAll()
assert.Equal(t, mainF+"::CrashController.triggerException", edge.To,
"a receiver-typed selector call must bind to the receiver's type, not a same-named method in the caller's own class")
}