]> source.dussan.org Git - sonarqube.git/blob
aedf90d7266f8a03a93785bf23b58cfc116ce4a6
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2017 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.server.computation.task.projectanalysis.analysis;
21
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.rules.ExpectedException;
25 import org.sonar.db.organization.OrganizationDto;
26
27 import static org.assertj.core.api.Assertions.assertThat;
28
29 public class OrganizationTest {
30   @Rule
31   public ExpectedException expectedException = ExpectedException.none();
32
33   private OrganizationDto underTest = new OrganizationDto();
34
35   @Test
36   public void build_throws_NPE_if_dto_is_null() {
37     expectedException.expect(NullPointerException.class);
38
39     Organization.from(null);
40   }
41
42   @Test
43   public void build_throws_NPE_if_uuid_is_null() {
44     expectedException.expect(NullPointerException.class);
45     expectedException.expectMessage("uuid can't be null");
46
47     Organization.from(underTest);
48   }
49
50   @Test
51   public void build_throws_NPE_if_key_is_null() {
52     underTest.setUuid("uuid");
53     
54     expectedException.expect(NullPointerException.class);
55     expectedException.expectMessage("key can't be null");
56
57     Organization.from(underTest);
58   }
59
60   @Test
61   public void build_throws_NPE_if_name_is_null() {
62     underTest.setUuid("uuid").setKey("key");
63     
64     expectedException.expect(NullPointerException.class);
65     expectedException.expectMessage("name can't be null");
66
67     Organization.from(underTest);
68   }
69
70   @Test
71   public void verify_getters() {
72     Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name"));
73
74     assertThat(organization.getUuid()).isEqualTo("uuid");
75     assertThat(organization.getKey()).isEqualTo("key");
76     assertThat(organization.getName()).isEqualTo("name");
77   }
78
79   @Test
80   public void verify_toString() {
81     Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name"));
82
83     assertThat(organization.toString()).isEqualTo("Organization{uuid='uuid', key='key', name='name'}");
84   }
85
86   @Test
87   public void equals_is_based_on_uuid_only() {
88     Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name"));
89
90     assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("name")));
91     assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("other key").setName("name")));
92     assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("other name")));
93     assertThat(organization).isNotEqualTo(Organization.from(underTest.setUuid("other uuid").setKey("key").setName("name")));
94     assertThat(organization).isNotEqualTo(null);
95     assertThat(organization).isNotEqualTo("toto");
96   }
97
98   @Test
99   public void hashcode_is_based_on_uuid_only() {
100     Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name"));
101
102     assertThat(organization.hashCode()).isEqualTo("uuid".hashCode());
103   }
104 }