You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QualityGateImplTest.java 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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.api.posttask;
  21. import com.google.common.collect.ImmutableList;
  22. import java.util.Collections;
  23. import java.util.List;
  24. import org.junit.Test;
  25. import org.sonar.api.ce.posttask.QualityGate;
  26. import static org.assertj.core.api.Assertions.assertThat;
  27. import static org.assertj.core.api.Assertions.assertThatThrownBy;
  28. import static org.mockito.Mockito.mock;
  29. import static org.mockito.Mockito.when;
  30. public class QualityGateImplTest {
  31. private static final String SOME_ID = "some id";
  32. private static final String SOME_NAME = "some name";
  33. private static final QualityGate.Status SOME_STATUS = QualityGate.Status.OK;
  34. private QualityGate.Condition condition = mock(QualityGate.Condition.class);
  35. private QualityGateImpl underTest = new QualityGateImpl(SOME_ID, SOME_NAME, SOME_STATUS, ImmutableList.of(condition));
  36. @Test
  37. public void constructor_throws_NPE_if_id_argument_is_null() {
  38. assertThatThrownBy(() -> new QualityGateImpl(null, SOME_NAME, SOME_STATUS, Collections.emptyList()))
  39. .isInstanceOf(NullPointerException.class)
  40. .hasMessage("id can not be null");
  41. }
  42. @Test
  43. public void constructor_throws_NPE_if_name_argument_is_null() {
  44. assertThatThrownBy(() -> new QualityGateImpl(SOME_ID, null, SOME_STATUS, Collections.emptyList()))
  45. .isInstanceOf(NullPointerException.class)
  46. .hasMessage("name can not be null");
  47. }
  48. @Test
  49. public void constructor_throws_NPE_if_status_argument_is_null() {
  50. assertThatThrownBy(() -> new QualityGateImpl(SOME_ID, SOME_NAME, null, Collections.emptyList()))
  51. .isInstanceOf(NullPointerException.class)
  52. .hasMessage("status can not be null");
  53. }
  54. @Test
  55. public void constructor_throws_NPE_if_conditions_argument_is_null() {
  56. assertThatThrownBy(() -> new QualityGateImpl(SOME_ID, SOME_NAME, SOME_STATUS, null))
  57. .isInstanceOf(NullPointerException.class)
  58. .hasMessage("conditions can not be null");
  59. }
  60. @Test
  61. public void verify_getters() {
  62. List<QualityGate.Condition> conditions = ImmutableList.of(condition);
  63. QualityGateImpl underTest = new QualityGateImpl(SOME_ID, SOME_NAME, SOME_STATUS, conditions);
  64. assertThat(underTest.getId()).isEqualTo(SOME_ID);
  65. assertThat(underTest.getName()).isEqualTo(SOME_NAME);
  66. assertThat(underTest.getStatus()).isEqualTo(SOME_STATUS);
  67. assertThat(underTest.getConditions()).isEqualTo(conditions);
  68. }
  69. @Test
  70. public void verify_toString() {
  71. when(condition.toString()).thenReturn("{Condition}");
  72. assertThat(underTest.toString())
  73. .isEqualTo("QualityGateImpl{id='some id', name='some name', status=OK, conditions=[{Condition}]}");
  74. }
  75. }