Ejemplo n.º 1
0
  @Test
  public void shouldReturnViolationsUsingImportAndBasicRuleSets() {
    config = ConfigurationBuilder.initFromResource(CONFIGURATION_WITH_BASIC_AND_IMPORT_RULE_SET);
    sut = new CodeNarcProcessor(config);
    Review review = getReview(REVIEW_FILE_WITH_ONE_VIOLATION, REVIEW_FILE_WITH_IMPORT_VIOLATION);

    ReviewResult result = sut.process(review);

    assertThat(result).isNotNull();
    assertThat(result.getViolations())
        .hasSize(4)
        .containsOnly(
            new Violation(
                REVIEW_FILE_WITH_ONE_VIOLATION,
                5,
                "EmptyTryBlock: The try block is empty",
                Severity.WARNING),
            new Violation(
                REVIEW_FILE_WITH_IMPORT_VIOLATION,
                2,
                "EmptyClass: Class 'FileWithoutViolations' is empty (has no methods, fields or properties). Why would you need a class like this?",
                Severity.WARNING),
            new Violation(
                REVIEW_FILE_WITH_IMPORT_VIOLATION, 1, "UnnecessaryGroovyImport", Severity.INFO),
            new Violation(
                REVIEW_FILE_WITH_IMPORT_VIOLATION,
                1,
                "UnusedImport: The [java.util.ArrayList] import is never referenced",
                Severity.INFO));
  }
Ejemplo n.º 2
0
  @Test
  public void shouldReturnViolationsUsingDefaultRuleSetFromResources() {
    config = ConfigurationBuilder.initFromResource(CONFIGURATION_WITHOUT_RULE_SET);
    sut = new CodeNarcProcessor(config);
    Review review = getReview(REVIEW_FILE_WITH_ONE_VIOLATION_PER_EACH_SEVERITY);

    ReviewResult result = sut.process(review);

    assertThat(result).isNotNull();
    assertThat(result.getViolations())
        .hasSize(3)
        .containsOnly(
            new Violation(
                REVIEW_FILE_WITH_ONE_VIOLATION_PER_EACH_SEVERITY,
                5,
                "ForLoopShouldBeWhileLoop: The for loop can be simplified to a while loop",
                Severity.INFO),
            new Violation(
                REVIEW_FILE_WITH_ONE_VIOLATION_PER_EACH_SEVERITY,
                9,
                "AssertWithinFinallyBlock: A finally block within class FileWithOneViolationPerEachLevel contains an assert statement, potentially hiding the original exception, if there is one",
                Severity.WARNING),
            new Violation(
                REVIEW_FILE_WITH_ONE_VIOLATION_PER_EACH_SEVERITY,
                13,
                "EmptyMethod: Violation in class FileWithOneViolationPerEachLevel. The method bar is both empty and not marked with @Override",
                Severity.WARNING));
  }
Ejemplo n.º 3
0
  @Test
  public void shouldReturnViolationsUsingImportRuleSet() {
    config = ConfigurationBuilder.initFromResource(CONFIGURATION_WITH_IMPORT_RULE_SET);
    sut = new CodeNarcProcessor(config);
    Review review = getReview(REVIEW_FILE_WITH_IMPORT_VIOLATION, REVIEW_FILE_WITH_ONE_VIOLATION);

    ReviewResult result = sut.process(review);

    assertThat(result).isNotNull();
    assertThat(result.getViolations())
        .hasSize(2)
        .containsOnly(
            new Violation(
                REVIEW_FILE_WITH_IMPORT_VIOLATION, 1, "UnnecessaryGroovyImport", Severity.INFO),
            new Violation(
                REVIEW_FILE_WITH_IMPORT_VIOLATION,
                1,
                "UnusedImport: The [java.util.ArrayList] import is never referenced",
                Severity.INFO));
  }
Ejemplo n.º 4
0
  public static void main(String[] args) {
    printWelcomeMessage();
    CliWrapper cliWrapper = new CliWrapper();
    CommandLine commandLine = null;
    try {
      commandLine = cliWrapper.parse(args);
    } catch (ParseException e) {
      printUsage(cliWrapper);
      System.out.println(e.getMessage());
      System.exit(1);
    }

    Configuration configuration =
        ConfigurationBuilder.initFromFile(
            commandLine.getOptionValue(CliOption.CONF.getCommandLineParam()));
    configuration.updateWithCliOptions(commandLine);

    ConnectorFacade facade = getConnectorFacade(configuration);
    new Engine(facade, facade, configuration).run();
  }
Ejemplo n.º 5
0
  @Test
  public void shouldNotReturnViolationsFromExcudedFiles() {
    config =
        ConfigurationBuilder.initFromResource(
            CONFIGURATION_WITH_BASIC_AND_IMPORT_RULE_SET_AND_EXCLUDE);
    sut = new CodeNarcProcessor(config);
    Review review =
        getReview(
            REVIEW_FILE_WITH_ONE_VIOLATION,
            REVIEW_FILE_WITHOUT_VIOLATIONS,
            REVIEW_FILE_WITH_ONE_VIOLATION_PER_EACH_SEVERITY);

    ReviewResult result = sut.process(review);

    assertThat(result).isNotNull();
    assertThat(result.getViolations())
        .hasSize(1)
        .containsOnly(
            new Violation(
                REVIEW_FILE_WITH_ONE_VIOLATION,
                5,
                "EmptyTryBlock: The try block is empty",
                Severity.WARNING));
  }
 @Before
 public void setUp() throws FileNotFoundException {
   config = ConfigurationBuilder.initFromResource("test-sonar.properties");
 }
Ejemplo n.º 7
0
 @Before
 public void setUp() {
   config = ConfigurationBuilder.initFromResource("pylint/sputnik/noConfigurationFile.properties");
   fixture = new PylintProcessor(config);
 }
Ejemplo n.º 8
0
 @Before
 public void setUp() throws Exception {
   config = ConfigurationBuilder.initFromResource(CONFIGURATION_WITH_BASIC_RULE_SET);
   sut = new CodeNarcProcessor(config);
 }