From 2014d5287ef4324d689c37ad6f6fd4a99a370e46 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Mon, 6 Jan 2020 09:43:45 +0800 Subject: [PATCH] refactor: [test] use same files --- cocatest/generate.go | 23 ++--------------------- core/context/arch/arch_app_test.go | 4 ++-- core/context/call/call_graph_test.go | 13 +++---------- core/context/deps/dep_app_test.go | 2 +- core/context/evaluate/analyser_test.go | 13 ++----------- core/context/tbs/tbs_app_test.go | 24 ++++++++++++++++++++++-- 6 files changed, 32 insertions(+), 47 deletions(-) diff --git a/cocatest/generate.go b/cocatest/generate.go index cd50e27..6eccd9c 100644 --- a/cocatest/generate.go +++ b/cocatest/generate.go @@ -1,31 +1,12 @@ package cocatest import ( - "github.com/phodal/coca/cmd/cmd_util" - "github.com/phodal/coca/core/adapter/cocafile" "github.com/phodal/coca/core/context/analysis" "github.com/phodal/coca/core/domain" "path/filepath" ) -func BuildTestAnalysisResultsByPath(codePath string) (map[string]domain.JIdentifier, []domain.JClassNode) { - files := cocafile.GetJavaTestFiles(codePath) - var identifiers []domain.JIdentifier - - identifiers = cmd_util.LoadTestIdentify(files) - identifiersMap := domain.BuildIdentifierMap(identifiers) - - var classes []string = nil - for _, node := range identifiers { - classes = append(classes, node.Package+"."+node.ClassName) - } - - analysisApp := analysis.NewJavaFullApp() - classNodes := analysisApp.AnalysisFiles(identifiers, files, classes) - return identifiersMap, classNodes -} - -func BuildAnalysisDeps(codePath string) ([]domain.JClassNode, map[string]domain.JIdentifier) { +func BuildAnalysisDeps(codePath string) ([]domain.JClassNode, map[string]domain.JIdentifier, []domain.JIdentifier) { codePath = filepath.FromSlash(codePath) identifierApp := new(analysis.JavaIdentifierApp) @@ -39,6 +20,6 @@ func BuildAnalysisDeps(codePath string) ([]domain.JClassNode, map[string]domain. callNodes := callApp.AnalysisPath(codePath, classes, identifiers) identifiersMap := domain.BuildIdentifierMap(identifiers) - return callNodes, identifiersMap + return callNodes, identifiersMap, identifiers } diff --git a/core/context/arch/arch_app_test.go b/core/context/arch/arch_app_test.go index 64463cb..2dbbfbb 100644 --- a/core/context/arch/arch_app_test.go +++ b/core/context/arch/arch_app_test.go @@ -14,7 +14,7 @@ func TestConceptAnalyser_Analysis(t *testing.T) { g := NewGomegaWithT(t) codePath := "../../../_fixtures/arch/step2-java" - callNodes, identifiersMap := cocatest.BuildAnalysisDeps(codePath) + callNodes, identifiersMap, _ := cocatest.BuildAnalysisDeps(codePath) app := NewArchApp() results := app.Analysis(callNodes, identifiersMap) @@ -42,7 +42,7 @@ func TestConceptAnalyser_AnalysisWithFans(t *testing.T) { g := NewGomegaWithT(t) codePath := "../../../_fixtures/arch/step2-java" - callNodes, identifiersMap := cocatest.BuildAnalysisDeps(codePath) + callNodes, identifiersMap, _ := cocatest.BuildAnalysisDeps(codePath) app := NewArchApp() result := app.Analysis(callNodes, identifiersMap) diff --git a/core/context/call/call_graph_test.go b/core/context/call/call_graph_test.go index f6e23b3..a68a6cb 100644 --- a/core/context/call/call_graph_test.go +++ b/core/context/call/call_graph_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" . "github.com/onsi/gomega" "github.com/phodal/coca/cmd/cmd_util" - "github.com/phodal/coca/core/context/analysis" + "github.com/phodal/coca/cocatest" "github.com/phodal/coca/core/context/api" "github.com/phodal/coca/core/context/call" "github.com/phodal/coca/core/domain" @@ -41,15 +41,8 @@ func Test_ShouldBuildSuccessDataFromSourceData(t *testing.T) { g := NewGomegaWithT(t) codePath := "../../../_fixtures/examples/api" - identApp := analysis.NewJavaIdentifierApp() - identifiers := identApp.AnalysisPath(filepath.FromSlash(codePath)) - var classes []string = nil - for _, node := range identifiers { - classes = append(classes, node.Package+"."+node.ClassName) - } - callApp := analysis.NewJavaFullApp() - callNodes := callApp.AnalysisPath(codePath, classes, identifiers) - identifiersMap := domain.BuildIdentifierMap(identifiers) + callNodes, identifiersMap, identifiers := cocatest.BuildAnalysisDeps(codePath) + diMap := domain.BuildDIMap(identifiers, identifiersMap) app := new(api.JavaApiApp) restApis := app.AnalysisPath(codePath, callNodes, identifiersMap, diMap) diff --git a/core/context/deps/dep_app_test.go b/core/context/deps/dep_app_test.go index 76ee224..db72daa 100644 --- a/core/context/deps/dep_app_test.go +++ b/core/context/deps/dep_app_test.go @@ -23,7 +23,7 @@ func Test_ShouldCountDeps_WhenHadClassNodes(t *testing.T) { g := NewGomegaWithT(t) codePath := "../../../_fixtures/examples/api/" - _, classNodes := cocatest.BuildTestAnalysisResultsByPath(codePath) + classNodes, _, _ := cocatest.BuildAnalysisDeps(codePath) depApp := NewDepApp() depApp.CountDeps(classNodes) diff --git a/core/context/evaluate/analyser_test.go b/core/context/evaluate/analyser_test.go index 3f9a8be..e83ff61 100644 --- a/core/context/evaluate/analyser_test.go +++ b/core/context/evaluate/analyser_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" . "github.com/onsi/gomega" "github.com/phodal/coca/cmd/cmd_util" - "github.com/phodal/coca/core/context/analysis" + "github.com/phodal/coca/cocatest" "github.com/phodal/coca/core/context/evaluate/evaluator" "github.com/phodal/coca/core/domain" "path/filepath" @@ -104,16 +104,7 @@ func Test_CheckFornull(t *testing.T) { } func buildEvaluateResult(codePath string) evaluator.EvaluateModel { - codePath = filepath.FromSlash(codePath) - identifierApp := new(analysis.JavaIdentifierApp) - identifiers := identifierApp.AnalysisPath(codePath) - var classes []string = nil - for _, node := range identifiers { - classes = append(classes, node.Package+"."+node.ClassName) - } - - callApp := analysis.NewJavaFullApp() - callNodes := callApp.AnalysisPath(codePath, classes, identifiers) + callNodes, _, identifiers := cocatest.BuildAnalysisDeps(codePath) analyser := NewEvaluateAnalyser() result := analyser.Analysis(callNodes, identifiers) diff --git a/core/context/tbs/tbs_app_test.go b/core/context/tbs/tbs_app_test.go index 07566d7..9c56bc4 100644 --- a/core/context/tbs/tbs_app_test.go +++ b/core/context/tbs/tbs_app_test.go @@ -2,7 +2,10 @@ package tbs import ( . "github.com/onsi/gomega" - "github.com/phodal/coca/cocatest" + "github.com/phodal/coca/cmd/cmd_util" + "github.com/phodal/coca/core/adapter/cocafile" + "github.com/phodal/coca/core/context/analysis" + "github.com/phodal/coca/core/domain" "path/filepath" "testing" ) @@ -129,9 +132,26 @@ func TestTbsApp_ShouldReturnMultipleResult(t *testing.T) { } func buildTbsResult(codePath string) []TestBadSmell { - identifiersMap, classNodes := cocatest.BuildTestAnalysisResultsByPath(codePath) + identifiersMap, classNodes := BuildTestAnalysisResultsByPath(codePath) app := NewTbsApp() result := app.AnalysisPath(classNodes, identifiersMap) return result } + +func BuildTestAnalysisResultsByPath(codePath string) (map[string]domain.JIdentifier, []domain.JClassNode) { + files := cocafile.GetJavaTestFiles(codePath) + var identifiers []domain.JIdentifier + + identifiers = cmd_util.LoadTestIdentify(files) + identifiersMap := domain.BuildIdentifierMap(identifiers) + + var classes []string = nil + for _, node := range identifiers { + classes = append(classes, node.Package+"."+node.ClassName) + } + + analysisApp := analysis.NewJavaFullApp() + classNodes := analysisApp.AnalysisFiles(identifiers, files, classes) + return identifiersMap, classNodes +} -- GitLab