Package org.sonar.core.issue

Source Code of org.sonar.core.issue.DefaultIssueBuilderTest

/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2014 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
package org.sonar.core.issue;

import org.junit.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;

import static org.fest.assertions.Assertions.assertThat;

public class DefaultIssueBuilderTest {

  @Test
  public void build_new_issue() throws Exception {
    String componentKey = "org.apache.struts:struts-core:Action.java";
    String projectKey = "org.apache.struts";
    DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder()
      .componentKey(componentKey)
      .projectKey(projectKey)
      .message("the message")
      .line(123)
      .effortToFix(10000.0)
      .ruleKey(RuleKey.of("squid", "NullDereference"))
      .severity(Severity.CRITICAL)
      .attribute("JIRA", "FOO-123")
      .attribute("YOUTRACK", "YT-123")
      .build();

    assertThat(issue).isNotNull();
    assertThat(issue.key()).isNotNull();
    assertThat(issue.effortToFix()).isEqualTo(10000.0);
    assertThat(issue.componentKey()).isEqualTo(componentKey);
    assertThat(issue.projectKey()).isEqualTo(projectKey);
    assertThat(issue.message()).isEqualTo("the message");
    assertThat(issue.line()).isEqualTo(123);
    assertThat(issue.ruleKey().repository()).isEqualTo("squid");
    assertThat(issue.ruleKey().rule()).isEqualTo("NullDereference");
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    assertThat(issue.assignee()).isNull();
    assertThat(issue.isNew()).isTrue();
    assertThat(issue.resolution()).isNull();
    assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN);
    assertThat(issue.attribute("JIRA")).isEqualTo("FOO-123");
    assertThat(issue.attribute("YOUTRACK")).isEqualTo("YT-123");
    assertThat(issue.attributes()).hasSize(2);
  }

  @Test
  public void not_set_default_severity() {
    DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder()
      .componentKey("Action.java")
      .projectKey("org.apache.struts")
      .ruleKey(RuleKey.of("squid", "NullDereference"))
      .build();

    assertThat(issue.severity()).isNull();
  }
}
TOP

Related Classes of org.sonar.core.issue.DefaultIssueBuilderTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.