@Test public void testPerformFileAnalysisWithMocks() throws IOException { MetricsExporter exporter = mock(MetricsExporter.class); ContentReader reader = mock(ContentReader.class); SourceCodeAnalyzer analyzer = mock(SourceCodeAnalyzer.class); when(reader.readFileForRegex(TEST_CLASS_LOCAL)).thenReturn(new String()); when(analyzer.calculateLOC(TEST_CLASS_LOCAL)).thenReturn(21); when(analyzer.calculateNOM(TEST_CLASS_LOCAL)).thenReturn(3); when(analyzer.calculateNOC(TEST_CLASS_LOCAL)).thenReturn(3); MetricsExporterFactory exporterFactory = mock(MetricsExporterFactory.class); ContentReaderFactory readerFactory = mock(ContentReaderFactory.class); SourceCodeAnalyzerFactory analyzerFactory= mock(SourceCodeAnalyzerFactory.class); when(exporterFactory.createMetricsExporter(EXPORT_TYPE)).thenReturn(exporter); when(readerFactory.createContentReader(FILE_LOCATION_TYPE)).thenReturn(reader); when(analyzerFactory.createSourceCodeAnalyzer(ANALYSIS_TYPE)).thenReturn(analyzer); SourceCodeAnalyzerFacade codeAnalyzer = new SourceCodeAnalyzerFacade(readerFactory, analyzerFactory, exporterFactory); codeAnalyzer.performFileAnalysis( TEST_CLASS_LOCAL, ANALYSIS_TYPE, FILE_LOCATION_TYPE, OUTPUT_FILE, EXPORT_TYPE); verify(readerFactory).createContentReader(FILE_LOCATION_TYPE); verify(exporterFactory).createMetricsExporter(EXPORT_TYPE); verify(analyzerFactory).createSourceCodeAnalyzer(ANALYSIS_TYPE); verify(analyzer).setContentReader(reader); verify(analyzer).calculateLOC(TEST_CLASS_LOCAL); verify(analyzer).calculateNOM(TEST_CLASS_LOCAL); verify(analyzer).calculateNOC(TEST_CLASS_LOCAL); Map<String,Integer> metrics = new HashMap<>(); metrics.put("loc", 21); metrics.put("nom", 3); metrics.put("noc", 3); verify(exporter).writeToFile(OUTPUT_FILE, metrics); }
public void performFileAnalysis(String filepath, String analysisType, String fileLocation, String outputFileName, String outputFileType) throws IOException { ContentReader contentReader = readerFactory.createContentReader(fileLocation); SourceCodeAnalyzer analyzer = analyzerFactory.createSourceCodeAnalyzer(analysisType); analyzer.setContentReader(contentReader); int loc = analyzer.calculateLOC(filepath); int nom = analyzer.calculateNOM(filepath); int noc = analyzer.calculateNOC(filepath); Map<String,Integer> metrics = new HashMap<>(); metrics.put("loc", loc); metrics.put("nom", nom); metrics.put("noc", noc); MetricsExporter metricsExporter = exporterFactory.createMetricsExporter(outputFileType); metricsExporter.writeToFile(outputFileName, metrics); }
SourceCodeAnalyzerFacade { public void performFileAnalysis(String filepath, String analysisType, String fileLocation, String outputFileName, String outputFileType) throws IOException { ContentReader contentReader = readerFactory.createContentReader(fileLocation); SourceCodeAnalyzer analyzer = analyzerFactory.createSourceCodeAnalyzer(analysisType); analyzer.setContentReader(contentReader); int loc = analyzer.calculateLOC(filepath); int nom = analyzer.calculateNOM(filepath); int noc = analyzer.calculateNOC(filepath); Map<String,Integer> metrics = new HashMap<>(); metrics.put("loc", loc); metrics.put("nom", nom); metrics.put("noc", noc); MetricsExporter metricsExporter = exporterFactory.createMetricsExporter(outputFileType); metricsExporter.writeToFile(outputFileName, metrics); } }
SourceCodeAnalyzerFacade { public void performFileAnalysis(String filepath, String analysisType, String fileLocation, String outputFileName, String outputFileType) throws IOException { ContentReader contentReader = readerFactory.createContentReader(fileLocation); SourceCodeAnalyzer analyzer = analyzerFactory.createSourceCodeAnalyzer(analysisType); analyzer.setContentReader(contentReader); int loc = analyzer.calculateLOC(filepath); int nom = analyzer.calculateNOM(filepath); int noc = analyzer.calculateNOC(filepath); Map<String,Integer> metrics = new HashMap<>(); metrics.put("loc", loc); metrics.put("nom", nom); metrics.put("noc", noc); MetricsExporter metricsExporter = exporterFactory.createMetricsExporter(outputFileType); metricsExporter.writeToFile(outputFileName, metrics); } SourceCodeAnalyzerFacade();  SourceCodeAnalyzerFacade(ContentReaderFactory readerFactory, SourceCodeAnalyzerFactory analyzerFactory,
			MetricsExporterFactory exporterFactory); }
SourceCodeAnalyzerFacade { public void performFileAnalysis(String filepath, String analysisType, String fileLocation, String outputFileName, String outputFileType) throws IOException { ContentReader contentReader = readerFactory.createContentReader(fileLocation); SourceCodeAnalyzer analyzer = analyzerFactory.createSourceCodeAnalyzer(analysisType); analyzer.setContentReader(contentReader); int loc = analyzer.calculateLOC(filepath); int nom = analyzer.calculateNOM(filepath); int noc = analyzer.calculateNOC(filepath); Map<String,Integer> metrics = new HashMap<>(); metrics.put("loc", loc); metrics.put("nom", nom); metrics.put("noc", noc); MetricsExporter metricsExporter = exporterFactory.createMetricsExporter(outputFileType); metricsExporter.writeToFile(outputFileName, metrics); } SourceCodeAnalyzerFacade();  SourceCodeAnalyzerFacade(ContentReaderFactory readerFactory, SourceCodeAnalyzerFactory analyzerFactory,
			MetricsExporterFactory exporterFactory); void performFileAnalysis(String filepath, String analysisType, String fileLocation, String outputFileName, String outputFileType); }
SourceCodeAnalyzerFacade { public void performFileAnalysis(String filepath, String analysisType, String fileLocation, String outputFileName, String outputFileType) throws IOException { ContentReader contentReader = readerFactory.createContentReader(fileLocation); SourceCodeAnalyzer analyzer = analyzerFactory.createSourceCodeAnalyzer(analysisType); analyzer.setContentReader(contentReader); int loc = analyzer.calculateLOC(filepath); int nom = analyzer.calculateNOM(filepath); int noc = analyzer.calculateNOC(filepath); Map<String,Integer> metrics = new HashMap<>(); metrics.put("loc", loc); metrics.put("nom", nom); metrics.put("noc", noc); MetricsExporter metricsExporter = exporterFactory.createMetricsExporter(outputFileType); metricsExporter.writeToFile(outputFileName, metrics); } SourceCodeAnalyzerFacade();  SourceCodeAnalyzerFacade(ContentReaderFactory readerFactory, SourceCodeAnalyzerFactory analyzerFactory,
			MetricsExporterFactory exporterFactory); void performFileAnalysis(String filepath, String analysisType, String fileLocation, String outputFileName, String outputFileType);  }