]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13766 PostProjectAnalysisTask's 'description' is a breaking change
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 17 Aug 2020 21:10:03 +0000 (16:10 -0500)
committersonartech <sonartech@sonarsource.com>
Tue, 25 Aug 2020 20:06:35 +0000 (20:06 +0000)
sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java
sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTest.java

index 5f1b61ec978271e1678e9187c78c7bcb15ad3a45..0f581e4d603ca4cfa32a3152300335b592227ea3 100644 (file)
@@ -46,19 +46,25 @@ public interface PostProjectAnalysisTask {
    * A short description or name for the task.
    * <p>
    * 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());
   }
index 0ff27846495c45138276cbf0769956edaf9aedec..f14035ef2f73d78bb2ed7112f9eb8068766636df 100644 (file)
@@ -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