<commit_before>package ru.agentlab.maia.memory.injector.test.func

import java.util.Random
import java.util.UUID
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.Spy
import org.mockito.runners.MockitoJUnitRunner
import ru.agentlab.maia.memory.IMaiaContext
import ru.agentlab.maia.memory.injector.MaiaContextInjector
import ru.agentlab.maia.memory.injector.test.func.doubles.FakeService_constructorsEmpty
import ru.agentlab.maia.memory.injector.test.func.doubles.FakeService_constructorsMany

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

@RunWith(MockitoJUnitRunner)
class ContextInjector_make_FunctionalTests {

	val static random = new Random

	val static INT_VALUE = random.nextInt

	val static STRING_VALUE = UUID.randomUUID.toString

	@Mock
	IMaiaContext context

	@Spy @InjectMocks
	MaiaContextInjector injector

	@Test
	def void shouldCallEmptyConstructor() {
		val service = injector.make(FakeService_constructorsEmpty)

		assertThat(service.constructorCalled, equalTo(true))
	}

	@Test
	def void shouldCreateServiceWithEmptyConstructor() {
		val service = injector.make(FakeService_constructorsEmpty)

		assertThat(service, notNullValue(FakeService_constructorsEmpty))
	}

	@Test
	def void shouldCallBiggestConstructor() {
		context.addService(STRING_VALUE)
		context.addService(INT_VALUE)

		assertThat(context.getService(Integer), equalTo(INT_VALUE))
//		assertThat(injector.context, equalTo(context))
		val service = injector.make(FakeService_constructorsMany)

		assertThat(service.firstConstructorCalled, equalTo(false))
		assertThat(service.secondConstructorCalled, equalTo(true))
	}

	@Test
	def void shouldInjectToBiggestConstructor() {
		context.addService(STRING_VALUE)
		context.addService(INT_VALUE)

		val service = injector.make(FakeService_constructorsMany)

		assertThat(service.stringValue, equalTo(STRING_VALUE))
		assertThat(service.intValue, equalTo(INT_VALUE))
	}

	@Test
	def void shouldCreateServiceByBiggestConstructor() {
		context.addService(STRING_VALUE)
		context.addService(INT_VALUE)

		val service = injector.make(FakeService_constructorsMany)

		assertThat(service, notNullValue(FakeService_constructorsMany))
	}

	@Test
	def void shouldCallRelevantConstructor() {
		context.addService(STRING_VALUE)

		val service = injector.make(FakeService_constructorsMany)

		assertThat(service.firstConstructorCalled, equalTo(true))
		assertThat(service.secondConstructorCalled, equalTo(false))
	}

	@Test
	def void shouldCreateServiceByRelevantConstructor() {
		context.addService(STRING_VALUE)

		val service = injector.make(FakeService_constructorsMany)

		assertThat(service, notNullValue(FakeService_constructorsMany))
	}

	def private void addService(IMaiaContext ctx, Object service) {
		when(ctx.getService(service.class)).thenReturn(service)
		when(ctx.getService(service.class.name)).thenReturn(service)
	}

}<commit_msg>* fix broken test<commit_after>package ru.agentlab.maia.memory.injector.test.func

import java.util.Random
import java.util.UUID
import org.junit.Before
import org.junit.Test
import ru.agentlab.maia.memory.IMaiaContext
import ru.agentlab.maia.memory.exception.MaiaContextKeyNotFound
import ru.agentlab.maia.memory.injector.MaiaContextInjector
import ru.agentlab.maia.memory.injector.test.func.doubles.FakeService_constructorsEmpty
import ru.agentlab.maia.memory.injector.test.func.doubles.FakeService_constructorsMany

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

class ContextInjector_make_FunctionalTests {

	val static random = new Random

	val static INT_VALUE = random.nextInt

	val static STRING_VALUE = UUID.randomUUID.toString

	IMaiaContext context = mock(IMaiaContext)

	MaiaContextInjector injector = new MaiaContextInjector(context)

	@Before
	def void before() {
		reset(context)
	}

	@Test
	def void shouldCallEmptyConstructor() {
		val service = injector.make(FakeService_constructorsEmpty)

		assertThat(service.constructorCalled, equalTo(true))
	}

	@Test
	def void shouldCreateServiceWithEmptyConstructor() {
		val service = injector.make(FakeService_constructorsEmpty)

		assertThat(service, notNullValue(FakeService_constructorsEmpty))
	}

	@Test
	def void shouldCallBiggestConstructor() {
		when(context.getService(String)).thenReturn(STRING_VALUE)
		when(context.getService(Integer)).thenReturn(INT_VALUE)

		val service = injector.make(FakeService_constructorsMany)

		assertThat(service.firstConstructorCalled, equalTo(false))
		assertThat(service.secondConstructorCalled, equalTo(true))
	}

	@Test
	def void shouldInjectToBiggestConstructor() {
		when(context.getService(String)).thenReturn(STRING_VALUE)
		when(context.getService(Integer)).thenReturn(INT_VALUE)

		val service = injector.make(FakeService_constructorsMany)

		assertThat(service.stringValue, equalTo(STRING_VALUE))
		assertThat(service.intValue, equalTo(INT_VALUE))
	}

	@Test
	def void shouldCreateServiceByBiggestConstructor() {
		when(context.getService(String)).thenReturn(STRING_VALUE)
		when(context.getService(Integer)).thenReturn(INT_VALUE)

		val service = injector.make(FakeService_constructorsMany)

		assertThat(service, notNullValue(FakeService_constructorsMany))
	}

	@Test
	def void shouldCallRelevantConstructor() {
		when(context.getService(String)).thenReturn(STRING_VALUE)
		when(context.getService(Integer)).thenThrow(MaiaContextKeyNotFound)

		val service = injector.make(FakeService_constructorsMany)

		assertThat(service.firstConstructorCalled, equalTo(true))
		assertThat(service.secondConstructorCalled, equalTo(false))
	}

	@Test
	def void shouldCreateServiceByRelevantConstructor() {
		when(context.getService(String)).thenReturn(STRING_VALUE)
		when(context.getService(Integer)).thenThrow(MaiaContextKeyNotFound)

		val service = injector.make(FakeService_constructorsMany)

		assertThat(service, notNullValue(FakeService_constructorsMany))
	}

}
{'fraction_non_alphanumeric': 0.09001989389920424, 'fraction_numerical': 0.0, 'mean_word_length': 6.95910290237467, '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': '266195', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1848, 'n_words': 286}