3 * Copyright (C) 2009-2022 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.ce.task.projectanalysis.component;
22 import org.junit.Test;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.assertj.core.api.Assertions.assertThatThrownBy;
27 public class FileAttributesTest {
29 public void create_production_file() {
30 FileAttributes underTest = new FileAttributes(true, "java", 10, true);
32 assertThat(underTest.isUnitTest()).isTrue();
33 assertThat(underTest.getLanguageKey()).isEqualTo("java");
34 assertThat(underTest.getLines()).isEqualTo(10);
35 assertThat(underTest.isMarkedAsUnchanged()).isTrue();
39 public void create_unit_test() {
40 FileAttributes underTest = new FileAttributes(true, "java", 10, false);
42 assertThat(underTest.isUnitTest()).isTrue();
43 assertThat(underTest.getLanguageKey()).isEqualTo("java");
44 assertThat(underTest.getLines()).isEqualTo(10);
45 assertThat(underTest.isMarkedAsUnchanged()).isFalse();
49 public void create_without_language() {
50 FileAttributes underTest = new FileAttributes(true, null, 10, false);
52 assertThat(underTest.isUnitTest()).isTrue();
53 assertThat(underTest.getLanguageKey()).isNull();
54 assertThat(underTest.getLines()).isEqualTo(10);
58 public void fail_with_IAE_when_lines_is_0() {
59 assertThatThrownBy(() -> new FileAttributes(true, "java", 0, false))
60 .isInstanceOf(IllegalArgumentException.class)
61 .hasMessage("Number of lines must be greater than zero");
65 public void fail_with_IAE_when_lines_is_less_than_0() {
66 assertThatThrownBy(() -> new FileAttributes(true, "java", -10, false))
67 .isInstanceOf(IllegalArgumentException.class)
68 .hasMessage("Number of lines must be greater than zero");
72 public void test_toString() {
73 assertThat(new FileAttributes(true, "java", 10, true))
74 .hasToString("FileAttributes{languageKey='java', unitTest=true, lines=10, markedAsUnchanged=true}");
75 assertThat(new FileAttributes(false, null, 1, false))
76 .hasToString("FileAttributes{languageKey='null', unitTest=false, lines=1, markedAsUnchanged=false}");