~ubuntu-branches/ubuntu/trusty/gmetrics/trusty

« back to all changes in this revision

Viewing changes to src/test/groovy/org/gmetrics/metricset/MetricSetBuilderTest.groovy

  • Committer: Package Import Robot
  • Author(s): Miguel Landaeta, Miguel Landaeta, tony mancill
  • Date: 2012-01-18 20:57:50 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120118205750-68fv86p7fs8xz470
Tags: 0.5-1
[Miguel Landaeta]
* New upstream release.
* Remove patch ftbfs_613266.diff since it was merged upstream.
* Update dates in copyright file.

[tony mancill]
* Set DMUA flag.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2010 the original author or authors.
 
2
 * Copyright 2012 the original author or authors.
3
3
 * 
4
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
5
 * you may not use this file except in compliance with the License.
18
18
import org.gmetrics.test.AbstractTestCase
19
19
import org.gmetrics.metric.abc.AbcMetric
20
20
import org.gmetrics.metric.StubMetric
 
21
import org.gmetrics.metricregistry.MetricRegistryHolder
 
22
import org.gmetrics.metricregistry.MetricRegistry
 
23
import org.gmetrics.metric.crap.CrapMetric
21
24
 
22
25
/**
23
26
 * Tests for MetricSetBuilder
24
27
 *
25
28
 * @author Chris Mair
26
 
 * @version $Revision: 103 $ - $Date: 2010-05-31 17:15:42 -0400 (Mon, 31 May 2010) $
27
29
 */
