]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19850 Fix name of method in ProjectLifeCycleListeners
authorBenjamin Campomenosi <109955405+benjamin-campomenosi-sonarsource@users.noreply.github.com>
Wed, 12 Jul 2023 12:04:51 +0000 (14:04 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 19 Jul 2023 20:03:06 +0000 (20:03 +0000)
server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectLifeCycleListeners.java
server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectLifeCycleListenersImpl.java
server/sonar-webserver-api/src/test/java/org/sonar/server/project/ProjectLifeCycleListenersImplTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/DeleteActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/SetMainBranchActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/DeleteAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/SetMainBranchAction.java

index 0a8c2238cb020b06eb5bbb864c986dd784042174..981237903e39d674b220fa933230f1ce6bebfb21 100644 (file)
@@ -40,7 +40,7 @@ public interface ProjectLifeCycleListeners {
    * This method ensures all {@link ProjectLifeCycleListener} implementations are called, even if one or more of
    * them fail with an exception.
    */
-  void onProjectBranchesDeleted(Set<Project> projects);
+  void onProjectBranchesChanged(Set<Project> projects);
 
   /**
    * This method is called after the specified project's key has been changed and will call method
index a7e96c110e162b2d7bb91dd4d18a0a7930fa4ce0..9d98d0f80afb50964ed7283f3daa3d160f68aa7c 100644 (file)
@@ -61,7 +61,7 @@ public class ProjectLifeCycleListenersImpl implements ProjectLifeCycleListeners
   }
 
   @Override
-  public void onProjectBranchesDeleted(Set<Project> projects) {
+  public void onProjectBranchesChanged(Set<Project> projects) {
     checkNotNull(projects, "projects can't be null");
     if (projects.isEmpty()) {
       return;
index c73ef83e00e48196cd944ce2f6d9964bfcac93f8..600a387656463e0a91df0f15dac86101d0675b80 100644 (file)
@@ -34,6 +34,7 @@ import org.mockito.Mockito;
 
 import static java.util.Collections.singleton;
 import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatNoException;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.same;
@@ -126,39 +127,39 @@ public class ProjectLifeCycleListenersImplTest {
   }
 
   @Test
-  public void onProjectBranchesDeleted_throws_NPE_if_set_is_null() {
-    assertThatThrownBy(() -> underTestWithListeners.onProjectBranchesDeleted(null))
+  public void onProjectBranchesChanged_throws_NPE_if_set_is_null() {
+    assertThatThrownBy(() -> underTestWithListeners.onProjectBranchesChanged(null))
       .isInstanceOf(NullPointerException.class)
       .hasMessage("projects can't be null");
   }
 
   @Test
-  public void onProjectBranchesDeleted_throws_NPE_if_set_is_null_even_if_no_listeners() {
-    assertThatThrownBy(() -> underTestNoListeners.onProjectBranchesDeleted(null))
+  public void onProjectBranchesChanged_throws_NPE_if_set_is_null_even_if_no_listeners() {
+    assertThatThrownBy(() -> underTestNoListeners.onProjectBranchesChanged(null))
       .isInstanceOf(NullPointerException.class)
       .hasMessage("projects can't be null");
   }
 
   @Test
-  public void onProjectBranchesDeleted_has_no_effect_if_set_is_empty() {
-    underTestNoListeners.onProjectBranchesDeleted(Collections.emptySet());
+  public void onProjectBranchesChanged_has_no_effect_if_set_is_empty() {
+    underTestNoListeners.onProjectBranchesChanged(Collections.emptySet());
 
-    underTestWithListeners.onProjectBranchesDeleted(Collections.emptySet());
+    underTestWithListeners.onProjectBranchesChanged(Collections.emptySet());
     verifyNoInteractions(listener1, listener2, listener3);
   }
 
   @Test
   @UseDataProvider("oneOrManyProjects")
-  public void onProjectBranchesDeleted_does_not_fail_if_there_is_no_listener(Set<Project> projects) {
-    underTestNoListeners.onProjectBranchesDeleted(projects);
+  public void onProjectBranchesChanged_does_not_fail_if_there_is_no_listener(Set<Project> projects) {
+     assertThatNoException().isThrownBy(()-> underTestNoListeners.onProjectBranchesChanged(projects));
   }
 
   @Test
   @UseDataProvider("oneOrManyProjects")
-  public void onProjectBranchesDeleted_calls_all_listeners_in_order_of_addition_to_constructor(Set<Project> projects) {
+  public void onProjectBranchesChanged_calls_all_listeners_in_order_of_addition_to_constructor(Set<Project> projects) {
     InOrder inOrder = Mockito.inOrder(listener1, listener2, listener3);
 
-    underTestWithListeners.onProjectBranchesDeleted(projects);
+    underTestWithListeners.onProjectBranchesChanged(projects);
 
     inOrder.verify(listener1).onProjectBranchesChanged(same(projects));
     inOrder.verify(listener2).onProjectBranchesChanged(same(projects));
@@ -168,13 +169,13 @@ public class ProjectLifeCycleListenersImplTest {
 
   @Test
   @UseDataProvider("oneOrManyProjects")
-  public void onProjectBranchesDeleted_calls_all_listeners_even_if_one_throws_an_Exception(Set<Project> projects) {
+  public void onProjectBranchesChanged_calls_all_listeners_even_if_one_throws_an_Exception(Set<Project> projects) {
     InOrder inOrder = Mockito.inOrder(listener1, listener2, listener3);
     doThrow(new RuntimeException("Faking listener2 throwing an exception"))
       .when(listener2)
       .onProjectBranchesChanged(any());
 
-    underTestWithListeners.onProjectBranchesDeleted(projects);
+    underTestWithListeners.onProjectBranchesChanged(projects);
 
     inOrder.verify(listener1).onProjectBranchesChanged(same(projects));
     inOrder.verify(listener2).onProjectBranchesChanged(same(projects));
@@ -184,13 +185,13 @@ public class ProjectLifeCycleListenersImplTest {
 
   @Test
   @UseDataProvider("oneOrManyProjects")
-  public void onProjectBranchesDeleted_calls_all_listeners_even_if_one_throws_an_Error(Set<Project> projects) {
+  public void onProjectBranchesChanged_calls_all_listeners_even_if_one_throws_an_Error(Set<Project> projects) {
     InOrder inOrder = Mockito.inOrder(listener1, listener2, listener3);
     doThrow(new Error("Faking listener2 throwing an Error"))
       .when(listener2)
       .onProjectBranchesChanged(any());
 
-    underTestWithListeners.onProjectBranchesDeleted(projects);
+    underTestWithListeners.onProjectBranchesChanged(projects);
 
     inOrder.verify(listener1).onProjectBranchesChanged(same(projects));
     inOrder.verify(listener2).onProjectBranchesChanged(same(projects));
@@ -240,7 +241,7 @@ public class ProjectLifeCycleListenersImplTest {
   @Test
   @UseDataProvider("oneOrManyRekeyedProjects")
   public void onProjectsRekeyed_does_not_fail_if_there_is_no_listener(Set<RekeyedProject> projects) {
-    underTestNoListeners.onProjectsRekeyed(projects);
+    assertThatNoException().isThrownBy(() -> underTestNoListeners.onProjectsRekeyed(projects));
   }
 
   @Test
index fd675a913270bcc30dc57b754a4f66a82b859a83..45b7a464bf846997513c6c9cbde25736c7978283 100644 (file)
@@ -72,7 +72,7 @@ public class DeleteActionIT {
       .execute();
 
     verifyDeletedKey("branch1");
-    verify(projectLifeCycleListeners).onProjectBranchesDeleted(singleton(Project.fromProjectDtoWithTags(project)));
+    verify(projectLifeCycleListeners).onProjectBranchesChanged(singleton(Project.fromProjectDtoWithTags(project)));
   }
 
   @Test
index bff8917f060ce013033a252554ff45569e3d1081..a6ad1c0de566ccdc3ac7ec5223762aba575303eb 100644 (file)
@@ -230,7 +230,7 @@ public class SetMainBranchActionIT {
 
   private void checkCallToProjectLifeCycleListenersOnProjectBranchesChanges(ProjectDto projectDto) {
     Project project = Project.from(projectDto);
-    verify(projectLifeCycleListeners).onProjectBranchesDeleted(Set.of(project));
+    verify(projectLifeCycleListeners).onProjectBranchesChanged(Set.of(project));
   }
 
   private void checkNewMainBranch(String projectUuid, String newBranchUuid) {
index b636143d1d794c6a47d21de51875e762235aaed2..8c1d14e85f9719a600478144279fddf0f80acba6 100644 (file)
@@ -86,7 +86,7 @@ public class DeleteAction implements BranchWsAction {
         "Branch '%s' not found for project '%s'", branchKey, projectKey);
 
       componentCleanerService.deleteBranch(dbSession, branch);
-      projectLifeCycleListeners.onProjectBranchesDeleted(singleton(Project.fromProjectDtoWithTags(project)));
+      projectLifeCycleListeners.onProjectBranchesChanged(singleton(Project.fromProjectDtoWithTags(project)));
       response.noContent();
     }
   }
index 77861127ab6d52ae6d4d98b8b91534e7fddeab6a..8f62233136c18d60c28153523c7b81d1f5592123 100644 (file)
@@ -122,7 +122,7 @@ public class SetMainBranchAction implements BranchWsAction {
   }
 
   private void refreshApplicationsAndPortfoliosComputedByProject(ProjectDto projectDto) {
-    projectLifeCycleListeners.onProjectBranchesDeleted(singleton(Project.from(projectDto)));
+    projectLifeCycleListeners.onProjectBranchesChanged(singleton(Project.from(projectDto)));
   }
 
   private void updateNewMainBranch(DbSession dbSession, BranchDto newMainBranch) {