未验证 提交 b4893c47 编写于 作者: P Phodal Huang

feat: [tbs] add RedundantAssertionTest

上级 a046289a
......@@ -193,3 +193,21 @@ func Test_ShouldNotGetCreators(t *testing.T) {
g.Expect(len(methodMap["testTrue"].Creators)).To(Equal(0))
}
func Test_ShouldGetMethodCallParameters(t *testing.T) {
g := NewGomegaWithT(t)
codePath := "../../../_fixtures/tbs/code/RedundantAssertionTest.java"
codePath = filepath.FromSlash(codePath)
callNodes := getCallNodes(codePath)
methodCallMap := make(map[string]models.JMethodCall)
for _, method := range callNodes[0].Methods {
for _, call := range method.MethodCalls {
methodCallMap[call.MethodName] = call
}
}
g.Expect(methodCallMap["assertEquals"].Parameters).To(Equal([]string{"true", "true"}))
}
......@@ -318,17 +318,7 @@ func buildMethodParameters(parameters parser.IFormalParametersContext, method *m
return true
}
var methodParams []models.JParameter = nil
parameterList := parameters.GetChild(1).(*parser.FormalParameterListContext)
formalParameter := parameterList.AllFormalParameter()
for _, param := range formalParameter {
paramContext := param.(*parser.FormalParameterContext)
paramType := paramContext.TypeType().GetText()
paramValue := paramContext.VariableDeclaratorId().(*parser.VariableDeclaratorIdContext).IDENTIFIER().GetText()
localVars[paramValue] = paramType
methodParams = append(methodParams, *&models.JParameter{Name: paramValue, Type: paramType})
}
methodParams := getMethodParameters(parameters)
method.Parameters = methodParams
updateMethod(method)
......@@ -336,6 +326,21 @@ func buildMethodParameters(parameters parser.IFormalParametersContext, method *m
return false
}
func getMethodParameters(parameters parser.IFormalParametersContext) []models.JParameter {
var methodParams []models.JParameter = nil
parameterList := parameters.GetChild(1).(*parser.FormalParameterListContext)
formalParameter := parameterList.AllFormalParameter()
for _, param := range formalParameter {
paramContext := param.(*parser.FormalParameterContext)
paramType := paramContext.TypeType().GetText()
paramValue := paramContext.VariableDeclaratorId().(*parser.VariableDeclaratorIdContext).IDENTIFIER().GetText()
localVars[paramValue] = paramType
methodParams = append(methodParams, *&models.JParameter{Name: paramValue, Type: paramType})
}
return methodParams
}
func updateMethod(method *models.JMethod) {
if currentType == "CreatorClass" {
creatorMethodMap[getMethodMapName(*method)] = *method
......@@ -535,6 +540,14 @@ func (s *JavaCallListener) EnterMethodCall(ctx *parser.MethodCallContext) {
}
jMethodCall.Class = targetType
if ctx.ExpressionList() != nil {
var parameters []string
for _, expression := range ctx.ExpressionList().(*parser.ExpressionListContext).AllExpression() {
parameters = append(parameters, expression.(*parser.ExpressionContext).GetText())
}
jMethodCall.Parameters = parameters
}
addMethodCall(jMethodCall)
}
......
......@@ -22,14 +22,6 @@ func NewSqlIdentifierListener() *SqlIdentifierListener {
return &SqlIdentifierListener{}
}
func (s *SqlIdentifierListener) EnterSelect_stmt(ctx *parser.Select_stmtContext) {
}
func (s *SqlIdentifierListener) EnterSelect_or_values(ctx *parser.Select_or_valuesContext) {
}
func (s *SqlIdentifierListener) EnterSelect_core(ctx *parser.Select_coreContext) {
columns := ctx.AllResult_column()
for _, col := range columns {
......
......@@ -86,8 +86,21 @@ func (a TbsApp) AnalysisPath(deps []models.JClassNode, identifiersMap map[string
return results
}
func checkRedundantAssertionTest(path string, call models.JMethodCall, method models.JMethod, result *[]TestBadSmell, testType *string) {
func checkRedundantAssertionTest(path string, call models.JMethodCall, method models.JMethod, results *[]TestBadSmell, testType *string) {
TWO_PARAMETERS := 2
if len(call.Parameters) == TWO_PARAMETERS {
if call.Parameters[0] == call.Parameters[1] {
*testType = "RedundantAssertionTest"
tbs := *&TestBadSmell{
FileName: path,
Type: *testType,
Description: "",
Line: method.StartLine,
}
*results = append(*results, tbs)
}
}
}
func hasAssertion(methodName string) bool {
......
......@@ -86,8 +86,8 @@ func TestTbsApp_RedundantAssertionTest(t *testing.T) {
result := buildTbsResult(codePath)
g.Expect(len(result)).To(Equal(0))
//g.Expect(result[0].Type).To(Equal("EmptyTest"))
g.Expect(len(result)).To(Equal(1))
g.Expect(result[0].Type).To(Equal("RedundantAssertionTest"))
}
func TestTbsApp_CreatorNotUnknownTest(t *testing.T) {
......
......@@ -5,7 +5,7 @@ type JMethodCall struct {
Type string
Class string
MethodName string
Parameters []JParameter
Parameters []string
StartLine int
StartLinePosition int
StopLine int
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册