package ru.kovbasa.config;

import com.google.inject.Injector;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstanceFactory;
import org.junit.jupiter.api.extension.TestInstanceFactoryContext;

public class GuiceExtension implements TestInstanceFactory {

    @Override
    public Object createTestInstance(
            TestInstanceFactoryContext factoryContext,
            ExtensionContext extensionContext
    ) {
        Class<?> testClass = factoryContext.getTestClass();
        Injector injector = InjectorProvider.getInjector();
        return injector.getInstance(testClass);
    }
}
