From 60c64b2c9f95bb52d070758fa88a3881ae69b5e7 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 17 Aug 2020 16:10:03 -0500 Subject: [PATCH] SONAR-13766 PostProjectAnalysisTask's 'description' is a breaking change --- .../ce/posttask/PostProjectAnalysisTask.java | 10 ++++++++-- .../posttask/PostProjectAnalysisTaskTest.java | 19 +++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java index 5f1b61ec978..0f581e4d603 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java @@ -46,19 +46,25 @@ public interface PostProjectAnalysisTask { * A short description or name for the task. *

* This will be used (but not limited to) in logs reporting the execution of the task. + * @since 8.0 */ - String getDescription(); + default String getDescription() { + return this.getClass().getSimpleName(); + } /** * This method is called whenever the processing of a Project analysis has finished, whether successfully or not. * - * @deprecated implement {@link #finished(Context)} instead + * @deprecated in 8.0. Implement {@link #finished(Context)} instead */ @Deprecated default void finished(ProjectAnalysis analysis) { throw new IllegalStateException("Provide an implementation of method finished(Context)"); } + /** + * @since 8.0 + */ default void finished(Context context) { finished(context.getProjectAnalysis()); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTest.java index 0ff27846495..f14035ef2f7 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTest.java @@ -25,7 +25,6 @@ import org.sonar.api.ce.posttask.PostProjectAnalysisTask.Context; import org.sonar.api.ce.posttask.PostProjectAnalysisTask.ProjectAnalysis; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -35,18 +34,14 @@ public class PostProjectAnalysisTaskTest { private final ProjectAnalysis projectAnalysis = Mockito.mock(ProjectAnalysis.class); @Test - public void default_implementation_of_finished_ProjectAnalysis_throws_ISE() { - PostProjectAnalysisTask underTest = () -> { - throw new UnsupportedOperationException("getDescription not implemented"); - }; + public void default_implementation_of_finished_ProjectAnalysis_returns_class_name() { + PostProjectAnalysisTask underTest = new PostTask(); + + assertThat(underTest.getDescription()).isEqualTo("PostTask"); + } + + private static class PostTask implements PostProjectAnalysisTask { - try { - underTest.finished(projectAnalysis); - fail("should have thrown an ISE"); - } catch (IllegalStateException e) { - assertThat(e.getMessage()).isEqualTo("Provide an implementation of method finished(Context)"); - Mockito.verifyZeroInteractions(projectAnalysis); - } } @Test -- 2.39.5