From 963ebc53266c3ebf6ec7a52b67a933adaaf3cf89 Mon Sep 17 00:00:00 2001 From: Benjamin Campomenosi <109955405+benjamin-campomenosi-sonarsource@users.noreply.github.com> Date: Wed, 12 Jul 2023 14:04:51 +0200 Subject: [PATCH] SONAR-19850 Fix name of method in ProjectLifeCycleListeners --- .../project/ProjectLifeCycleListeners.java | 2 +- .../ProjectLifeCycleListenersImpl.java | 2 +- .../ProjectLifeCycleListenersImplTest.java | 33 ++++++++++--------- .../server/branch/ws/DeleteActionIT.java | 2 +- .../branch/ws/SetMainBranchActionIT.java | 2 +- .../sonar/server/branch/ws/DeleteAction.java | 2 +- .../server/branch/ws/SetMainBranchAction.java | 2 +- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectLifeCycleListeners.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectLifeCycleListeners.java index 0a8c2238cb0..981237903e3 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectLifeCycleListeners.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectLifeCycleListeners.java @@ -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 projects); + void onProjectBranchesChanged(Set projects); /** * This method is called after the specified project's key has been changed and will call method diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectLifeCycleListenersImpl.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectLifeCycleListenersImpl.java index a7e96c110e1..9d98d0f80af 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectLifeCycleListenersImpl.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectLifeCycleListenersImpl.java @@ -61,7 +61,7 @@ public class ProjectLifeCycleListenersImpl implements ProjectLifeCycleListeners } @Override - public void onProjectBranchesDeleted(Set projects) { + public void onProjectBranchesChanged(Set projects) { checkNotNull(projects, "projects can't be null"); if (projects.isEmpty()) { return; diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/project/ProjectLifeCycleListenersImplTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/project/ProjectLifeCycleListenersImplTest.java index c73ef83e00e..600a3876564 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/project/ProjectLifeCycleListenersImplTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/project/ProjectLifeCycleListenersImplTest.java @@ -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 projects) { - underTestNoListeners.onProjectBranchesDeleted(projects); + public void onProjectBranchesChanged_does_not_fail_if_there_is_no_listener(Set projects) { + assertThatNoException().isThrownBy(()-> underTestNoListeners.onProjectBranchesChanged(projects)); } @Test @UseDataProvider("oneOrManyProjects") - public void onProjectBranchesDeleted_calls_all_listeners_in_order_of_addition_to_constructor(Set projects) { + public void onProjectBranchesChanged_calls_all_listeners_in_order_of_addition_to_constructor(Set 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 projects) { + public void onProjectBranchesChanged_calls_all_listeners_even_if_one_throws_an_Exception(Set 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 projects) { + public void onProjectBranchesChanged_calls_all_listeners_even_if_one_throws_an_Error(Set 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 projects) { - underTestNoListeners.onProjectsRekeyed(projects); + assertThatNoException().isThrownBy(() -> underTestNoListeners.onProjectsRekeyed(projects)); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/DeleteActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/DeleteActionIT.java index fd675a91327..45b7a464bf8 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/DeleteActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/DeleteActionIT.java @@ -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 diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/SetMainBranchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/SetMainBranchActionIT.java index bff8917f060..a6ad1c0de56 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/SetMainBranchActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/SetMainBranchActionIT.java @@ -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) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/DeleteAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/DeleteAction.java index b636143d1d7..8c1d14e85f9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/DeleteAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/DeleteAction.java @@ -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(); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/SetMainBranchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/SetMainBranchAction.java index 77861127ab6..8f62233136c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/SetMainBranchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/SetMainBranchAction.java @@ -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) { -- 2.39.5