]> source.dussan.org Git - sonarqube.git/blob
264f14d2cc2eaf1817cb8f4547eae40105faf1b9
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2023 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.ce.task.projectanalysis.event;
21
22 import org.junit.Test;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.assertj.core.api.Assertions.assertThatThrownBy;
26
27 public class EventTest {
28
29   private static final String SOME_NAME = "someName";
30   private static final String SOME_DATA = "some data";
31   private static final String SOME_DESCRIPTION = "some description";
32
33   @Test
34   public void createAlert_fail_fast_null_check_on_null_name() {
35     assertThatThrownBy(() -> Event.createAlert(null, SOME_DATA, SOME_DESCRIPTION))
36       .isInstanceOf(NullPointerException.class);
37   }
38
39   @Test
40   public void createProfile_fail_fast_null_check_on_null_name() {
41     assertThatThrownBy(() -> Event.createProfile(null, SOME_DATA, SOME_DESCRIPTION))
42       .isInstanceOf(NullPointerException.class);
43   }
44
45   @Test
46   public void createAlert_verify_fields() {
47     Event event = Event.createAlert(SOME_NAME, SOME_DATA, SOME_DESCRIPTION);
48     assertThat(event.getName()).isEqualTo(SOME_NAME);
49     assertThat(event.getCategory()).isEqualTo(Event.Category.ALERT);
50     assertThat(event.getData()).isEqualTo(SOME_DATA);
51     assertThat(event.getDescription()).isEqualTo(SOME_DESCRIPTION);
52   }
53
54   @Test
55   public void createProfile_verify_fields() {
56     Event event = Event.createProfile(SOME_NAME, SOME_DATA, SOME_DESCRIPTION);
57     assertThat(event.getName()).isEqualTo(SOME_NAME);
58     assertThat(event.getCategory()).isEqualTo(Event.Category.PROFILE);
59     assertThat(event.getData()).isEqualTo(SOME_DATA);
60     assertThat(event.getDescription()).isEqualTo(SOME_DESCRIPTION);
61   }
62
63   @Test
64   public void same_name_and_category_make_equal_events() {
65     Event source = Event.createAlert(SOME_NAME, null, null);
66     assertThat(source)
67       .isEqualTo(Event.createAlert(SOME_NAME, null, null))
68       .isEqualTo(source)
69       .isNotNull();
70   }
71 }