]> source.dussan.org Git - sonarqube.git/blob
75c251936a8b07f6cca33e346d57f319ba42118e
[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_defaultQualityGateUuid_is_null() {
62     underTest.setUuid("uuid").setKey("key").setName("name");
63
64     expectedException.expect(NullPointerException.class);
65     expectedException.expectMessage("defaultQualityGateUuid can't be null");
66
67     Organization.from(underTest);
68   }
69
70   @Test
71   public void build_throws_NPE_if_name_is_null() {
72     underTest.setUuid("uuid").setKey("key");
73     
74     expectedException.expect(NullPointerException.class);
75     expectedException.expectMessage("name can't be null");
76
77     Organization.from(underTest);
78   }
79
80   @Test
81   public void verify_getters() {
82     Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
83
84     assertThat(organization.getUuid()).isEqualTo("uuid");
85     assertThat(organization.getKey()).isEqualTo("key");
86     assertThat(organization.getName()).isEqualTo("name");
87     assertThat(organization.getDefaultQualityGateUuid()).isEqualTo("uuid1");
88   }
89
90   @Test
91   public void verify_toString() {
92     Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
93
94     assertThat(organization.toString()).isEqualTo("Organization{uuid='uuid', key='key', name='name', defaultQualityGateUuid='uuid1'}");
95   }
96
97   @Test
98   public void equals_is_based_on_uuid_only() {
99     Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
100
101     assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1")));
102     assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("other key").setName("name").setDefaultQualityGateUuid("uuid1")));
103     assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("other name").setDefaultQualityGateUuid("uuid1")));
104     assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("other uuid")));
105     assertThat(organization).isNotEqualTo(Organization.from(underTest.setUuid("other uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1")));
106     assertThat(organization).isNotEqualTo(null);
107     assertThat(organization).isNotEqualTo("toto");
108   }
109
110   @Test
111   public void hashcode_is_based_on_uuid_only() {
112     Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
113
114     assertThat(organization.hashCode()).isEqualTo("uuid".hashCode());
115   }
116 }