package io.zerodi.server.handler;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.MockitoAnnotations.initMocks;

import java.util.Date;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Spy;

import io.zerodi.environment.service.CurrentClock;
import io.zerodi.ping.PingMessage;

public class PingHandlerTest {

    @InjectMocks
    private PingHandler handler;

    @Spy
    private CurrentClock currentClock;

    private PingMessage  pingMessage;

    @Before
    public void setUp() throws Exception {
        initMocks(this);

        pingMessage = new PingMessage("test", new Date());
    }

    @Test
    public void itShouldProduceResponseToPingMessage() throws Exception {
        // given
        Date responseDate = new Date();

        // when
        doReturn(responseDate).when(currentClock).getCurrentDate();
        PingMessage response = handler.handleMessage(pingMessage);

        // then
        assertThat(response).isNotNull();
        assertThat(response.getPayload()).isEqualTo("response to: test");
        assertThat(response.getDate()).isEqualTo(responseDate);
    }
}

@@ -133,64 +133,8 @@
 urn;
-%0Aimport static org.mockito.MockitoAnnotations.initMocks;
 %0A%0Aim
@@ -172,22 +172,20 @@
 g.junit.
-Before
+Test
 ;%0Aimport
@@ -187,36 +187,46 @@
 mport org.junit.
-Test
+runner.RunWith
 ;%0Aimport org.moc
@@ -266,16 +266,63 @@
 ito.Spy;
+%0Aimport org.mockito.runners.MockitoJUnitRunner;
 %0A%0Aimport
@@ -402,16 +402,51 @@
 ssage;%0A%0A
+@RunWith(MockitoJUnitRunner.class)%0A
 public c
@@ -597,112 +597,8 @@
 age 
- pingMessage;%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        initMocks(this);%0A%0A        
 ping
@@ -643,22 +643,16 @@
 Date());
-%0A    %7D
 %0A%0A    @T

simplifying the test