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.

SonarLintClientTest.java 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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.server.pushapi.sonarlint;
  21. import java.util.Set;
  22. import javax.servlet.AsyncContext;
  23. import org.junit.Test;
  24. import static org.assertj.core.api.Assertions.assertThat;
  25. import static org.mockito.Mockito.mock;
  26. public class SonarLintClientTest {
  27. private final AsyncContext firstContext = mock(AsyncContext.class);
  28. private final AsyncContext secondContext = mock(AsyncContext.class);
  29. private final String USER_UUID = "userUUID";
  30. private final SonarLintPushEventExecutorService sonarLintPushEventExecutorService = mock(SonarLintPushEventExecutorService.class);
  31. @Test
  32. public void equals_twoClientsWithSameArgumentsAreEqual() {
  33. SonarLintClient first = new SonarLintClient(sonarLintPushEventExecutorService, firstContext, Set.of(), Set.of(), USER_UUID);
  34. SonarLintClient second = new SonarLintClient(sonarLintPushEventExecutorService, firstContext, Set.of(), Set.of(), USER_UUID);
  35. assertThat(first).isEqualTo(second);
  36. }
  37. @Test
  38. public void equals_twoClientsWithDifferentAsyncObjects() {
  39. SonarLintClient first = new SonarLintClient(sonarLintPushEventExecutorService, firstContext, Set.of(), Set.of(), USER_UUID);
  40. SonarLintClient second = new SonarLintClient(sonarLintPushEventExecutorService, secondContext, Set.of(), Set.of(), USER_UUID);
  41. assertThat(first).isNotEqualTo(second);
  42. }
  43. @Test
  44. public void equals_twoClientsWithDifferentLanguages() {
  45. SonarLintClient first = new SonarLintClient(sonarLintPushEventExecutorService, firstContext, Set.of(), Set.of("java"), USER_UUID);
  46. SonarLintClient second = new SonarLintClient(sonarLintPushEventExecutorService, firstContext, Set.of(), Set.of("cobol"), USER_UUID);
  47. assertThat(first).isNotEqualTo(second);
  48. }
  49. @Test
  50. public void equals_twoClientsWithDifferentProjectUuids() {
  51. SonarLintClient first = new SonarLintClient(sonarLintPushEventExecutorService, firstContext, Set.of("project1", "project2"), Set.of(), USER_UUID);
  52. SonarLintClient second = new SonarLintClient(sonarLintPushEventExecutorService, firstContext, Set.of("project1"), Set.of(), USER_UUID);
  53. assertThat(first).isNotEqualTo(second);
  54. }
  55. @Test
  56. public void equals_secondClientIsNull() {
  57. SonarLintClient first = new SonarLintClient(sonarLintPushEventExecutorService, firstContext, Set.of("project1", "project2"), Set.of(), USER_UUID);
  58. assertThat(first).isNotEqualTo(null);
  59. }
  60. @Test
  61. public void hashCode_producesSameHashesForEqualObjects() {
  62. SonarLintClient first = new SonarLintClient(sonarLintPushEventExecutorService, firstContext, Set.of(), Set.of(), USER_UUID);
  63. SonarLintClient second = new SonarLintClient(sonarLintPushEventExecutorService, firstContext, Set.of(), Set.of(), USER_UUID);
  64. assertThat(first).hasSameHashCodeAs(second);
  65. }
  66. }