* 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());
}
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;
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