<commit_before>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.progress.impl

import com.intellij.idea.TestFor
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.testFramework.LightPlatformTestCase
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.util.concurrency.AppExecutorUtil
import com.intellij.util.ui.UIUtil
import java.util.concurrent.atomic.AtomicInteger

class ProgressManagerContractsTest : LightPlatformTestCase() {
  fun `test backgroundable task exception is thrown directly in GUI`() = runWithGuiTasksMode {
    `test backgroundable task exception is thrown directly in tests`()
  }

  fun `test backgroundable task exception is thrown directly in tests`() {
    val msg = "This is our failure message to test"

    val task = object : Task.Backgroundable(project, "mock", true) {
      override fun run(indicator: ProgressIndicator) {
        throw RuntimeException(msg)
      }
    }

    try {
      task.queue()
    } catch (t: Throwable) {
      assertThat(t.message).contains(msg)
    }
  }

  @TestFor(issues = ["IDEA-241785"])
  fun `test backgroundable modality in GUI`() = runWithGuiTasksMode { `test backgroundable modality in tests`() }

  @TestFor(issues = ["IDEA-241785"])
  fun `test backgroundable modality in tests`() = repeat(10) {
    require(ApplicationManager.getApplication().isDispatchThread)
    var callbackResult = ""

    val taskCompleted = AtomicInteger(0)
    ApplicationManager.getApplication().invokeLater {
      callbackResult += "invokeLater."
      taskCompleted.incrementAndGet()
    }

    object : Task.Backgroundable(project, "mock", true) {
      override fun run(indicator: ProgressIndicator) {
        // we add the next callbackResult update operation.
        ApplicationManager.getApplication().invokeAndWait {
          callbackResult += "fromProgress."
          taskCompleted.incrementAndGet()
        }
      }

      override fun onFinished() {
        super.onFinished()
        taskCompleted.incrementAndGet()
      }
    }.queue()
<commit_msg>ProgressManager - remove unneeded contract tests<commit_after>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.progress.impl

import com.intellij.idea.TestFor
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.testFramework.LightPlatformTestCase
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.util.concurrency.AppExecutorUtil
import com.intellij.util.ui.UIUtil
import org.junit.Ignore
import java.util.concurrent.atomic.AtomicInteger

class ProgressManagerContractsTest : LightPlatformTestCase() {
  @TestFor(issues = ["IDEA-241785"])
  fun `test backgroundable modality in GUI`() = runWithGuiTasksMode { `test backgroundable modality in tests`() }

  @TestFor(issues = ["IDEA-241785"])
  fun `test backgroundable modality in tests`() = repeat(10) {
    require(ApplicationManager.getApplication().isDispatchThread)
    var callbackResult = ""

    val taskCompleted = AtomicInteger(0)
    ApplicationManager.getApplication().invokeLater {
      callbackResult += "invokeLater."
      taskCompleted.incrementAndGet()
    }

    object : Task.Backgroundable(project, "mock", true) {
      override fun run(indicator: ProgressIndicator) {
        // we add the next callbackResult update operation.
        ApplicationManager.getApplication().invokeAndWait {
          callbackResult += "fromProgress."
          taskCompleted.incrementAndGet()
        }
      }

      override fun onFinished() {
        super.onFinished()
        taskCompleted.incrementAndGet()
      }
    }.queue()

{'fraction_non_alphanumeric': 0.09365781710914454, 'fraction_numerical': 0.012291052114060964, 'mean_word_length': 3.902409638554217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2775425', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1108, 'n_words': 275}