package com.braintree.fraud.symptom.impl;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.core.model.c2l.CurrencyModel;
import de.hybris.platform.core.model.order.AbstractOrderModel;
import de.hybris.platform.fraud.impl.FraudServiceResponse;
import de.hybris.platform.fraud.impl.FraudSymptom;
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.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.any;

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

    private Double orderTotalPrice = new Double(19.99);
    @Mock
    private FraudServiceResponse fraudResponse;
    @Mock
    private AbstractOrderModel order;
    @Mock
    private CurrencyModel currencyModel;

    @InjectMocks
    private BraintreeOrderThresholdSymptom unit;

    @Test
    public void shouldRecognizeSymptom() {
        final Double conversion = new Double(0.01);

        when(order.getTotalPrice()).thenReturn(orderTotalPrice);
        when(order.getCurrency()).thenReturn(currencyModel);
        when(currencyModel.getConversion()).thenReturn(conversion);

        unit.recognizeSymptom(fraudResponse, order);

        verify(order, times(2)).getTotalPrice();
        verify(order).getCurrency();
        verify(currencyModel).getConversion();
        verify(fraudResponse).addSymptom(any(FraudSymptom.class));
    }

    @Test
    public void shouldRecognizeSymptomWithFalse() {
        final Double conversion = new Double(1.99);

        when(order.getTotalPrice()).thenReturn(orderTotalPrice);
        when(order.getCurrency()).thenReturn(currencyModel);
        when(currencyModel.getConversion()).thenReturn(conversion);

        unit.recognizeSymptom(fraudResponse, order);

        verify(order).getTotalPrice();
        verify(order).getCurrency();
        verify(currencyModel).getConversion();
        verify(fraudResponse).addSymptom(any(FraudSymptom.class));
    }

}
