]> source.dussan.org Git - sonarqube.git/blob
25bc2d4614d5d75b6f138a8086e6383f5d6d8343
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2016 SonarSource SA
4  * mailto:contact 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.ce.posttask;
21
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.rules.ExpectedException;
25
26 import static org.assertj.core.api.Assertions.assertThat;
27
28 public class ProjectBuilder_PostProjectAnalysisTaskTesterTest {
29   private static final String SOME_NAME = "some name";
30   private static final String SOME_KEY = "some key";
31   private static final String SOME_UUID = "some uuid";
32
33   @Rule
34   public ExpectedException expectedException = ExpectedException.none();
35
36   private PostProjectAnalysisTaskTester.ProjectBuilder underTest = PostProjectAnalysisTaskTester.newProjectBuilder();
37
38   @Test
39   public void setKey_throws_NPE_if_key_is_null() {
40     expectedException.expect(NullPointerException.class);
41     expectedException.expectMessage("key can not be null");
42
43     underTest.setKey(null);
44   }
45
46   @Test
47   public void setName_throws_NPE_if_name_is_null() {
48     expectedException.expect(NullPointerException.class);
49     expectedException.expectMessage("name can not be null");
50
51     underTest.setName(null);
52   }
53
54   @Test
55   public void setUuid_throws_NPE_if_uuid_is_null() {
56     expectedException.expect(NullPointerException.class);
57     expectedException.expectMessage("uuid can not be null");
58
59     underTest.setUuid(null);
60   }
61
62   @Test
63   public void build_throws_NPE_if_key_is_null() {
64     underTest.setUuid(SOME_UUID).setName(SOME_NAME);
65
66     expectedException.expect(NullPointerException.class);
67     expectedException.expectMessage("key can not be null");
68
69     underTest.build();
70   }
71
72   @Test
73   public void build_throws_NPE_if_name_is_null() {
74     underTest.setUuid(SOME_UUID).setKey(SOME_KEY);
75
76     expectedException.expect(NullPointerException.class);
77     expectedException.expectMessage("name can not be null");
78
79
80     underTest.build();
81   }
82
83   @Test
84   public void build_throws_NPE_if_uuid_is_null() {
85     underTest.setKey(SOME_KEY).setName(SOME_NAME);
86
87     expectedException.expect(NullPointerException.class);
88     expectedException.expectMessage("uuid can not be null");
89
90     underTest.build();
91   }
92
93   @Test
94   public void build_returns_new_instance_at_each_call() {
95     underTest.setUuid(SOME_UUID).setKey(SOME_KEY).setName(SOME_NAME);
96
97     assertThat(underTest.build()).isNotSameAs(underTest.build());
98   }
99
100   @Test
101   public void verify_getters() {
102     Project project = underTest.setUuid(SOME_UUID).setKey(SOME_KEY).setName(SOME_NAME).build();
103
104     assertThat(project.getUuid()).isEqualTo(SOME_UUID);
105     assertThat(project.getKey()).isEqualTo(SOME_KEY);
106     assertThat(project.getName()).isEqualTo(SOME_NAME);
107   }
108
109   @Test
110   public void verify_toString() {
111     assertThat(underTest.setUuid(SOME_UUID).setKey(SOME_KEY).setName(SOME_NAME).build().toString())
112       .isEqualTo("Project{uuid='some uuid', key='some key', name='some name'}");
113   }
114 }