2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.server.computation.step;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.sonar.server.computation.batch.TreeRootHolderRule;
26 import org.sonar.server.computation.duplication.DuplicationRepositoryRule;
27 import org.sonar.server.computation.duplication.TextBlock;
28 import org.sonar.server.computation.measure.MeasureRepositoryRule;
29 import org.sonar.server.computation.metric.MetricRepositoryRule;
31 import static com.google.common.base.Preconditions.checkArgument;
32 import static org.assertj.core.api.Assertions.assertThat;
33 import static org.assertj.guava.api.Assertions.assertThat;
34 import static org.sonar.api.measures.CoreMetrics.COMMENT_LINES;
35 import static org.sonar.api.measures.CoreMetrics.COMMENT_LINES_KEY;
36 import static org.sonar.api.measures.CoreMetrics.DUPLICATED_BLOCKS;
37 import static org.sonar.api.measures.CoreMetrics.DUPLICATED_BLOCKS_KEY;
38 import static org.sonar.api.measures.CoreMetrics.DUPLICATED_FILES;
39 import static org.sonar.api.measures.CoreMetrics.DUPLICATED_FILES_KEY;
40 import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES;
41 import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY;
42 import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY;
43 import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_KEY;
44 import static org.sonar.api.measures.CoreMetrics.LINES;
45 import static org.sonar.api.measures.CoreMetrics.LINES_KEY;
46 import static org.sonar.api.measures.CoreMetrics.NCLOC;
47 import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
48 import static org.sonar.server.computation.component.Component.Type.DIRECTORY;
49 import static org.sonar.server.computation.component.Component.Type.FILE;
50 import static org.sonar.server.computation.component.Component.Type.MODULE;
51 import static org.sonar.server.computation.component.Component.Type.PROJECT;
52 import static org.sonar.server.computation.component.ReportComponent.builder;
53 import static org.sonar.server.computation.measure.Measure.newMeasureBuilder;
55 public class ReportDuplicationMeasuresStepTest {
57 private static final int ROOT_REF = 1;
58 private static final int MODULE_REF = 12;
59 private static final int SUB_MODULE_1_REF = 123;
60 private static final int SUB_MODULE_2_REF = 126;
61 private static final int DIRECTORY_REF = 1234;
62 private static final int FILE_1_REF = 12341;
63 private static final int FILE_2_REF = 12342;
64 private static final int FILE_3_REF = 1261;
65 private static final int FILE_4_REF = 1262;
66 private static final String SOME_FILE_KEY = "some file key";
69 public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()
71 builder(PROJECT, ROOT_REF)
73 builder(MODULE, MODULE_REF)
75 builder(MODULE, SUB_MODULE_1_REF)
77 builder(DIRECTORY, DIRECTORY_REF)
79 builder(FILE, FILE_1_REF).build(),
80 builder(FILE, FILE_2_REF).build())
83 builder(MODULE, SUB_MODULE_2_REF)
85 builder(FILE, FILE_3_REF).build(),
86 builder(FILE, FILE_4_REF).build()
92 public MetricRepositoryRule metricRepository = new MetricRepositoryRule()
96 .add(DUPLICATED_BLOCKS)
97 .add(DUPLICATED_FILES)
98 .add(DUPLICATED_LINES)
99 .add(DUPLICATED_LINES_DENSITY);
101 public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
103 public DuplicationRepositoryRule duplicationRepository = DuplicationRepositoryRule.create(treeRootHolder);
105 ComputationStep underTest = new DuplicationMeasuresStep(treeRootHolder, metricRepository, measureRepository, duplicationRepository);
108 public void compute_duplicated_blocks_one_for_original_one_for_each_InnerDuplicate() {
109 TextBlock original = new TextBlock(1, 1);
110 duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(2, 2));
111 duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(3, 3));
112 duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(2, 3));
116 assertRawMeasureValue(FILE_1_REF, DUPLICATED_BLOCKS_KEY, 4);
120 public void compute_duplicated_blocks_does_not_count_blocks_only_once_it_assumes_consistency_from_duplication_data() {
121 duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 1), new TextBlock(3, 3));
122 duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(2, 2), new TextBlock(3, 3));
126 assertRawMeasureValue(FILE_1_REF, DUPLICATED_BLOCKS_KEY, 4);
130 public void compute_duplicated_blocks_one_for_original_and_ignores_InProjectDuplicate() {
131 duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 1), FILE_2_REF, new TextBlock(2, 2));
135 assertRawMeasureValue(FILE_1_REF, DUPLICATED_BLOCKS_KEY, 1);
139 public void compute_duplicated_blocks_one_for_original_and_ignores_CrossProjectDuplicate() {
140 duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 1), SOME_FILE_KEY, new TextBlock(2, 2));
144 assertRawMeasureValue(FILE_1_REF, DUPLICATED_BLOCKS_KEY, 1);
148 public void compute_and_aggregate_duplicated_blocks_from_single_duplication() {
149 addDuplicatedBlock(FILE_1_REF, 10);
150 addDuplicatedBlock(FILE_2_REF, 40);
151 addDuplicatedBlock(FILE_4_REF, 5);
155 assertRawMeasureValue(FILE_1_REF, DUPLICATED_BLOCKS_KEY, 10);
156 assertRawMeasureValue(FILE_2_REF, DUPLICATED_BLOCKS_KEY, 40);
157 assertRawMeasureValue(FILE_3_REF, DUPLICATED_BLOCKS_KEY, 0);
158 assertRawMeasureValue(FILE_4_REF, DUPLICATED_BLOCKS_KEY, 5);
159 assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_BLOCKS_KEY, 50);
160 assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_BLOCKS_KEY, 50);
161 assertRawMeasureValue(SUB_MODULE_2_REF, DUPLICATED_BLOCKS_KEY, 5);
162 assertRawMeasureValue(MODULE_REF, DUPLICATED_BLOCKS_KEY, 55);
163 assertRawMeasureValue(ROOT_REF, DUPLICATED_BLOCKS_KEY, 55);
167 public void compute_and_aggregate_duplicated_blocks_to_zero_when_no_duplication() {
170 assertComputedAndAggregatedToZeroInt(DUPLICATED_BLOCKS_KEY);
174 public void compute_duplicated_lines_counts_lines_from_original_and_InnerDuplicate_of_a_single_line() {
175 TextBlock original = new TextBlock(1, 1);
176 duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(2, 2));
180 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_KEY, 2);
184 public void compute_duplicated_lines_counts_lines_from_original_and_ignores_InProjectDuplicate() {
185 TextBlock original = new TextBlock(1, 1);
186 duplicationRepository.addDuplication(FILE_1_REF, original, FILE_2_REF, new TextBlock(2, 2));
190 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_KEY, 1);
194 public void compute_duplicated_lines_counts_lines_from_original_and_ignores_CrossProjectDuplicate() {
195 TextBlock original = new TextBlock(1, 1);
196 duplicationRepository.addDuplication(FILE_1_REF, original, SOME_FILE_KEY, new TextBlock(2, 2));
200 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_KEY, 1);
204 public void compute_duplicated_lines_counts_lines_from_original_and_InnerDuplicate() {
205 TextBlock original = new TextBlock(1, 5);
206 duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(10, 11));
210 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_KEY, 7);
214 public void compute_duplicated_lines_counts_lines_from_original_and_InnerDuplicate_only_once() {
215 TextBlock original = new TextBlock(1, 12);
216 duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(10, 11));
217 duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(11, 15));
218 duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(2, 2), new TextBlock(96, 96));
222 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_KEY, 16);
226 public void compute_and_aggregate_duplicated_files() {
227 addDuplicatedBlock(FILE_1_REF, 2);
228 addDuplicatedBlock(FILE_3_REF, 10);
229 addDuplicatedBlock(FILE_4_REF, 50);
233 assertRawMeasureValue(FILE_1_REF, DUPLICATED_FILES_KEY, 1);
234 assertRawMeasureValue(FILE_2_REF, DUPLICATED_FILES_KEY, 0);
235 assertRawMeasureValue(FILE_3_REF, DUPLICATED_FILES_KEY, 1);
236 assertRawMeasureValue(FILE_4_REF, DUPLICATED_FILES_KEY, 1);
237 assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_FILES_KEY, 1);
238 assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_FILES_KEY, 1);
239 assertRawMeasureValue(SUB_MODULE_2_REF, DUPLICATED_FILES_KEY, 2);
240 assertRawMeasureValue(MODULE_REF, DUPLICATED_FILES_KEY, 3);
241 assertRawMeasureValue(ROOT_REF, DUPLICATED_FILES_KEY, 3);
245 public void compute_and_aggregate_zero_duplicated_files_when_no_duplication_data() {
248 assertComputedAndAggregatedToZeroInt(DUPLICATED_FILES_KEY);
252 public void compute_and_aggregate_duplicated_lines() {
253 addDuplicatedBlock(FILE_1_REF, 10);
254 addDuplicatedBlock(FILE_2_REF, 9);
255 addDuplicatedBlock(FILE_4_REF, 7);
259 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_KEY, 10);
260 assertRawMeasureValue(FILE_2_REF, DUPLICATED_LINES_KEY, 9);
261 assertRawMeasureValue(FILE_3_REF, DUPLICATED_LINES_KEY, 0);
262 assertRawMeasureValue(FILE_4_REF, DUPLICATED_LINES_KEY, 7);
263 assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_LINES_KEY, 19);
264 assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_LINES_KEY, 19);
265 assertRawMeasureValue(SUB_MODULE_2_REF, DUPLICATED_LINES_KEY, 7);
266 assertRawMeasureValue(MODULE_REF, DUPLICATED_LINES_KEY, 26);
267 assertRawMeasureValue(ROOT_REF, DUPLICATED_LINES_KEY, 26);
271 public void compute_and_aggregate_zero_duplicated_line_when_no_duplication() {
274 String metricKey = DUPLICATED_LINES_KEY;
275 assertComputedAndAggregatedToZeroInt(metricKey);
279 public void compute_and_aggregate_duplicated_lines_density_using_lines() throws Exception {
280 addDuplicatedBlock(FILE_1_REF, 2);
281 addDuplicatedBlock(FILE_2_REF, 3);
283 addRawMeasure(FILE_1_REF, LINES_KEY, 10);
284 addRawMeasure(FILE_2_REF, LINES_KEY, 40);
285 addRawMeasure(DIRECTORY_REF, LINES_KEY, 50);
286 addRawMeasure(SUB_MODULE_1_REF, LINES_KEY, 50);
287 addRawMeasure(MODULE_REF, LINES_KEY, 50);
288 addRawMeasure(ROOT_REF, LINES_KEY, 50);
292 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 20d);
293 assertRawMeasureValue(FILE_2_REF, DUPLICATED_LINES_DENSITY_KEY, 7.5d);
294 assertNoRawMeasure(FILE_3_REF, DUPLICATED_LINES_DENSITY_KEY);
295 assertNoRawMeasure(FILE_4_REF, DUPLICATED_LINES_DENSITY_KEY);
296 assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
297 assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
298 assertNoRawMeasure(SUB_MODULE_2_REF, DUPLICATED_LINES_DENSITY_KEY);
299 assertRawMeasureValue(MODULE_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
300 assertRawMeasureValue(ROOT_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
304 public void compute_and_aggregate_duplicated_lines_density_using_nclocs_and_comment_lines() throws Exception {
305 addDuplicatedBlock(FILE_1_REF, 2);
306 addDuplicatedBlock(FILE_2_REF, 3);
308 addRawMeasure(FILE_1_REF, COMMENT_LINES_KEY, 2);
309 addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, 10);
310 addRawMeasure(DIRECTORY_REF, COMMENT_LINES_KEY, 12);
311 addRawMeasure(SUB_MODULE_1_REF, COMMENT_LINES_KEY, 12);
312 addRawMeasure(MODULE_REF, COMMENT_LINES_KEY, 12);
313 addRawMeasure(ROOT_REF, COMMENT_LINES_KEY, 12);
315 addRawMeasure(FILE_1_REF, NCLOC_KEY, 8);
316 addRawMeasure(FILE_2_REF, NCLOC_KEY, 30);
317 addRawMeasure(DIRECTORY_REF, NCLOC_KEY, 38);
318 addRawMeasure(SUB_MODULE_1_REF, NCLOC_KEY, 38);
319 addRawMeasure(MODULE_REF, NCLOC_KEY, 38);
320 addRawMeasure(ROOT_REF, NCLOC_KEY, 38);
324 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 20d);
325 assertRawMeasureValue(FILE_2_REF, DUPLICATED_LINES_DENSITY_KEY, 7.5d);
326 assertNoRawMeasure(FILE_3_REF, DUPLICATED_LINES_DENSITY_KEY);
327 assertNoRawMeasure(FILE_4_REF, DUPLICATED_LINES_DENSITY_KEY);
328 assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
329 assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
330 assertNoRawMeasure(SUB_MODULE_2_REF, DUPLICATED_LINES_DENSITY_KEY);
331 assertRawMeasureValue(MODULE_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
332 assertRawMeasureValue(ROOT_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
336 public void compute_duplicated_lines_density_using_only_nclocs() throws Exception {
337 addDuplicatedBlock(FILE_1_REF, 2);
338 addDuplicatedBlock(FILE_2_REF, 3);
340 addRawMeasure(FILE_1_REF, NCLOC_KEY, 10);
341 addRawMeasure(FILE_2_REF, NCLOC_KEY, 40);
342 addRawMeasure(DIRECTORY_REF, NCLOC_KEY, 50);
343 addRawMeasure(SUB_MODULE_1_REF, NCLOC_KEY, 50);
344 addRawMeasure(MODULE_REF, NCLOC_KEY, 50);
345 addRawMeasure(ROOT_REF, NCLOC_KEY, 50);
349 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 20d);
350 assertRawMeasureValue(FILE_2_REF, DUPLICATED_LINES_DENSITY_KEY, 7.5d);
351 assertNoRawMeasure(FILE_3_REF, DUPLICATED_LINES_DENSITY_KEY);
352 assertNoRawMeasure(FILE_4_REF, DUPLICATED_LINES_DENSITY_KEY);
353 assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
354 assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
355 assertNoRawMeasure(SUB_MODULE_2_REF, DUPLICATED_LINES_DENSITY_KEY);
356 assertRawMeasureValue(MODULE_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
357 assertRawMeasureValue(ROOT_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
361 public void compute_zero_percent_duplicated_lines_density_when_there_is_no_duplication() throws Exception {
362 addRawMeasure(FILE_1_REF, COMMENT_LINES_KEY, 2);
363 addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, 10);
364 addRawMeasure(DIRECTORY_REF, COMMENT_LINES_KEY, 12);
365 addRawMeasure(SUB_MODULE_1_REF, COMMENT_LINES_KEY, 12);
366 addRawMeasure(MODULE_REF, COMMENT_LINES_KEY, 12);
367 addRawMeasure(ROOT_REF, COMMENT_LINES_KEY, 12);
369 addRawMeasure(FILE_1_REF, NCLOC_KEY, 8);
370 addRawMeasure(FILE_2_REF, NCLOC_KEY, 30);
371 addRawMeasure(DIRECTORY_REF, NCLOC_KEY, 38);
372 addRawMeasure(SUB_MODULE_1_REF, NCLOC_KEY, 38);
373 addRawMeasure(MODULE_REF, NCLOC_KEY, 38);
374 addRawMeasure(ROOT_REF, NCLOC_KEY, 38);
378 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 0d);
379 assertRawMeasureValue(FILE_2_REF, DUPLICATED_LINES_DENSITY_KEY, 0d);
380 assertNoRawMeasure(FILE_3_REF, DUPLICATED_LINES_DENSITY_KEY);
381 assertNoRawMeasure(FILE_4_REF, DUPLICATED_LINES_DENSITY_KEY);
382 assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_LINES_DENSITY_KEY, 0d);
383 assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 0d);
384 assertNoRawMeasure(SUB_MODULE_2_REF, DUPLICATED_LINES_DENSITY_KEY);
385 assertRawMeasureValue(MODULE_REF, DUPLICATED_LINES_DENSITY_KEY, 0d);
386 assertRawMeasureValue(ROOT_REF, DUPLICATED_LINES_DENSITY_KEY, 0d);
390 public void not_compute_duplicated_lines_density_when_lines_is_zero() throws Exception {
391 addRawMeasure(FILE_1_REF, LINES_KEY, 0);
392 addRawMeasure(FILE_2_REF, LINES_KEY, 0);
393 addRawMeasure(DIRECTORY_REF, LINES_KEY, 0);
394 addRawMeasure(SUB_MODULE_1_REF, LINES_KEY, 0);
395 addRawMeasure(MODULE_REF, LINES_KEY, 0);
396 addRawMeasure(ROOT_REF, LINES_KEY, 0);
400 assertNoRawMeasures(DUPLICATED_LINES_DENSITY_KEY);
404 public void not_compute_duplicated_lines_density_when_ncloc_and_comment_are_zero() throws Exception {
405 addRawMeasure(FILE_1_REF, COMMENT_LINES_KEY, 0);
406 addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, 0);
407 addRawMeasure(DIRECTORY_REF, COMMENT_LINES_KEY, 0);
408 addRawMeasure(SUB_MODULE_1_REF, COMMENT_LINES_KEY, 0);
409 addRawMeasure(MODULE_REF, COMMENT_LINES_KEY, 0);
410 addRawMeasure(ROOT_REF, COMMENT_LINES_KEY, 0);
412 addRawMeasure(FILE_1_REF, NCLOC_KEY, 0);
413 addRawMeasure(FILE_2_REF, NCLOC_KEY, 0);
414 addRawMeasure(DIRECTORY_REF, NCLOC_KEY, 0);
415 addRawMeasure(SUB_MODULE_1_REF, NCLOC_KEY, 0);
416 addRawMeasure(MODULE_REF, NCLOC_KEY, 0);
417 addRawMeasure(ROOT_REF, NCLOC_KEY, 0);
421 assertNoRawMeasures(DUPLICATED_LINES_DENSITY_KEY);
425 public void compute_100_percent_duplicated_lines_density() throws Exception {
426 addDuplicatedBlock(FILE_1_REF, 2);
427 addDuplicatedBlock(FILE_2_REF, 3);
429 addRawMeasure(FILE_1_REF, LINES_KEY, 2);
430 addRawMeasure(FILE_2_REF, LINES_KEY, 3);
431 addRawMeasure(DIRECTORY_REF, LINES_KEY, 5);
432 addRawMeasure(SUB_MODULE_1_REF, LINES_KEY, 5);
433 addRawMeasure(MODULE_REF, LINES_KEY, 5);
434 addRawMeasure(ROOT_REF, LINES_KEY, 5);
438 assertRawMeasureValue(FILE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 100d);
439 assertRawMeasureValue(FILE_2_REF, DUPLICATED_LINES_DENSITY_KEY, 100d);
440 assertNoRawMeasure(FILE_3_REF, DUPLICATED_LINES_DENSITY_KEY);
441 assertNoRawMeasure(FILE_4_REF, DUPLICATED_LINES_DENSITY_KEY);
442 assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_LINES_DENSITY_KEY, 100d);
443 assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 100d);
444 assertNoRawMeasure(SUB_MODULE_2_REF, DUPLICATED_LINES_DENSITY_KEY);
445 assertRawMeasureValue(MODULE_REF, DUPLICATED_LINES_DENSITY_KEY, 100d);
446 assertRawMeasureValue(ROOT_REF, DUPLICATED_LINES_DENSITY_KEY, 100d);
450 * Adds duplication blocks of a single line (each line is specific to its block).
452 * This is a very simple use case, convenient for unit tests but more realistic and complex use cases must be tested separately.
454 private void addDuplicatedBlock(int fileRef, int blockCount) {
455 checkArgument(blockCount > 1, "BlockCount can not be less than 2");
456 TextBlock original = new TextBlock(1, 1);
457 for (int i = 10; i < blockCount + 9; i++) {
458 duplicationRepository.addDuplication(fileRef, original, new TextBlock(i, i));
462 private void addRawMeasure(int componentRef, String metricKey, int value) {
463 measureRepository.addRawMeasure(componentRef, metricKey, newMeasureBuilder().create(value));
466 private void assertNoRawMeasures(String metricKey) {
467 assertThat(measureRepository.getAddedRawMeasures(FILE_1_REF).get(metricKey)).isEmpty();
468 assertThat(measureRepository.getAddedRawMeasures(FILE_2_REF).get(metricKey)).isEmpty();
469 assertThat(measureRepository.getAddedRawMeasures(DIRECTORY_REF).get(metricKey)).isEmpty();
470 assertThat(measureRepository.getAddedRawMeasures(SUB_MODULE_1_REF).get(metricKey)).isEmpty();
471 assertThat(measureRepository.getAddedRawMeasures(MODULE_REF).get(metricKey)).isEmpty();
472 assertThat(measureRepository.getAddedRawMeasures(ROOT_REF).get(metricKey)).isEmpty();
475 private void assertNoRawMeasure(int componentRef, String metricKey) {
476 assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)).isAbsent();
479 private void assertRawMeasureValue(int componentRef, String metricKey, int value) {
480 assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey).get().getIntValue()).isEqualTo(value);
483 private void assertRawMeasureValue(int componentRef, String metricKey, double value) {
484 assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey).get().getDoubleValue()).isEqualTo(value);
487 private void assertComputedAndAggregatedToZeroInt(String metricKey) {
488 assertRawMeasureValue(FILE_1_REF, metricKey, 0);
489 assertRawMeasureValue(FILE_2_REF, metricKey, 0);
490 assertRawMeasureValue(FILE_3_REF, metricKey, 0);
491 assertRawMeasureValue(FILE_4_REF, metricKey, 0);
492 assertRawMeasureValue(DIRECTORY_REF, metricKey, 0);
493 assertRawMeasureValue(SUB_MODULE_1_REF, metricKey, 0);
494 assertRawMeasureValue(SUB_MODULE_2_REF, metricKey, 0);
495 assertRawMeasureValue(MODULE_REF, metricKey, 0);
496 assertRawMeasureValue(ROOT_REF, metricKey, 0);