tbs_app_test.go 2.5 KB
Newer Older
P
Phodal Huang 已提交
1 2 3 4 5 6 7 8
package tbs

import (
	. "github.com/onsi/gomega"
	"github.com/phodal/coca/core/adapter"
	"github.com/phodal/coca/core/adapter/call"
	"github.com/phodal/coca/core/models"
	"github.com/phodal/coca/core/support"
P
Phodal Huang 已提交
9
	"path/filepath"
P
Phodal Huang 已提交
10 11 12
	"testing"
)

P
Phodal Huang 已提交
13
func TestTbsApp_EmptyTest(t *testing.T) {
P
Phodal Huang 已提交
14 15 16
	g := NewGomegaWithT(t)

	codePath := "../../../_fixtures/tbs/code/EmptyTest.java"
P
Phodal Huang 已提交
17
	codePath = filepath.FromSlash(codePath)
P
Phodal Huang 已提交
18 19
	result := buildTbsResult(codePath)

P
Phodal Huang 已提交
20
	g.Expect(len(result)).To(Equal(2))
P
Phodal Huang 已提交
21
	g.Expect(result[0].Type).To(Equal("EmptyTest"))
P
Phodal Huang 已提交
22
	g.Expect(result[1].Type).To(Equal("UnknownTest"))
P
Phodal Huang 已提交
23 24 25 26 27 28
}

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

	codePath := "../../../_fixtures/tbs/code/IgnoreTest.java"
P
Phodal Huang 已提交
29
	codePath = filepath.FromSlash(codePath)
P
Phodal Huang 已提交
30 31
	result := buildTbsResult(codePath)

P
Phodal Huang 已提交
32
	g.Expect(len(result)).To(Equal(2))
P
Phodal Huang 已提交
33 34 35
	g.Expect(result[0].Type).To(Equal("IgnoreTest"))
}

P
Phodal Huang 已提交
36 37 38 39
func TestTbsApp_RedundantPrintTest(t *testing.T) {
	g := NewGomegaWithT(t)

	codePath := "../../../_fixtures/tbs/code/RedundantPrintTest.java"
P
Phodal Huang 已提交
40
	codePath = filepath.FromSlash(codePath)
P
Phodal Huang 已提交
41 42 43 44 45
	result := buildTbsResult(codePath)

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

P
Phodal Huang 已提交
46 47 48 49
func TestTbsApp_SleepyTest(t *testing.T) {
	g := NewGomegaWithT(t)

	codePath := "../../../_fixtures/tbs/code/SleepyTest.java"
P
Phodal Huang 已提交
50
	codePath = filepath.FromSlash(codePath)
P
Phodal Huang 已提交
51 52 53 54 55
	result := buildTbsResult(codePath)

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

P
Phodal Huang 已提交
56 57 58 59 60 61 62 63 64 65
func TestTbsApp_DuplicateAssertTest(t *testing.T) {
	g := NewGomegaWithT(t)

	codePath := "../../../_fixtures/tbs/code/DuplicateAssertTest.java"
	codePath = filepath.FromSlash(codePath)
	result := buildTbsResult(codePath)

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

P
Phodal Huang 已提交
66 67 68 69 70 71 72 73 74 75 76
func TestTbsApp_UnknownTest(t *testing.T) {
	g := NewGomegaWithT(t)

	codePath := "../../../_fixtures/tbs/code/UnknownTest.java"
	codePath = filepath.FromSlash(codePath)
	result := buildTbsResult(codePath)

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

P
Phodal Huang 已提交
77
func buildTbsResult(codePath string) []TestBadSmell {
P
Phodal Huang 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	files := support.GetJavaTestFiles(codePath)
	var identifiers []models.JIdentifier

	identifiers = adapter.LoadTestIdentify(files)
	identifiersMap := adapter.BuildIdentifierMap(identifiers)

	var classes []string = nil
	for _, node := range identifiers {
		classes = append(classes, node.Package+"."+node.ClassName)
	}

	analysisApp := call.NewJavaCallApp()
	classNodes := analysisApp.AnalysisFiles(identifiers, files, classes)

	app := NewTbsApp()
	result := app.AnalysisPath(classNodes, identifiersMap)
P
Phodal Huang 已提交
94
	return result
P
Phodal Huang 已提交
95
}