package hello;

import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.ContentResultMatchers;

import java.time.LocalTime;

/*
 * Created by mrc on 15/04/17.
 */


@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class HelloControllerTest {

    @Autowired
    private MockMvc mvc;

    @Test
    public void getHelloDefaultTest() throws Exception {
        mvc.perform(MockMvcRequestBuilders.get("/greeting?").accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(content().json("{\"id\":3,\"content\":\"Hello, World!\"}"));
    }

    @Test
    public void getHelloTest() throws Exception {

        mvc.perform(MockMvcRequestBuilders.get("/greeting?name=Jose").accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(content().json("{\"id\":2,\"content\":\"Hello, Jose!\"}"));
    }

    @Test
    public void getLandingTime() throws Exception {
        mvc.perform(MockMvcRequestBuilders.get("/timeGreeting").accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(getJsonContent());
    }

    private ResultMatcher getJsonContent() {
        if (LocalTime.now().isAfter(LocalTime.of(12, 0))) {
            return content().json("{\"id\":1,\"content\":\"Hello, night!\"}");
        } else {
            return  content().json("{\"id\":1,\"content\":\"Hello, morning!\"}");
        }
    }
}

@@ -1077,16 +1077,18 @@
 c mvc;%0A%0A
+//
     @Tes
@@ -1081,32 +1081,34 @@
 c;%0A%0A//    @Test%0A
+//
     public void 
@@ -1140,32 +1140,34 @@
 ows Exception %7B%0A
+//
         mvc.perf
@@ -1239,32 +1239,34 @@
 LICATION_JSON))%0A
+//
                 
@@ -1285,32 +1285,34 @@
 tatus().isOk())%0A
+//
                 
@@ -1375,39 +1375,45 @@
 , World!%5C%22%7D%22));%0A
+//
     %7D%0A
-%0A
+//%0A//
     @Test%0A    pu
@@ -1398,32 +1398,34 @@
 %0A//%0A//    @Test%0A
+//
     public void 
@@ -1458,17 +1458,21 @@
 ption %7B%0A
-%0A
+//%0A//
         
@@ -1561,32 +1561,34 @@
 LICATION_JSON))%0A
+//
                 
@@ -1607,32 +1607,34 @@
 tatus().isOk())%0A
+//
                 
@@ -1700,31 +1700,37 @@
 ose!%5C%22%7D%22));%0A
+//
     %7D%0A
-%0A
+//%0A//
     @Test%0A  
@@ -1727,16 +1727,18 @@
   @Test%0A
+//
     publ
@@ -1781,16 +1781,18 @@
 ption %7B%0A
+//
         
@@ -1883,16 +1883,18 @@
 _JSON))%0A
+//
         
@@ -1929,16 +1929,18 @@
 isOk())%0A
+//
         
@@ -1977,16 +1977,18 @@
 ent());%0A
+//
     %7D%0A%0A 

Prueba umbral de cobertura