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_name_is_null() {
62 underTest.setUuid("uuid").setKey("key");
64 expectedException.expect(NullPointerException.class);
65 expectedException.expectMessage("name can't be null");
67 Organization.from(underTest);
71 public void verify_getters() {
72 Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name"));
74 assertThat(organization.getUuid()).isEqualTo("uuid");
75 assertThat(organization.getKey()).isEqualTo("key");
76 assertThat(organization.getName()).isEqualTo("name");
80 public void verify_toString() {
81 Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name"));
83 assertThat(organization.toString()).isEqualTo("Organization{uuid='uuid', key='key', name='name'}");
87 public void equals_is_based_on_uuid_only() {
88 Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name"));
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");
99 public void hashcode_is_based_on_uuid_only() {
100 Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name"));
102 assertThat(organization.hashCode()).isEqualTo("uuid".hashCode());