java_call_app_test.go 2.2 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
	"path/filepath"
P
Phodal Huang 已提交
8 9 10 11
	"testing"
)

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

P
Phodal Huang 已提交
14
	codePath := "../../../_fixtures/call"
P
Phodal Huang 已提交
15 16
	codePath = filepath.FromSlash(codePath)

P
Phodal Huang 已提交
17 18 19 20 21 22 23
	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 已提交
24
	callApp := NewJavaCallApp()
P
Phodal Huang 已提交
25 26 27
	callNodes := callApp.AnalysisPath(codePath, classes, iNodes)

	g.Expect(len(callNodes)).To(Equal(1))
P
Phodal Huang 已提交
28 29 30 31 32 33
}

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

	codePath := "../../../_fixtures/suggest/factory"
P
Phodal Huang 已提交
34 35
	codePath = filepath.FromSlash(codePath)

P
Phodal Huang 已提交
36 37 38 39 40
	callNodes := getCallNodes(codePath)
	g.Expect(len(callNodes[0].Methods)).To(Equal(3))
}

func getCallNodes(codePath string) []models.JClassNode {
P
Phodal Huang 已提交
41 42 43 44 45 46 47
	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 已提交
48
	callApp := NewJavaCallApp()
P
Phodal Huang 已提交
49 50

	callNodes := callApp.AnalysisPath(codePath, classes, iNodes)
P
Phodal Huang 已提交
51
	return callNodes
P
Phodal Huang 已提交
52 53 54 55 56 57
}

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

	codePath := "../../../_fixtures/lambda"
P
Phodal Huang 已提交
58 59
	codePath = filepath.FromSlash(codePath)

P
Phodal Huang 已提交
60
	callNodes := getCallNodes(codePath)
P
Phodal Huang 已提交
61 62 63 64 65 66 67 68

	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"))
69 70 71 72 73 74
}

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

	codePath := "../../../_fixtures/grammar/interface"
P
Phodal Huang 已提交
75 76
	codePath = filepath.FromSlash(codePath)

77 78 79 80 81 82 83 84 85 86
	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 已提交
87
}