選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CoreMetricsTest.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.api.resources;
  21. import java.util.List;
  22. import java.util.NoSuchElementException;
  23. import org.junit.Test;
  24. import org.sonar.api.measures.Metric;
  25. import static org.assertj.core.api.Assertions.assertThat;
  26. import static org.assertj.core.api.Assertions.assertThatThrownBy;
  27. import static org.sonar.api.measures.CoreMetrics.DIRECTORIES;
  28. import static org.sonar.api.measures.CoreMetrics.NCLOC;
  29. import static org.sonar.api.measures.CoreMetrics.getMetric;
  30. import static org.sonar.api.measures.CoreMetrics.getMetrics;
  31. public class CoreMetricsTest {
  32. @Test
  33. public void read_metrics_from_class_reflection() {
  34. List<Metric> metrics = getMetrics();
  35. assertThat(metrics.size()).isGreaterThan(100);
  36. assertThat(metrics).contains(NCLOC, DIRECTORIES);
  37. }
  38. @Test
  39. public void get_metric_by_key() {
  40. Metric metric = getMetric("ncloc");
  41. assertThat(metric.getKey()).isEqualTo("ncloc");
  42. }
  43. @Test
  44. public void fail_get_unknown_metric_by_key() {
  45. assertThatThrownBy(() -> getMetric("unknown"))
  46. .isInstanceOf(NoSuchElementException.class);
  47. }
  48. @Test
  49. public void someMetricsAreMeantToBeHidden() {
  50. Metric metric = getMetric("analysis_from_sonarqube_9_4");
  51. assertThat(metric.isHidden()).isTrue();
  52. }
  53. }