<commit_before>package ru.agentlab.maia.task.test.integration

import java.util.ArrayList
import java.util.HashMap
import java.util.List
import java.util.Map
import org.hamcrest.Matchers
import org.jbehave.core.annotations.Given
import org.jbehave.core.annotations.Then
import org.jbehave.core.annotations.When
import org.mockito.InOrder
import ru.agentlab.maia.task.ITask
import ru.agentlab.maia.task.ITask.State
import ru.agentlab.maia.task.ITaskScheduler
import ru.agentlab.maia.task.annotation.Action
import ru.agentlab.maia.task.parallel.ParallelTaskScheduler
import ru.agentlab.maia.task.primitive.AnnotatedAction
import ru.agentlab.maia.task.sequential.SequentialTaskScheduler

import static org.junit.Assert.*
import static org.mockito.Mockito.*

class Main {

	val Map<String, ITask> cache = new HashMap

	var InOrder inOrder

	@Given("a sequential schedulers $ids")
	def void givenSequentialScheduler(List<String> ids) {
		ids.forEach [
			cache.put(it, new SequentialTaskScheduler)
		]
	}

	@Given("a parallel schedulers $ids")
	def void givenParallelScheduler(List<String> ids) {
		ids.forEach [
			cache.put(it, new ParallelTaskScheduler)
		]
	}

	@Given("a primitive tasks $ids")
	def void givenPrimitiveTask(List<String> ids) {
		val primitives = new ArrayList
		ids.forEach [
			val primitive = spy(new AnnotatedAction(new DummyAction))
			cache.put(it, primitive)
			primitives += primitive
		]
		inOrder = inOrder(primitives.toArray)
	}

	@Given("task $id have subtasks $ids")
	def void givenTaskHaveSubtasks(String id, List<String> ids) {
		val scheduler = cache.get(id) as ITaskScheduler
		ids.forEach [
			scheduler.addSubtask(cache.get(it))
		]
	}

	@When("execute task $id by $times times")
	def void whenExecuteTaskByTimes(String id, int times) {
		val task = cache.get(id)
		for (i : 0 ..< times) {
			task.execute
		}
	}

	@Then("execution order is $ids")
	def void thenExecutionOrderIs(List<String> ids) {
		ids.forEach [
			inOrder.verify(cache.get(it)).execute
		]
	}

	@Then("task $execute have been executed")
	def void thenTaskExecuted(String id) {
		if (id != null && !id.empty) {
			verify(cache.get(id)).execute
		}
	}

	@Then("task $id have $state state")
	def void thenTaskHaveState(String id, String state) {
		assertThat(cache.get(id).state, Matchers.equalTo(State.valueOf(state)))
	}

}

class DummyAction {

	@Action
	def void action() {
	}
}<commit_msg>- remove Mockito, annotations lost when spy or mock<commit_after>package ru.agentlab.maia.task.test.integration

import java.util.HashMap
import java.util.List
import java.util.Map
import org.jbehave.core.annotations.Given
import org.jbehave.core.annotations.Then
import org.jbehave.core.annotations.When
import ru.agentlab.maia.task.ITask
import ru.agentlab.maia.task.ITask.State
import ru.agentlab.maia.task.ITaskScheduler
import ru.agentlab.maia.task.annotation.Action
import ru.agentlab.maia.task.parallel.ParallelTaskScheduler
import ru.agentlab.maia.task.primitive.AnnotatedAction
import ru.agentlab.maia.task.sequential.SequentialTaskScheduler

import static org.hamcrest.Matchers.*
import static org.junit.Assert.*

class Main {

	val Map<String, ITask> tasks = new HashMap
	
	val Map<String, DummyAction> impls = new HashMap

	@Given("a sequential schedulers $ids")
	def void givenSequentialScheduler(List<String> ids) {
		ids.forEach [
			tasks.put(it, new SequentialTaskScheduler)
		]
	}

	@Given("a parallel schedulers $ids")
	def void givenParallelScheduler(List<String> ids) {
		ids.forEach [
			tasks.put(it, new ParallelTaskScheduler)
		]
	}

	@Given("a primitive tasks $ids")
	def void givenPrimitiveTask(List<String> ids) {
		ids.forEach [
			val impl = new DummyAction
			val task = new AnnotatedAction(impl)
			impls.put(it, impl)
			tasks.put(it, task)
		]
	}

	@Given("task $id have subtasks $ids")
	def void givenTaskHaveSubtasks(String id, List<String> ids) {
		val scheduler = tasks.get(id) as ITaskScheduler
		ids.forEach [
			scheduler.addSubtask(tasks.get(it))
		]
	}

	@When("execute task $id by $times times")
	def void whenExecuteTaskByTimes(String id, int times) {
		val task = tasks.get(id)
		for (i : 0 ..< times) {
			task.execute
		}
	}

	@Then("task $execute have been executed")
	def void thenTaskExecuted(String id) {
		if (id != null && !id.empty) {
			assertThat(impls.get(id).count, equalTo(1))
		}
	}

	@Then("task $id have $state state")
	def void thenTaskHaveState(String id, String state) {
		assertThat(tasks.get(id).state, equalTo(State.valueOf(state)))
	}

}

class DummyAction {

	var protected int count = 0

	@Action
	def void action() {
		count++
	}
}
{'fraction_non_alphanumeric': 0.1171993911719939, 'fraction_numerical': 0.0008697542944118286, 'mean_word_length': 4.482717520858165, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '1379129', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1583, 'n_words': 359}