Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FileAttributesTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.ce.task.projectanalysis.component;
  21. import org.junit.Test;
  22. import static org.assertj.core.api.Assertions.assertThat;
  23. import static org.assertj.core.api.Assertions.assertThatThrownBy;
  24. public class FileAttributesTest {
  25. @Test
  26. public void create_production_file() {
  27. FileAttributes underTest = new FileAttributes(true, "java", 10, true);
  28. assertThat(underTest.isUnitTest()).isTrue();
  29. assertThat(underTest.getLanguageKey()).isEqualTo("java");
  30. assertThat(underTest.getLines()).isEqualTo(10);
  31. assertThat(underTest.isMarkedAsUnchanged()).isTrue();
  32. }
  33. @Test
  34. public void create_unit_test() {
  35. FileAttributes underTest = new FileAttributes(true, "java", 10, false);
  36. assertThat(underTest.isUnitTest()).isTrue();
  37. assertThat(underTest.getLanguageKey()).isEqualTo("java");
  38. assertThat(underTest.getLines()).isEqualTo(10);
  39. assertThat(underTest.isMarkedAsUnchanged()).isFalse();
  40. }
  41. @Test
  42. public void create_without_language() {
  43. FileAttributes underTest = new FileAttributes(true, null, 10, false);
  44. assertThat(underTest.isUnitTest()).isTrue();
  45. assertThat(underTest.getLanguageKey()).isNull();
  46. assertThat(underTest.getLines()).isEqualTo(10);
  47. }
  48. @Test
  49. public void fail_with_IAE_when_lines_is_0() {
  50. assertThatThrownBy(() -> new FileAttributes(true, "java", 0, false))
  51. .isInstanceOf(IllegalArgumentException.class)
  52. .hasMessage("Number of lines must be greater than zero");
  53. }
  54. @Test
  55. public void fail_with_IAE_when_lines_is_less_than_0() {
  56. assertThatThrownBy(() -> new FileAttributes(true, "java", -10, false))
  57. .isInstanceOf(IllegalArgumentException.class)
  58. .hasMessage("Number of lines must be greater than zero");
  59. }
  60. @Test
  61. public void test_toString() {
  62. assertThat(new FileAttributes(true, "java", 10, true))
  63. .hasToString("FileAttributes{languageKey='java', unitTest=true, lines=10, markedAsUnchanged=true}");
  64. assertThat(new FileAttributes(false, null, 1, false))
  65. .hasToString("FileAttributes{languageKey='null', unitTest=false, lines=1, markedAsUnchanged=false}");
  66. }
  67. }