### Question:
AnsibleExtraSensor extends AbstractAnsibleSensor { @Override public void execute(SensorContext context) { Path extraRulesDir = extractExtraRules(EXTRA_RULES_DIR); if (extraRulesDir != null) { executeWithAnsibleLint(context, Arrays.asList("-r", extraRulesDir.toString())); deleteDirectory(extraRulesDir); } } AnsibleExtraSensor(FileSystem fileSystem); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); static final String EXTRA_RULES_TEMP_DIR; static final String EXTRA_RULES_DIR; }### Answer:
@Test public void testExecute() throws IOException { InputFile playbook1 = Utils.getInputFile("playbooks/playbook1.yml"); InputFile playbook2 = Utils.getInputFile("playbooks/playbook2.yml"); InputFile playbook3 = Utils.getInputFile("playbooks/playbook3.yml"); context.fileSystem().add(playbook1).add(playbook2).add(playbook3); if (System.getProperty("os.name").toLowerCase().contains("windows")) { context.settings().appendProperty(AnsibleSettings.ANSIBLE_LINT_PATH_KEY, new File(getClass().getResource("/scripts/ansible-lint4.cmd").getFile()).getAbsolutePath()); } else { String path = new File(getClass().getResource("/scripts/ansible-lint4.sh").getFile()).getAbsolutePath(); context.settings().appendProperty(AnsibleSettings.ANSIBLE_LINT_PATH_KEY, path); setShellRights(path); } DummySensorDescriptor descriptor = new DummySensorDescriptor(); sensor.describe(descriptor); assertEquals("Ansible-Lint Sensor with Extra Rules", descriptor.sensorName); assertEquals(YamlLanguage.KEY, descriptor.languageKey); sensor.execute(context); Collection<Issue> issues = context.allIssues(); assertEquals(3, issues.size()); assertTrue(issueExists(issues, ruleKey1, playbook1, 3, "An error -p")); assertTrue(issueExists(issues, ruleKey2, playbook1, 5, "Another error --nocolor")); assertTrue(issueExists(issues, ruleKey2, playbook2, 3, "Another error -r")); }