Skip to content

Commit

Permalink
fix: fix methodname empty unknown issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 5, 2020
1 parent d064daa commit 7924018
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions core/context/tbs/tbs_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
}
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/context/tbs/tbs_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7924018

Please sign in to comment.