@@ -99,43 +99,80 @@ void whenCallingMainWithRunAndInputFileThatDoesNotContainValidJson_thenError(@Te
9999 }
100100
101101 @ Test
102- void whenCallingRunWithMissingField_filesToScanPerLanguage_thenError (@ TempDir Path tempDir ) throws Exception {
102+ void whenCallingRunWithMissingField_runDataPerLanguage_thenError (@ TempDir Path tempDir ) throws Exception {
103103 String inputFileContents = "{" +
104- " \" minimumTokens\" : 100, " +
105104 " \" skipDuplicateFiles\" : false " +
106105 "}" ;
107106 String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
108107
109108 String [] args = {"run" , inputFile , "/does/not/matter" };
110109 RuntimeException thrown = assertThrows (RuntimeException .class , () -> callCpdWrapper (args ));
111110 assertThat (thrown .getMessage (), is (
112- "Error while attempting to invoke CpdRunner.run: The \" filesToScanPerLanguage\" field was not set." ));
111+ "Error while attempting to invoke CpdRunner.run: The \" runDataPerLanguage\" field was not set." ));
112+ }
113+
114+ @ Test
115+ void whenCallingRunWithMissingField_filesToScan_thenError (@ TempDir Path tempDir ) throws Exception {
116+ String inputFileContents = "{" +
117+ " \" runDataPerLanguage\" : {" +
118+ " \" apex\" : {" +
119+ " \" minimumTokens\" : 100 " +
120+ " }" +
121+ " }," +
122+ " \" skipDuplicateFiles\" : false " +
123+ "}" ;
124+ String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
125+
126+ String [] args = {"run" , inputFile , "/does/not/matter" };
127+ RuntimeException thrown = assertThrows (RuntimeException .class , () -> callCpdWrapper (args ));
128+ assertThat (thrown .getMessage (), is (
129+ "Error while attempting to invoke CpdRunner.run: The \" filesToScan\" field was missing or empty for language: apex" ));
130+ }
131+
132+ @ Test
133+ void whenCallingRunWithEmptyArrayFor_filesToScan_thenError (@ TempDir Path tempDir ) throws Exception {
134+ String inputFileContents = "{" +
135+ " \" runDataPerLanguage\" : {" +
136+ " \" apex\" : {" +
137+ " \" filesToScan\" : []," +
138+ " \" minimumTokens\" : 100 " +
139+ " }" +
140+ " }," +
141+ " \" skipDuplicateFiles\" : false " +
142+ "}" ;
143+ String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
144+
145+ String [] args = {"run" , inputFile , "/does/not/matter" };
146+ RuntimeException thrown = assertThrows (RuntimeException .class , () -> callCpdWrapper (args ));
147+ assertThat (thrown .getMessage (), is (
148+ "Error while attempting to invoke CpdRunner.run: The \" filesToScan\" field was missing or empty for language: apex" ));
113149 }
114150
115151 @ Test
116152 void whenCallingRunWithZeroLanguages_thenError (@ TempDir Path tempDir ) throws Exception {
117153 String inputFileContents = "{" +
118- " \" filesToScanPerLanguage \" : {" +
154+ " \" runDataPerLanguage \" : {" +
119155 " }," +
120- " \" minimumTokens\" : 120," +
121156 " \" skipDuplicateFiles\" : false " +
122157 "}" ;
123158 String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
124159
125160 String [] args = {"run" , inputFile , "/does/not/matter" };
126161 RuntimeException thrown = assertThrows (RuntimeException .class , () -> callCpdWrapper (args ));
127162 assertThat (thrown .getMessage (), is (
128- "Error while attempting to invoke CpdRunner.run: The \" filesToScanPerLanguage \" field was found to be empty ." ));
163+ "Error while attempting to invoke CpdRunner.run: The \" runDataPerLanguage \" field didn't have any languages listed ." ));
129164 }
130165
131166 @ Test
132167 void whenCallingRunWithInvalidLanguage_thenError (@ TempDir Path tempDir ) throws Exception {
133168 String dummyFile = createTempFile (tempDir , "dummy" , "" );
134169 String inputFileContents = "{" +
135- " \" filesToScanPerLanguage\" : {" +
136- " \" unknownLanguage\" : [\" " + makePathJsonSafe (dummyFile ) + "\" ]" +
170+ " \" runDataPerLanguage\" : {" +
171+ " \" unknownLanguage\" : {" +
172+ " \" filesToScan\" : [\" " + makePathJsonSafe (dummyFile ) + "\" ]," +
173+ " \" minimumTokens\" : 120" +
174+ " }" +
137175 " }," +
138- " \" minimumTokens\" : 120," +
139176 " \" skipDuplicateFiles\" : false " +
140177 "}" ;
141178 String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
@@ -150,8 +187,10 @@ void whenCallingRunWithInvalidLanguage_thenError(@TempDir Path tempDir) throws E
150187 void whenCallingRunWithMissingField_minimumTokens_thenError (@ TempDir Path tempDir ) throws Exception {
151188 String dummyApexFile = createTempFile (tempDir , "dummy.cls" , "" );
152189 String inputFileContents = "{" +
153- " \" filesToScanPerLanguage\" : {" +
154- " \" apex\" : [\" " + makePathJsonSafe (dummyApexFile ) + "\" ]" +
190+ " \" runDataPerLanguage\" : {" +
191+ " \" apex\" : {" +
192+ " \" filesToScan\" : [\" " + makePathJsonSafe (dummyApexFile ) + "\" ]" +
193+ " }" +
155194 " }," +
156195 " \" skipDuplicateFiles\" : false " +
157196 "}" ;
@@ -160,35 +199,39 @@ void whenCallingRunWithMissingField_minimumTokens_thenError(@TempDir Path tempDi
160199 String [] args = {"run" , inputFile , "/does/not/matter" };
161200 RuntimeException thrown = assertThrows (RuntimeException .class , () -> callCpdWrapper (args ));
162201 assertThat (thrown .getMessage (), is (
163- "Error while attempting to invoke CpdRunner.run: The \" minimumTokens\" field was not set to a positive number. " ));
202+ "Error while attempting to invoke CpdRunner.run: The \" minimumTokens\" field was not set to a positive number for language: apex " ));
164203 }
165204
166205 @ Test
167206 void whenCallingRunWithNegativeMinimumTokensValue_thenError (@ TempDir Path tempDir ) throws Exception {
168207 String dummyApexFile = createTempFile (tempDir , "dummy.cls" , "" );
169208 String inputFileContents = "{" +
170- " \" filesToScanPerLanguage\" : {" +
171- " \" apex\" : [\" " + makePathJsonSafe (dummyApexFile ) + "\" ]" +
209+ " \" runDataPerLanguage\" : {" +
210+ " \" apex\" : {" +
211+ " \" filesToScan\" : [\" " + makePathJsonSafe (dummyApexFile ) + "\" ]," +
212+ " \" minimumTokens\" : -1" +
213+ " }" +
172214 " }," +
173- " \" minimumTokens\" : -1," +
174215 " \" skipDuplicateFiles\" : false " +
175216 "}" ;
176217 String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
177218
178219 String [] args = {"run" , inputFile , "/does/not/matter" };
179220 RuntimeException thrown = assertThrows (RuntimeException .class , () -> callCpdWrapper (args ));
180221 assertThat (thrown .getMessage (), is (
181- "Error while attempting to invoke CpdRunner.run: The \" minimumTokens\" field was not set to a positive number. " ));
222+ "Error while attempting to invoke CpdRunner.run: The \" minimumTokens\" field was not set to a positive number for language: apex " ));
182223 }
183224
184225 @ Test
185226 void whenCallingRunWithFileToScanThatDoesNotExist_thenExceptionIsForwardedAsProcessingErrorWithTerminatingExceptionMarker (@ TempDir Path tempDir ) throws Exception {
186227 String doesNotExist = tempDir .resolve ("doesNotExist.cls" ).toAbsolutePath ().toString ();
187228 String inputFileContents = "{" +
188- " \" filesToScanPerLanguage\" : {" +
189- " \" apex\" : [\" " + makePathJsonSafe (doesNotExist ) + "\" ]" +
229+ " \" runDataPerLanguage\" : {" +
230+ " \" apex\" : {" +
231+ " \" filesToScan\" : [\" " + makePathJsonSafe (doesNotExist ) + "\" ]," +
232+ " \" minimumTokens\" : 100" +
233+ " }" +
190234 " }," +
191- " \" minimumTokens\" : 100," +
192235 " \" skipDuplicateFiles\" : false " +
193236 "}" ;
194237 String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
@@ -212,11 +255,16 @@ void whenCallingRunWithValidFilesThatHaveDuplicates_thenJsonOutputShouldContainR
212255 String jsFile2 = createTempFile (tempDir , "jsFile2.js" , SAMPLE_JS_2 );
213256
214257 String inputFileContents = "{" +
215- " \" filesToScanPerLanguage\" : {" +
216- " \" apex\" : [\" " + makePathJsonSafe (apexFile1 ) + "\" , \" " + makePathJsonSafe (apexFile2 ) + "\" ]," +
217- " \" ecmascript\" : [\" " + makePathJsonSafe (jsFile1 ) + "\" , \" " + makePathJsonSafe (jsFile2 ) + "\" ]" +
258+ " \" runDataPerLanguage\" : {" +
259+ " \" apex\" : {" +
260+ " \" filesToScan\" : [\" " + makePathJsonSafe (apexFile1 ) + "\" , \" " + makePathJsonSafe (apexFile2 ) + "\" ]," +
261+ " \" minimumTokens\" : 5" +
262+ " }," +
263+ " \" ecmascript\" : {" +
264+ " \" filesToScan\" : [\" " + makePathJsonSafe (jsFile1 ) + "\" , \" " + makePathJsonSafe (jsFile2 ) + "\" ]," +
265+ " \" minimumTokens\" : 13" +
266+ " }" +
218267 " }," +
219- " \" minimumTokens\" : 5," +
220268 " \" skipDuplicateFiles\" : false " +
221269 "}" ;
222270 String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
@@ -344,10 +392,12 @@ void whenCallingRunWithValidFilesHaveZeroDuplicatesSinceMinTokensIsHigh_thenJson
344392 String apexFile2 = createTempFile (tempDir , "ApexClass2.cls" , SAMPLE_APEX_2 );
345393
346394 String inputFileContents = "{" +
347- " \" filesToScanPerLanguage\" : {" +
348- " \" apex\" : [\" " + makePathJsonSafe (apexFile1 ) + "\" , \" " + makePathJsonSafe (apexFile2 ) + "\" ]" +
395+ " \" runDataPerLanguage\" : {" +
396+ " \" apex\" : {" +
397+ " \" filesToScan\" : [\" " + makePathJsonSafe (apexFile1 ) + "\" , \" " + makePathJsonSafe (apexFile2 ) + "\" ]," +
398+ " \" minimumTokens\" : 500" +
399+ " }" +
349400 " }," +
350- " \" minimumTokens\" : 500," + // This is why there are no dups found
351401 " \" skipDuplicateFiles\" : false " +
352402 "}" ;
353403 String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
@@ -370,11 +420,12 @@ void whenCallingRunWithTwoIdenticalFilesButSkipDuplicateFilesIsFalse_thenJsonOut
370420 String apexFileInSubFolder = createTempFile (subFolder , "ApexClass1.cls" , SAMPLE_APEX_1 );
371421
372422 String inputFileContents = "{" +
373- " \" filesToScanPerLanguage\" : {" +
374- " \" apex\" : [\" " + makePathJsonSafe (apexFileInParentFolder ) + "\" , \" " + makePathJsonSafe (apexFileInSubFolder ) + "\" ]," +
375- " \" xml\" : []" + // Edge case - checking also that this doesn't blow up anything
423+ " \" runDataPerLanguage\" : {" +
424+ " \" apex\" : {" +
425+ " \" filesToScan\" : [\" " + makePathJsonSafe (apexFileInParentFolder ) + "\" , \" " + makePathJsonSafe (apexFileInSubFolder ) + "\" ]," +
426+ " \" minimumTokens\" : 15" +
427+ " }" +
376428 " }," +
377- " \" minimumTokens\" : 15," +
378429 " \" skipDuplicateFiles\" : false " +
379430 "}" ;
380431 String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
@@ -434,10 +485,12 @@ void whenCallingRunWithTwoIdenticalFilesButSkipDuplicateFilesIsTrue_thenJsonOutp
434485 String apexFileInSubFolder = createTempFile (subFolder , "ApexClass1.cls" , SAMPLE_APEX_1 );
435486
436487 String inputFileContents = "{" +
437- " \" filesToScanPerLanguage\" : {" +
438- " \" apex\" : [\" " + makePathJsonSafe (apexFileInParentFolder ) + "\" , \" " + makePathJsonSafe (apexFileInSubFolder ) + "\" ]" +
488+ " \" runDataPerLanguage\" : {" +
489+ " \" apex\" : {" +
490+ " \" filesToScan\" : [\" " + makePathJsonSafe (apexFileInParentFolder ) + "\" , \" " + makePathJsonSafe (apexFileInSubFolder ) + "\" ]," +
491+ " \" minimumTokens\" : 15" +
492+ " }" +
439493 " }," +
440- " \" minimumTokens\" : 15," +
441494 " \" skipDuplicateFiles\" : true " +
442495 "}" ;
443496 String inputFile = createTempFile (tempDir , "inputFile.json" , inputFileContents );
0 commit comments