package click.kamil.springstatemachineexporter.analysis.service;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class FunctionalInterfaceTypesTest {

    @Test
    void shouldRecognizeSupplierParameter() {
        assertThat(FunctionalInterfaceTypes.isFunctionalInterface("java.util.function.Supplier"))
                .isTrue();
    }

    @Test
    void shouldRecognizeConsumerSamMethod() {
        assertThat(FunctionalInterfaceTypes.isFunctionalSamMethod("java.util.function.Consumer.accept"))
                .isTrue();
    }

    @Test
    void shouldRecognizeRunnableSamMethod() {
        assertThat(FunctionalInterfaceTypes.isFunctionalSamMethod("java.lang.Runnable.run"))
                .isTrue();
    }

    @Test
    void shouldRejectMapGetAsSamMethod() {
        assertThat(FunctionalInterfaceTypes.isFunctionalSamMethod("java.util.Map.get"))
                .isFalse();
    }

    @Test
    void shouldAcceptLambdaIntoSupplierParameter() {
        assertThat(FunctionalInterfaceTypes.isProvablyResolvedCallSiteArgument(
                "() -> OrderEvent.CANCEL", "java.util.function.Supplier"))
                .isTrue();
    }

    @Test
    void shouldRejectNonFunctionalParameter() {
        assertThat(FunctionalInterfaceTypes.isProvablyResolvedCallSiteArgument(
                "OrderEvent.CANCEL", "com.example.OrderEvent"))
                .isFalse();
    }
}
