Skip to content

Commit

Permalink
feat: add redundant print
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 29, 2019
1 parent fc9f063 commit 7528520
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions _fixtures/tbs/code/RedundantPrintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public class RedundantPrintTest {
public void testTransform10mNEUAndBack() {
String result = "a, b, c";
System.out.println("result = " + result);
assertEquals(true, true);
}
}
16 changes: 16 additions & 0 deletions core/domain/tbs/tbs_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,28 @@ func (a TbsApp) AnalysisPath(deps []models.JClassNode, identifiersMap map[string
for _, method := range clz.Methods {
checkIgnoreTest(clz.Path, method, &results)
checkEmptyTest(clz.Path, method, &results)
checkRedundantPrintTest(clz.Path, method, &results)
}
}

return results
}

func checkRedundantPrintTest(path string, method models.JMethod, results *[]TestBadSmell) {
for _, method := range method.MethodCalls {
if method.Class == "System.out" && (method.MethodName == "println" || method.MethodName == "printf" || method.MethodName == "print") {
tbs := *&TestBadSmell{
FileName: path,
Type: "RedundantPrintTest",
Description: "",
Line: 0,
}

*results = append(*results, tbs)
}
}
}

func checkEmptyTest(path string, method models.JMethod, results *[]TestBadSmell) {
for _, annotation := range method.Annotations {
if annotation.QualifiedName == "Test" {
Expand Down
11 changes: 11 additions & 0 deletions core/domain/tbs/tbs_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestTbsApp_EmptyTest(t *testing.T) {
codePath := "../../../_fixtures/tbs/code/EmptyTest.java"
result := buildTbsResult(codePath)

g.Expect(len(result)).To(Equal(1))
g.Expect(result[0].Type).To(Equal("EmptyTest"))
}

Expand All @@ -24,9 +25,19 @@ func TestTbsApp_IgnoreTest(t *testing.T) {
codePath := "../../../_fixtures/tbs/code/IgnoreTest.java"
result := buildTbsResult(codePath)

g.Expect(len(result)).To(Equal(1))
g.Expect(result[0].Type).To(Equal("IgnoreTest"))
}

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

codePath := "../../../_fixtures/tbs/code/RedundantPrintTest.java"
result := buildTbsResult(codePath)

g.Expect(result[0].Type).To(Equal("RedundantPrintTest"))
}

func buildTbsResult(codePath string) []TestBadSmell {
files := support.GetJavaTestFiles(codePath)
var identifiers []models.JIdentifier
Expand Down

0 comments on commit 7528520

Please sign in to comment.