java_call_app_test.go 2.0 KB
Newer Older
P
Phodal Huang 已提交
1 2 3
package call

import (
P
Phodal Huang 已提交
4
	. "github.com/onsi/gomega"
P
Phodal Huang 已提交
5
	"github.com/phodal/coca/core/adapter/identifier"
P
Phodal Huang 已提交
6
	"github.com/phodal/coca/core/models"
P
Phodal Huang 已提交
7 8 9 10
	"testing"
)

func TestJavaCallApp_AnalysisPath(t *testing.T) {
P
Phodal Huang 已提交
11
	g := NewGomegaWithT(t)
P
Phodal Huang 已提交
12

P
Phodal Huang 已提交
13 14 15 16 17 18 19 20
	codePath := "../../../_fixtures/call"
	identifierApp := new(identifier.JavaIdentifierApp)
	iNodes := identifierApp.AnalysisPath(codePath)
	var classes []string = nil
	for _, node := range iNodes {
		classes = append(classes, node.Package+"."+node.ClassName)
	}

P
Phodal Huang 已提交
21
	callApp := NewJavaCallApp()
P
Phodal Huang 已提交
22 23 24
	callNodes := callApp.AnalysisPath(codePath, classes, iNodes)

	g.Expect(len(callNodes)).To(Equal(1))
P
Phodal Huang 已提交
25 26 27 28 29 30
}

func TestJavaCallListener_EnterConstructorDeclaration(t *testing.T) {
	g := NewGomegaWithT(t)

	codePath := "../../../_fixtures/suggest/factory"
P
Phodal Huang 已提交
31 32 33 34 35
	callNodes := getCallNodes(codePath)
	g.Expect(len(callNodes[0].Methods)).To(Equal(3))
}

func getCallNodes(codePath string) []models.JClassNode {
P
Phodal Huang 已提交
36 37 38 39 40 41 42
	identifierApp := new(identifier.JavaIdentifierApp)
	iNodes := identifierApp.AnalysisPath(codePath)
	var classes []string = nil
	for _, node := range iNodes {
		classes = append(classes, node.Package+"."+node.ClassName)
	}

P
Phodal Huang 已提交
43
	callApp := NewJavaCallApp()
P
Phodal Huang 已提交
44 45

	callNodes := callApp.AnalysisPath(codePath, classes, iNodes)
P
Phodal Huang 已提交
46
	return callNodes
P
Phodal Huang 已提交
47 48 49 50 51 52
}

func TestLambda_Express(t *testing.T) {
	g := NewGomegaWithT(t)

	codePath := "../../../_fixtures/lambda"
P
Phodal Huang 已提交
53
	callNodes := getCallNodes(codePath)
P
Phodal Huang 已提交
54 55 56 57 58 59 60 61

	methodMap := make(map[string]models.JMethod)
	for _, c := range callNodes[1].Methods {
		methodMap[c.Name] = c
	}

	g.Expect(methodMap["save"].MethodCalls[0].MethodName).To(Equal("of"))
	g.Expect(methodMap["findById"].MethodCalls[3].MethodName).To(Equal("toDomainModel"))
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
}

func TestInterface(t *testing.T) {
	g := NewGomegaWithT(t)

	codePath := "../../../_fixtures/grammar/interface"
	callNodes := getCallNodes(codePath)

	g.Expect(true).To(Equal(true))
	methodMap := make(map[string]models.JMethod)
	for _, c := range callNodes[0].Methods {
		methodMap[c.Name] = c
	}

	g.Expect(len(callNodes[0].Methods)).To(Equal(6))
	g.Expect(methodMap["count"].Name).To(Equal("count"))
P
Phodal Huang 已提交
78
}