This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
FindbugsIntegrationTest.groovy
171 lines (147 loc) · 6.57 KB
/
FindbugsIntegrationTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.novoda.staticanalysis.internal.findbugs
import com.novoda.test.TestProject
import com.novoda.test.TestProjectRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import static com.novoda.test.Fixtures.Findbugs.*
import static com.novoda.test.LogsSubject.assertThat
import static com.novoda.test.TestProjectSubject.assumeThat
@RunWith(Parameterized.class)
class FindbugsIntegrationTest {
@Parameterized.Parameters
public static List<Object[]> rules() {
return [TestProjectRule.forJavaProject(), TestProjectRule.forAndroidProject()].collect { [it] as Object[] }
}
@Rule
public final TestProjectRule projectRule
FindbugsIntegrationTest(TestProjectRule projectRule) {
this.projectRule = projectRule
}
@Test
public void shouldFailBuildWhenFindbugsWarningsOverTheThreshold() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withPenalty('''{
maxErrors = 0
maxWarnings = 1
}''')
.withFindbugs('findbugs {}')
.buildAndFail('check')
assertThat(result.logs).containsLimitExceeded(0, 1)
assertThat(result.logs).containsFindbugsViolations(0, 2,
result.buildFile('reports/findbugs/debug.html'))
}
@Test
public void shouldDetectMoreWarningsWhenEffortIsMaxAndReportLevelIsLow() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withPenalty('''{
maxErrors = 0
maxWarnings = 1
}''')
.withFindbugs("findbugs { effort = 'max' \n reportLevel = 'low'}")
.buildAndFail('check')
assertThat(result.logs).containsLimitExceeded(0, 2)
assertThat(result.logs).containsFindbugsViolations(0, 3,
result.buildFile('reports/findbugs/debug.html'))
}
@Test
public void shouldFailBuildWhenFindbugsErrorsOverTheThreshold() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_HIGH_VIOLATION)
.withPenalty('''{
maxErrors = 0
maxWarnings = 0
}''')
.withFindbugs('findbugs {}')
.buildAndFail('check')
assertThat(result.logs).containsLimitExceeded(1, 0)
assertThat(result.logs).containsFindbugsViolations(1, 0,
result.buildFile('reports/findbugs/debug.html'))
}
@Test
public void shouldNotFailBuildWhenNoFindbugsWarningsOrErrorsEncounteredAndNoThresholdTrespassed() {
TestProject.Result result = projectRule.newProject()
.withPenalty('''{
maxErrors = 0
maxWarnings = 0
}''')
.withFindbugs('findbugs {}')
.build('check')
assertThat(result.logs).doesNotContainLimitExceeded()
assertThat(result.logs).doesNotContainFindbugsViolations()
}
@Test
public void shouldNotFailBuildWhenFindbugsWarningsAndErrorsEncounteredAndNoThresholdTrespassed() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withSourceSet('release', SOURCES_WITH_HIGH_VIOLATION)
.withPenalty('''{
maxErrors = 10
maxWarnings = 10
}''')
.withFindbugs('findbugs {}')
.build('check')
assertThat(result.logs).doesNotContainLimitExceeded()
assertThat(result.logs).containsFindbugsViolations(1, 2,
result.buildFile('reports/findbugs/debug.html'),
result.buildFile('reports/findbugs/release.html'))
}
@Test
public void shouldNotFailBuildWhenFindbugsConfiguredToNotIgnoreFailures() {
projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withSourceSet('release', SOURCES_WITH_HIGH_VIOLATION)
.withPenalty('''{
maxErrors = 10
maxWarnings = 10
}''')
.withFindbugs('findbugs { ignoreFailures = false }')
.build('check')
}
@Test
public void shouldNotFailBuildWhenFindbugsNotConfigured() {
projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withSourceSet('release', SOURCES_WITH_HIGH_VIOLATION)
.withPenalty('''{
maxErrors = 0
maxWarnings = 0
}''')
.build('check')
}
@Test
public void shouldNotFailBuildWhenFindbugsConfiguredToIgnoreFaultySourceSets() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withSourceSet('release', SOURCES_WITH_HIGH_VIOLATION)
.withPenalty('''{
maxErrors = 0
maxWarnings = 10
}''')
.withFindbugs('findbugs { exclude "HighPriorityViolator.java" }')
.build('check')
assertThat(result.logs).doesNotContainLimitExceeded()
assertThat(result.logs).containsFindbugsViolations(0, 2,
result.buildFile('reports/findbugs/debug.html'))
}
@Test
public void shouldCollectDuplicatedFindbugsWarningsAndErrorsAcrossAndroidVariantsForSharedSourceSets() {
TestProject project = projectRule.newProject()
assumeThat(project).isAndroidProject()
TestProject.Result result = project
.withSourceSet('main', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION, SOURCES_WITH_HIGH_VIOLATION)
.withPenalty('''{
maxErrors = 10
maxWarnings = 10
}''')
.withFindbugs('findbugs {}')
.build('check')
assertThat(result.logs).doesNotContainLimitExceeded()
assertThat(result.logs).containsFindbugsViolations(2, 4,
result.buildFile('reports/findbugs/debug.html'),
result.buildFile('reports/findbugs/release.html'))
}
}