3 * Copyright (C) 2009-2023 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.ce.task.projectanalysis.event;
22 import org.junit.Test;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.assertj.core.api.Assertions.assertThatThrownBy;
27 public class EventTest {
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";
34 public void createAlert_fail_fast_null_check_on_null_name() {
35 assertThatThrownBy(() -> Event.createAlert(null, SOME_DATA, SOME_DESCRIPTION))
36 .isInstanceOf(NullPointerException.class);
40 public void createProfile_fail_fast_null_check_on_null_name() {
41 assertThatThrownBy(() -> Event.createProfile(null, SOME_DATA, SOME_DESCRIPTION))
42 .isInstanceOf(NullPointerException.class);
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);
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);
64 public void same_name_and_category_make_equal_events() {
65 Event source = Event.createAlert(SOME_NAME, null, null);
67 .isEqualTo(Event.createAlert(SOME_NAME, null, null))