@@ -64,7 +64,7 @@ public void testIgnoreFileStream() {
64
64
Stream <Path > paths ;
65
65
try {
66
66
paths = sensor .createStream (testerContext );
67
- assertEquals (28 , paths .count ());
67
+ assertEquals (33 , paths .count ());
68
68
69
69
} catch (IOException e ) {
70
70
// TODO Auto-generated catch block
@@ -73,97 +73,95 @@ public void testIgnoreFileStream() {
73
73
74
74
}
75
75
76
- @ Test
77
- public void testExecution () {
78
- final CoverageSensor sensor = new CoverageSensor ();
76
+ private void initFile () {
77
+ String [] listFile = { "util/util.go" , "mathutil/mathutil.go" , "pixel/pixel.go" ,
78
+ "mathutil/filewithnocoverage.go" , "issue60/a.go" , "issue61/simplelinecomment.go" ,
79
+ "issue61/multilinecomment.go" , "issue61/typestruct.go" };
79
80
81
+ BufferedReader reader ;
80
82
try {
81
- BufferedReader reader = new BufferedReader (
82
- new FileReader (new File (CoverageSensor .class .getResource ("/coverage/util/util.go" ).getFile ())));
83
-
84
- String sCurrentLine ;
85
-
86
- StringBuilder sb = new StringBuilder ();
87
- while ((sCurrentLine = reader .readLine ()) != null ) {
88
- sb .append (sCurrentLine + "\n " );
89
- }
90
-
91
- testerContext .fileSystem ().add (new DefaultInputFile ("myProjectKey" , "util/util.go" )
92
- .setLanguage (GoLanguage .KEY ).initMetadata (sb .toString ()));
93
-
94
- reader = new BufferedReader (new FileReader (
95
- new File (CoverageSensor .class .getResource ("/coverage/mathutil/mathutil.go" ).getFile ())));
96
-
97
- sb = new StringBuilder ();
98
- while ((sCurrentLine = reader .readLine ()) != null ) {
99
- sb .append (sCurrentLine + "\n " );
100
- }
101
-
102
- testerContext .fileSystem ().add (new DefaultInputFile ("myProjectKey" , "mathutil/mathutil.go" )
103
- .setLanguage (GoLanguage .KEY ).initMetadata (sb .toString ()));
104
83
105
- reader = new BufferedReader (
106
- new FileReader (new File (CoverageSensor .class .getResource ("/coverage/pixel/pixel.go" ).getFile ())));
84
+ for (int i = 0 ; i < listFile .length ; i ++) {
85
+ System .out .println (listFile [i ]);
86
+ reader = new BufferedReader (new FileReader (
87
+ new File (CoverageSensor .class .getResource ("/coverage/" + listFile [i ]).getFile ())));
107
88
108
- sb = new StringBuilder ();
109
- while ((sCurrentLine = reader .readLine ()) != null ) {
110
- sb .append (sCurrentLine + "\n " );
111
- }
89
+ String sCurrentLine ;
112
90
113
- testerContext .fileSystem ().add (new DefaultInputFile ("myProjectKey" , "pixel/pixel.go" )
114
- .setLanguage (GoLanguage .KEY ).initMetadata (sb .toString ()));
91
+ StringBuilder sb = new StringBuilder ();
92
+ while ((sCurrentLine = reader .readLine ()) != null ) {
93
+ sb .append (sCurrentLine + "\n " );
94
+ }
115
95
116
- reader = new BufferedReader ( new FileReader (
117
- new File ( CoverageSensor . class . getResource ( "/coverage/mathutil/filewithnocoverage.go" ). getFile () )));
96
+ testerContext . fileSystem (). add ( new DefaultInputFile ( "myProjectKey" , listFile [ i ])
97
+ . setLanguage ( GoLanguage . KEY ). initMetadata ( sb . toString ( )));
118
98
119
- sb = new StringBuilder ();
120
- while ((sCurrentLine = reader .readLine ()) != null ) {
121
- sb .append (sCurrentLine + "\n " );
122
99
}
123
100
124
- testerContext .fileSystem ().add (new DefaultInputFile ("myProjectKey" , "mathutil/filewithnocoverage.go" )
125
- .setLanguage (GoLanguage .KEY ).initMetadata (sb .toString ()));
126
-
127
- reader = new BufferedReader (
128
- new FileReader (new File (CoverageSensor .class .getResource ("/coverage/mathutil/a.go" ).getFile ())));
129
-
130
- sb = new StringBuilder ();
131
- while ((sCurrentLine = reader .readLine ()) != null ) {
132
- sb .append (sCurrentLine + "\n " );
133
- }
134
-
135
- testerContext .fileSystem ().add (new DefaultInputFile ("myProjectKey" , "mathutil/a.go" )
136
- .setLanguage (GoLanguage .KEY ).initMetadata (sb .toString ()));
137
-
138
- sensor .execute (testerContext );
139
-
140
- Map <String , Map <Integer , Integer >> map = new HashMap <>();
141
- map .put ("myProjectKey:mathutil/mathutil.go" , ImmutableMap .of (7 , 1 ));
142
- map .put ("myProjectKey:pixel/pixel.go" , ImmutableMap .of (21 , 0 , 37 , 0 ));
143
-
144
- Map <Integer , Integer > testValuesMap = new HashMap <>();
145
-
146
- testValuesMap .put (3 , null );
147
- testValuesMap .put (1 , null );
148
- testValuesMap .put (4 , null );
149
- testValuesMap .put (8 , 0 );
150
- testValuesMap .put (12 , 0 );
101
+ } catch (FileNotFoundException e ) {
102
+ // TODO Auto-generated catch block
103
+ e .printStackTrace ();
104
+ } catch (IOException e ) {
105
+ // TODO Auto-generated catch block
106
+ e .printStackTrace ();
107
+ }
108
+ }
151
109
152
- map .put ("myProjectKey:mathutil/filewithnocoverage.go" , testValuesMap );
153
- map .put ("myProjectKey:mathutil/a.go" , ImmutableMap .of (8 , 0 , 9 , 0 ));
110
+ @ Test
111
+ public void testExecution () {
112
+ final CoverageSensor sensor = new CoverageSensor ();
113
+ initFile ();
114
+ sensor .execute (testerContext );
115
+
116
+ Map <String , Map <Integer , Integer >> map = new HashMap <>();
117
+ map .put ("myProjectKey:mathutil/mathutil.go" , ImmutableMap .of (7 , 1 ));
118
+ map .put ("myProjectKey:pixel/pixel.go" , ImmutableMap .of (21 , 0 , 37 , 0 ));
119
+
120
+ Map <Integer , Integer > testValuesMap = new HashMap <>();
121
+
122
+ testValuesMap .put (3 , null );
123
+ testValuesMap .put (1 , null );
124
+ testValuesMap .put (4 , null );
125
+ testValuesMap .put (8 , 0 );
126
+ testValuesMap .put (12 , 0 );
127
+
128
+ map .put ("myProjectKey:mathutil/filewithnocoverage.go" , testValuesMap );
129
+ map .put ("myProjectKey:issue60/a.go" , ImmutableMap .of (8 , 0 , 9 , 0 ));
130
+ Map <Integer , Integer > testValuesMap2 = new HashMap <>();
131
+ testValuesMap2 .put (1 , null );
132
+ testValuesMap2 .put (2 , null );
133
+ testValuesMap2 .put (3 , null );
134
+ testValuesMap2 .put (4 , null );
135
+ testValuesMap2 .put (5 , null );
136
+ testValuesMap2 .put (6 , null );
137
+ testValuesMap2 .put (8 , 0 );
138
+ testValuesMap2 .put (9 , 0 );
139
+ testValuesMap2 .put (11 , null );
140
+ map .put ("myProjectKey:issue61/simplelinecomment.go" , testValuesMap2 );
141
+
142
+ Map <Integer , Integer > testValuesMap3 = new HashMap <>();
143
+
144
+ for (int i = 1 ; i <= 20 ; i ++) {
145
+ testValuesMap3 .put (i , null );
146
+ }
147
+ testValuesMap3 .put (26 , null );
148
+ testValuesMap3 .put (27 , null );
149
+ testValuesMap3 .put (28 , null );
150
+ testValuesMap3 .put (30 , 0 );
151
+ testValuesMap3 .put (31 , 0 );
154
152
155
- map .forEach ((key , mapValue ) -> {
156
- mapValue .forEach ((line , value ) -> {
157
- assertEquals ("line " + line + " " + key , value ,
158
- testerContext .lineHits (key , CoverageType .UNIT , line ));
159
- });
160
- });
153
+ map .put ("myProjectKey:issue61/multilinecomment.go" , testValuesMap3 );
161
154
162
- } catch (final FileNotFoundException e ) {
163
- e .printStackTrace ();
164
- } catch (final IOException e ) {
165
- e .printStackTrace ();
155
+ Map <Integer , Integer > testValuesMap4 = new HashMap <>();
156
+ for (int i = 6 ; i <= 48 ; i ++) {
157
+ testValuesMap4 .put (i , null );
166
158
}
159
+ map .put ("myProjectKey:issue61/typestruct.go" , testValuesMap4 );
160
+ map .forEach ((key , mapValue ) -> {
161
+ mapValue .forEach ((line , value ) -> {
162
+ assertEquals ("line " + line + " " + key , value , testerContext .lineHits (key , CoverageType .UNIT , line ));
163
+ });
164
+ });
167
165
168
166
}
169
167
0 commit comments