3 * Copyright (C) 2009-2017 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.server.computation.task.projectanalysis.analysis;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.rules.ExpectedException;
25 import org.sonar.db.organization.OrganizationDto;
27 import static org.assertj.core.api.Assertions.assertThat;
29 public class OrganizationTest {
31 public ExpectedException expectedException = ExpectedException.none();
33 private OrganizationDto underTest = new OrganizationDto();
36 public void build_throws_NPE_if_dto_is_null() {
37 expectedException.expect(NullPointerException.class);
39 Organization.from(null);
43 public void build_throws_NPE_if_uuid_is_null() {
44 expectedException.expect(NullPointerException.class);
45 expectedException.expectMessage("uuid can't be null");
47 Organization.from(underTest);
51 public void build_throws_NPE_if_key_is_null() {
52 underTest.setUuid("uuid");
54 expectedException.expect(NullPointerException.class);
55 expectedException.expectMessage("key can't be null");
57 Organization.from(underTest);
61 public void build_throws_NPE_if_defaultQualityGateUuid_is_null() {
62 underTest.setUuid("uuid").setKey("key").setName("name");
64 expectedException.expect(NullPointerException.class);
65 expectedException.expectMessage("defaultQualityGateUuid can't be null");
67 Organization.from(underTest);
71 public void build_throws_NPE_if_name_is_null() {
72 underTest.setUuid("uuid").setKey("key");
74 expectedException.expect(NullPointerException.class);
75 expectedException.expectMessage("name can't be null");
77 Organization.from(underTest);
81 public void verify_getters() {
82 Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
84 assertThat(organization.getUuid()).isEqualTo("uuid");
85 assertThat(organization.getKey()).isEqualTo("key");
86 assertThat(organization.getName()).isEqualTo("name");
87 assertThat(organization.getDefaultQualityGateUuid()).isEqualTo("uuid1");
91 public void verify_toString() {
92 Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
94 assertThat(organization.toString()).isEqualTo("Organization{uuid='uuid', key='key', name='name', defaultQualityGateUuid='uuid1'}");
98 public void equals_is_based_on_uuid_only() {
99 Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
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");
111 public void hashcode_is_based_on_uuid_only() {
112 Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
114 assertThat(organization.hashCode()).isEqualTo("uuid".hashCode());