3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact 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.api.ce.posttask;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.rules.ExpectedException;
26 import static org.assertj.core.api.Assertions.assertThat;
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";
34 public ExpectedException expectedException = ExpectedException.none();
36 private PostProjectAnalysisTaskTester.ProjectBuilder underTest = PostProjectAnalysisTaskTester.newProjectBuilder();
39 public void setKey_throws_NPE_if_key_is_null() {
40 expectedException.expect(NullPointerException.class);
41 expectedException.expectMessage("key can not be null");
43 underTest.setKey(null);
47 public void setName_throws_NPE_if_name_is_null() {
48 expectedException.expect(NullPointerException.class);
49 expectedException.expectMessage("name can not be null");
51 underTest.setName(null);
55 public void setUuid_throws_NPE_if_uuid_is_null() {
56 expectedException.expect(NullPointerException.class);
57 expectedException.expectMessage("uuid can not be null");
59 underTest.setUuid(null);
63 public void build_throws_NPE_if_key_is_null() {
64 underTest.setUuid(SOME_UUID).setName(SOME_NAME);
66 expectedException.expect(NullPointerException.class);
67 expectedException.expectMessage("key can not be null");
73 public void build_throws_NPE_if_name_is_null() {
74 underTest.setUuid(SOME_UUID).setKey(SOME_KEY);
76 expectedException.expect(NullPointerException.class);
77 expectedException.expectMessage("name can not be null");
84 public void build_throws_NPE_if_uuid_is_null() {
85 underTest.setKey(SOME_KEY).setName(SOME_NAME);
87 expectedException.expect(NullPointerException.class);
88 expectedException.expectMessage("uuid can not be null");
94 public void build_returns_new_instance_at_each_call() {
95 underTest.setUuid(SOME_UUID).setKey(SOME_KEY).setName(SOME_NAME);
97 assertThat(underTest.build()).isNotSameAs(underTest.build());
101 public void verify_getters() {
102 Project project = underTest.setUuid(SOME_UUID).setKey(SOME_KEY).setName(SOME_NAME).build();
104 assertThat(project.getUuid()).isEqualTo(SOME_UUID);
105 assertThat(project.getKey()).isEqualTo(SOME_KEY);
106 assertThat(project.getName()).isEqualTo(SOME_NAME);
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'}");