package com.braintree.commands.factory;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.payment.commands.Command;
import de.hybris.platform.payment.commands.factory.CommandNotSupportedException;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;


@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class DefaultBrainTreeCommandFactoryTest {

    private static final String PAYMENT_PROVIDER = "BRAINTREE";

    @Mock
    private Command mockCommand;

    @InjectMocks
    private DefaultBrainTreeCommandFactory commandFactory;

    @Test
    public void shouldReturnSuccessWhenCreateCommand() throws CommandNotSupportedException {
        Map<Class<Command>, Command> commands = Map.of(Command.class, mockCommand);
        commandFactory.setGraphQLCommands(commands);

        Command result = commandFactory.createCommand(Command.class);

        assertNotNull(result);
        assertEquals(mockCommand, result);
    }

    @Test(expected = CommandNotSupportedException.class)
    public void shouldFailWhenCommandNotImplemented() throws CommandNotSupportedException {
        Map<Class<Command>, Command> commands = new HashMap<>();
        commandFactory.setGraphQLCommands(commands);

        commandFactory.createCommand(Command.class);
    }

    @Test
    public void shouldGetPaymentProvider() {
        commandFactory.setPaymentProvider(PAYMENT_PROVIDER);

        String result = commandFactory.getPaymentProvider();

        assertEquals(PAYMENT_PROVIDER, result);
    }

    @Test
    public void shouldSetPaymentProvider() {
        commandFactory.setPaymentProvider(PAYMENT_PROVIDER);

        assertEquals(PAYMENT_PROVIDER, commandFactory.getPaymentProvider());
    }
}
