1
+ /**
2
+ * backelite-sonar-swift-plugin - Enables analysis of Swift and Objective-C projects into SonarQube.
3
+ * Copyright © 2015 Backelite (${email})
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Lesser General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ package com .backelite .sonarqube .swift .complexity ;
19
+
20
+ import org .junit .Test ;
21
+ import org .junit .runner .RunWith ;
22
+ import org .mockito .ArgumentCaptor ;
23
+ import org .mockito .Captor ;
24
+ import org .mockito .Mock ;
25
+ import org .mockito .runners .MockitoJUnitRunner ;
26
+ import org .sonar .api .batch .fs .*;
27
+ import org .sonar .api .batch .measure .Metric ;
28
+ import org .sonar .api .batch .sensor .SensorContext ;
29
+ import org .sonar .api .batch .sensor .measure .NewMeasure ;
30
+
31
+ import java .io .File ;
32
+ import java .util .Arrays ;
33
+
34
+ import static org .junit .Assert .assertEquals ;
35
+ import static org .mockito .Mockito .when ;
36
+
37
+ @ RunWith (MockitoJUnitRunner .class )
38
+ public class LizardReportParserTest {
39
+
40
+ @ Mock
41
+ SensorContext sensorContext ;
42
+
43
+ @ Mock
44
+ FileSystem fileSystem ;
45
+
46
+ @ Mock
47
+ FilePredicates filePredicates ;
48
+
49
+ @ Mock
50
+ FilePredicate filePredicate ;
51
+
52
+ @ Mock
53
+ InputFile inputFile ;
54
+
55
+ @ Mock
56
+ NewMeasure <Integer > newMeasure ;
57
+
58
+ @ Captor
59
+ ArgumentCaptor <String > hasRelativePathCaptor ;
60
+
61
+ @ Captor
62
+ ArgumentCaptor <InputComponent > onCaptor ;
63
+
64
+ @ Captor
65
+ ArgumentCaptor <Metric <Integer >> forMetricCaptor ;
66
+
67
+ @ Captor
68
+ ArgumentCaptor <Integer > withValueCaptor ;
69
+
70
+
71
+ @ Test
72
+ public void parseSimpleFile () {
73
+
74
+ LizardReportParser parser = new LizardReportParser (sensorContext );
75
+ File xmlFile = new File ("src/test/resources/lizard-report.xml" );
76
+
77
+ when (sensorContext .<Integer >newMeasure ()).thenReturn (newMeasure );
78
+ when (newMeasure .on (onCaptor .capture ())).thenReturn (newMeasure );
79
+ when (newMeasure .forMetric (forMetricCaptor .capture ())).thenReturn (newMeasure );
80
+ when (newMeasure .withValue (withValueCaptor .capture ())).thenReturn (newMeasure );
81
+
82
+ when (sensorContext .fileSystem ()).thenReturn (fileSystem );
83
+ when (fileSystem .predicates ()).thenReturn (filePredicates );
84
+ when (filePredicates .hasRelativePath (hasRelativePathCaptor .capture ())).thenReturn (filePredicate );
85
+ when (fileSystem .hasFiles (filePredicate )).thenReturn (true );
86
+ when (fileSystem .inputFile (filePredicate )).thenReturn (inputFile );
87
+
88
+ parser .parseReport (xmlFile );
89
+
90
+ assertEquals (5 , onCaptor .getAllValues ().size ());
91
+ assertEquals (5 , forMetricCaptor .getAllValues ().size ());
92
+
93
+ assertEquals (Arrays .asList (1 , 4 , 8 , 5 , 46 ), withValueCaptor .getAllValues ());
94
+ assertEquals (Arrays .asList ("./Folder With Space/File With Space.swift" ), hasRelativePathCaptor .getAllValues ());
95
+ }
96
+
97
+ }
0 commit comments