@Test public void testAnalyse() { parser = mock(CoverageResultParser.class); // create the parser before the sensor CoverageReportSensor sensor = buildSensor(); microsoftWindowsEnvironment.setTestExecutionDone(); File solutionDir = TestUtils.getResource("/Results/coverage/"); microsoftWindowsEnvironment.setWorkingDirectory(""); when(solution.getSolutionDir()).thenReturn(solutionDir); when(solution.getProject("MyAssembly")).thenReturn(vsProject1); List<FileCoverage> sourceFiles = new ArrayList<FileCoverage>(); List<ProjectCoverage> projects = new ArrayList<ProjectCoverage>(); ParserResult parserResult = new ParserResult(projects, sourceFiles); when(parser.parse(eq(project), any(File.class))).thenReturn(parserResult); ProjectCoverage projectCoverage = mock(ProjectCoverage.class); when(projectCoverage.getAssemblyName()).thenReturn("MyAssembly"); projects.add(projectCoverage); SensorContext context = mock(SensorContext.class); sensor.analyse(project, context); verify(projectCoverage).getFileCoverageCollection(); }
@BeforeClass public static void initData() { project = mock(VisualStudioProject.class); when(project.getProjectFile()) .thenReturn(new File("target/sonar/solution/project/project.csproj")); new File("target/sonar/solution").mkdirs(); solution = mock(VisualStudioSolution.class); when(solution.getSolutionDir()).thenReturn(new File("target/sonar/solution")); when(solution.getSolutionFile()).thenReturn(new File("target/sonar/solution/solution.sln")); }
@Test public void testShouldNotExecuteOnProjectUsingPatterns() throws Exception { conf.setProperty(GendarmeConstants.ASSEMBLIES_TO_SCAN_KEY, new String[] {"**/*.whatever"}); conf.setProperty( CSharpConstants.BUILD_CONFIGURATION_KEY, "DummyBuildConf"); // we simulate no generated assemblies when(solution.getSolutionDir()).thenReturn(TestUtils.getResource("/Sensor")); when(vsProject.getDirectory()).thenReturn(TestUtils.getResource("/Sensor")); Project project = mock(Project.class); when(project.getName()).thenReturn("Project #1"); when(project.getLanguageKey()).thenReturn("cs"); assertFalse(sensor.shouldExecuteOnProject(project)); }