package eu.ydp.empiria.player.client.module.feedback.text;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.xml.client.Element;
import com.google.gwtmockito.GwtMockitoTestRunner;
import eu.ydp.empiria.player.client.controller.feedback.processor.TextActionProcessor;
import eu.ydp.empiria.player.client.module.feedback.text.blend.FeedbackBlend;
import eu.ydp.empiria.player.client.module.mathjax.common.MathJaxNative;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

@RunWith(GwtMockitoTestRunner.class)
public class TextActionProcessorTest {

    @InjectMocks
    private TextActionProcessor testObj;
    @Mock
    private TextFeedback feedbackPresenter;
    @Mock
    private MathJaxNative mathJaxNative;
    @Mock
    private FeedbackBlend feedbackBlend;
    @Captor
    private ArgumentCaptor<ClickHandler> clickHandlerCaptor;

    @Test
    public void shouldShowFeedback() {
        //given
        Element element = mock(Element.class);
        testObj.initModule(element);
        verify(feedbackPresenter).addShowButtonClickHandler(clickHandlerCaptor.capture());
        ClickHandler clickHandler = clickHandlerCaptor.getValue();
        ClickEvent clickEvent = mock(ClickEvent.class);
        //when
        clickHandler.onClick(clickEvent);
        //then
        verify(feedbackPresenter).showFeedback();
        verify(feedbackBlend).show(feedbackPresenter);
    }

    @Test
    public void shouldHideFeedback() {
        //given
        Element element = mock(Element.class);
        testObj.initModule(element);
        verify(feedbackPresenter).addCloseButtonClickHandler(clickHandlerCaptor.capture());
        ClickHandler clickHandler = clickHandlerCaptor.getValue();
        ClickEvent clickEvent = mock(ClickEvent.class);
        //when
        clickHandler.onClick(clickEvent);
        //then
        verify(feedbackPresenter).hideFeedback();
        verify(feedbackBlend).hide();
    }

}

@@ -704,16 +704,57 @@
 o.mock;%0A
+import static org.mockito.Mockito.times;%0A
 import s
@@ -2056,32 +2056,33 @@
 ckEvent.class);%0A
+%0A
         //when%0A 
@@ -2114,32 +2114,33 @@
 ck(clickEvent);%0A
+%0A
         //then%0A 
@@ -2170,16 +2170,26 @@
 resenter
+, times(2)
 ).hideFe
@@ -2226,16 +2226,26 @@
 ackBlend
+, times(2)
 ).hide()
@@ -2252,11 +2252,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

test fix