From 792401859058917e5790d8d39f31817c1d874787 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sun, 5 Jan 2020 11:48:12 +0800 Subject: [PATCH] fix: fix methodname empty unknown issue --- core/context/tbs/tbs_app.go | 34 ++++++++++++++++++-------------- core/context/tbs/tbs_app_test.go | 2 +- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/core/context/tbs/tbs_app.go b/core/context/tbs/tbs_app.go index d8a1ebff..232482ca 100644 --- a/core/context/tbs/tbs_app.go +++ b/core/context/tbs/tbs_app.go @@ -41,6 +41,9 @@ func (a TbsApp) AnalysisPath(deps []domain.JClassNode, identifiersMap map[string var hasAssert = false for index, methodCall := range currentMethodCalls { if methodCall.MethodName == "" { + if index == len(currentMethodCalls)-1 { + checkAssert(hasAssert, clz, method, &results, &testType) + } continue } @@ -55,9 +58,7 @@ func (a TbsApp) AnalysisPath(deps []domain.JClassNode, identifiersMap map[string } if index == len(currentMethodCalls)-1 { - if !hasAssert { - checkUnknownTest(clz, method, &results, &testType) - } + checkAssert(hasAssert, clz, method, &results, &testType) } } @@ -68,6 +69,21 @@ func (a TbsApp) AnalysisPath(deps []domain.JClassNode, identifiersMap map[string return results } +func checkAssert(hasAssert bool, clz domain.JClassNode, method domain.JMethod, results *[]TestBadSmell, testType *string) { + if !hasAssert { + *testType = "UnknownTest" + tbs := *&TestBadSmell{ + FileName: clz.Path, + Type: *testType, + Description: "", + Line: method.StartLine, + } + + *results = append(*results, tbs) + + } +} + func updateMethodCallsForSelfCall(method domain.JMethod, clz domain.JClassNode, callMethodMap map[string]domain.JMethod) []domain.JMethodCall { currentMethodCalls := method.MethodCalls for _, methodCall := range currentMethodCalls { @@ -98,18 +114,6 @@ func checkRedundantAssertionTest(path string, call domain.JMethodCall, method do } } -func checkUnknownTest(clz domain.JClassNode, method domain.JMethod, results *[]TestBadSmell, testType *string) { - *testType = "UnknownTest" - tbs := *&TestBadSmell{ - FileName: clz.Path, - Type: *testType, - Description: "", - Line: method.StartLine, - } - - *results = append(*results, tbs) -} - func checkDuplicateAssertTest(clz domain.JClassNode, results *[]TestBadSmell, methodCallMap map[string][]domain.JMethodCall, method domain.JMethod, testType *string) { var isDuplicateAssert = false for _, methodCall := range methodCallMap { diff --git a/core/context/tbs/tbs_app_test.go b/core/context/tbs/tbs_app_test.go index c3e5d726..6f1f584c 100644 --- a/core/context/tbs/tbs_app_test.go +++ b/core/context/tbs/tbs_app_test.go @@ -128,7 +128,7 @@ func TestTbsApp_ShouldReturnMultipleResult(t *testing.T) { result := buildTbsResult(codePath) - g.Expect(len(result)).To(Equal(3)) + g.Expect(len(result)).To(Equal(4)) } func buildTbsResult(codePath string) []TestBadSmell {