28
30
class MetricSetBuilderTest extends AbstractTestCase {
29
31
 
30
32
    private metricSetBuilder
 
33
    private newMetric
 
34
    private originalMetricRegistry
31
35
 
32
36
    void testMetricset_NullFilename() {
33
37
        log(metricSetBuilder)
56
60
        assertMetricProperties('NewName', [otherProperty:'888'])
57
61
    }
58
62
 
 
63
    void testMetricset_GroovyFile_NestedMetricDefinitionNotIncludedInMetricSet() {
 
64
        metricSetBuilder.metricset {
 
65
            metricset(MetricSetTestFiles.METRICSET1) {
 
66
                Stub {
 
67
                    otherProperty = ABC
 
68
                }
 
69
            }
 
70
        }
 
71
        assertMetricNames('Stub', 'XXX')
 
72
    }
 
73
 
59
74
    void testMetricset_GroovyFile_ConfigureMetricUsingMap_MetricNotFound() {
60
75
        shouldFailWithMessageContaining('NotFound') {
61
76
            metricSetBuilder.metricset {
97
112
        assertMetricNames('Stub', 'XXX')
98
113
    }
99
114
 
 
115
    void testMetric_Class_Map() {
 
116
        metricSetBuilder.metricset {
 
117
            newMetric = metric(AbcMetric, [enabled:false])
 
118
        }
 
119
        assertMetricNames('ABC')
 
120
        assert !findMetric('ABC').enabled
 
121
        assert newMetric instanceof AbcMetric
 
122
    }
 
123
 
100
124
    void testMetric_Class_NoClosure() {
101
125
        metricSetBuilder.metricset {
102
 
            metric AbcMetric
 
126
            newMetric = metric(AbcMetric)
103
127
        }
104
128
        assertMetricNames('ABC')
 
129
        assert newMetric instanceof AbcMetric
105
130
    }
106
131
 
107
132
    void testMetric_Class_NoClosure_NullMetricClass() {
125
150
            metric(StubMetric) {
126
151
                name = 'xxx'
127
152
            }
128
 
            metric(StubMetric) {
 
153
            newMetric = metric(StubMetric) {
129
154
                name = 'yyyy'
130
155
                otherProperty = '1234'
131
156
            }
133
158
        }
134
159
        assertMetricNames('xxx', 'yyyy')
135
160
        assert findMetric('yyyy').otherProperty == '1234'
 
161
        assert newMetric.name == 'yyyy'
136
162
    }
137
163
 
138
164
    void testMetric_Class_Closure_NullRuleClass() {
155
181
        }
156
182
    }
157
183
 
 
184
    void testMetric_MetricName_EmptyParentheses() {
 
185
        metricSetBuilder.metricset {
 
186
            newMetric = ABC()
 
187
        }
 
188
        assertMetricNames('ABC')
 
189
        assert newMetric instanceof AbcMetric
 
190
    }
 
191
 
 
192
    void testMetric_MetricName_ParenthesesWithMap() {
 
193
        metricSetBuilder.metricset {
 
194
            newMetric = ABC([enabled:false])
 
195
        }
 
196
        assertMetricNames('ABC')
 
197
        assert !findMetric('ABC').enabled
 
198
        assert newMetric instanceof AbcMetric
 
199
    }
 
200
 
 
201
    void testMetric_MetricName_NoParenthesesWithClosure() {
 
202
        metricSetBuilder.metricset {
 
203
            newMetric = ABC {
 
204
                enabled = false
 
205
            }
 
206
        }
 
207
        assertMetricNames('ABC')
 
208
        assert !findMetric('ABC').enabled
 
209
        assert newMetric instanceof AbcMetric
 
210
    }
 
211
 
 
212
    void testMetric_NestedMetricDefinitionUsingMetric_NotIncludedInMetricSet() {
 
213
        metricSetBuilder.metricset {
 
214
            CRAP {
 
215
                coverageMetric = metric(StubMetric)
 
216
            }
 
217
        }
 
218
        assertMetricNames('CRAP')
 
219
    }
 
220
 
 
221
    void testMetric_NestedMetricDefinitionUsingMetricWithMap_NotIncludedInMetricSet() {
 
222
        metricSetBuilder.metricset {
 
223
            CRAP {
 
224
                coverageMetric = metric(StubMetric, [name:'yyyy'])
 
225
            }
 
226
        }
 
227
        assertMetricNames('CRAP')
 
228
    }
 
229
 
 
230
    void testMetric_NestedMetricDefinitionUsingMetricWithClosure_NotIncludedInMetricSet() {
 
231
        metricSetBuilder.metricset {
 
232
            CRAP {
 
233
                coverageMetric = metric(StubMetric) {
 
234
                    name = 'yyyy'
 
235
                    otherProperty = '1234'
 
236
                }
 
237
            }
 
238
        }
 
239
        assertMetricNames('CRAP')
 
240
    }
 
241
 
 
242
    void testMetric_NestedMetricDefinition_AssignNestedMetricWithinMap_KnownLimitation() {
 
243
        metricSetBuilder.metricset {
 
244
            CRAP(coverageMetric:ABC)
 
245
        }
 
246
        // Known limitation *****
 
247
        assertMetricNames('ABC', 'CRAP')
 
248
    }
 
249
 
 
250
    void testMetric_NestedMetricDefinitionUsingMetricNameWithClosure_NotIncludedInMetricSet() {
 
251
        metricSetBuilder.metricset {
 
252
            CRAP {
 
253
                coverageMetric = ABC {
 
254
                    enabled = false
 
255
                }
 
256
            }
 
257
        }
 
258
        assertMetricNames('CRAP')
 
259
    }
 
260
 
 
261
    void testMetric_NestedMetricDefinitionUsingMetricNameWithMap_IsIncludedInMetricSet() {
 
262
        metricSetBuilder.metricset {
 
263
            CRAP([coverageMetric: ABC(enabled:false)])
 
264
        }
 
265
        assertMetricNames('ABC', 'CRAP')
 
266
    }
 
267
 
 
268
    void testMetric_MetricName_NoParenthesesOrClosure() {
 
269
        metricSetBuilder.metricset {
 
270
            newMetric = ABC
 
271
        }
 
272
        assertMetricNames('ABC')
 
273
        assert newMetric instanceof AbcMetric
 
274
    }
 
275
 
 
276
    void testMetric_MetricName_NoSuchMetricName() {
 
277
        MetricRegistryHolder.metricRegistry = [getMetricClass:{ null }] as MetricRegistry
 
278
        shouldFailWithMessageContaining('DoesNotExist') {
 
279
            metricSetBuilder.metricset {
 
280
                DoesNotExist
 
281
            }
 
282
        }
 
283
    }
 
284
 
158
285
    void testDescription() {
159
286
        metricSetBuilder.metricset {
160
287
            description 'abc'
161
288
        }
162
289
    }
163
290
 
 
291
    //------------------------------------------------------------------------------------
 
292
    // Setup and helper methods
 
293
    //------------------------------------------------------------------------------------
 
294
 
 
295
    @Override
164
296
    void setUp() {
165
297
        super.setUp()
166
298
        metricSetBuilder = new MetricSetBuilder()
 
299
        final METRICS = [CRAP:CrapMetric, ABC:AbcMetric]
 
300
        originalMetricRegistry = MetricRegistryHolder.metricRegistry
 
301
        MetricRegistryHolder.metricRegistry = [getMetricClass:{ name -> METRICS[name] }] as MetricRegistry
 
302
    }
 
303
 
 
304
    @Override
 
305
    protected void tearDown() {
 
306
        super.tearDown()
 
307
        MetricRegistryHolder.metricRegistry = originalMetricRegistry
167
308
    }
168
309
 
169
310
    private MetricSet getMetricSet() {