Package org.sonar.core.qualityprofile.db

Source Code of org.sonar.core.qualityprofile.db.ActiveRuleKeyTest

/*
* 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.qualityprofile.db;

import org.junit.Test;
import org.sonar.api.rule.RuleKey;

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

public class ActiveRuleKeyTest {

  @Test
  public void of() throws Exception {
    RuleKey ruleKey = RuleKey.of("xoo", "R1");
    ActiveRuleKey key = ActiveRuleKey.of("P1", ruleKey);
    assertThat(key.qProfile()).isEqualTo("P1");
    assertThat(key.ruleKey()).isSameAs(ruleKey);
    assertThat(key.toString()).isEqualTo("P1:xoo:R1");
  }

  @Test
  public void rule_key_can_contain_colons() throws Exception {
    RuleKey ruleKey = RuleKey.of("squid", "Key:With:Some::Colons");
    ActiveRuleKey key = ActiveRuleKey.of("P1", ruleKey);
    assertThat(key.qProfile()).isEqualTo("P1");
    assertThat(key.ruleKey()).isSameAs(ruleKey);
    assertThat(key.toString()).isEqualTo("P1:squid:Key:With:Some::Colons");
  }

  @Test
  public void profile_must_not_be_null() throws Exception {
    try {
      ActiveRuleKey.of(null, RuleKey.of("xoo", "R1"));
      fail();
    } catch (NullPointerException e) {
      assertThat(e).hasMessage("QProfile is missing");
    }
  }

  @Test
  public void rule_key_must_not_be_null() throws Exception {
    try {
      ActiveRuleKey.of("P1", null);
      fail();
    } catch (NullPointerException e) {
      assertThat(e).hasMessage("RuleKey is missing");
    }
  }

  @Test
  public void parse() throws Exception {
    ActiveRuleKey key = ActiveRuleKey.parse("P1:xoo:R1");
    assertThat(key.qProfile()).isEqualTo("P1");
    assertThat(key.ruleKey().repository()).isEqualTo("xoo");
    assertThat(key.ruleKey().rule()).isEqualTo("R1");
  }

  @Test
  public void parse_fail_when_less_than_three_colons() throws Exception {
    try {
      ActiveRuleKey.parse("P1:xoo");
      fail();
    } catch (IllegalArgumentException e) {
      assertThat(e).hasMessage("Bad format of activeRule key: P1:xoo");
    }
  }

  @Test
  public void equals_and_hashcode() throws Exception {
    ActiveRuleKey key1 = ActiveRuleKey.parse("P1:xoo:R1");
    ActiveRuleKey key1b = ActiveRuleKey.parse("P1:xoo:R1");
    ActiveRuleKey key2 = ActiveRuleKey.parse("P1:xoo:R2");
    ActiveRuleKey key3 = ActiveRuleKey.parse("P2:xoo:R1");
    assertThat(key1.equals(key1)).isTrue();
    assertThat(key1.equals(key1b)).isTrue();
    assertThat(key1.equals(null)).isFalse();
    assertThat(key1.equals("P1:xoo:R1")).isFalse();
    assertThat(key1.equals(key2)).isFalse();
    assertThat(key1.equals(key3)).isFalse();

    assertThat(key1.hashCode()).isEqualTo(key1.hashCode());
  }
}
TOP

Related Classes of org.sonar.core.qualityprofile.db.ActiveRuleKeyTest

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.