package com.github.solairerove.woodstock;

import com.github.solairerove.woodstock.domain.Unit;
import com.github.solairerove.woodstock.repository.UnitRepository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.context.WebApplicationContext;

import static com.github.solairerove.woodstock.controller.ControllerApi.UNIT_API;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.request;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;

@SpringBootTest
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class UnitControllerTest {

    private MockMvc mvc;

    @Autowired
    private UnitRepository repository;

    @Autowired
    private WebApplicationContext context;

    @Before
    public void setup() throws Exception {
        this.mvc = webAppContextSetup(context).build();
    }

    @Test
    public void getAllPostsTest() throws Exception {
        repository.deleteAll();
        Unit unit = new Unit("Label", "URL to avatar", "Short MD description");
        repository.save(unit);

        mvc.perform(request(HttpMethod.GET, UNIT_API)
                .accept(APPLICATION_JSON_UTF8_VALUE)
                .contentType(APPLICATION_JSON_UTF8_VALUE))
                .andExpect(status().isOk())
                .andExpect(MockMvcResultMatchers.jsonPath("$", hasSize(1)))
                .andExpect(jsonPath("$.[0].label", is("Label")))
                .andExpect(jsonPath("$.[0].avatar", is("URL to avatar")));
    }
}

@@ -365,101 +365,8 @@
 st;%0A
-import org.springframework.http.HttpMethod;%0Aimport org.springframework.stereotype.Component;%0A
 impo
@@ -433,16 +433,16 @@
 Runner;%0A
+
 import o
@@ -555,82 +555,8 @@
 vc;%0A
-import org.springframework.test.web.servlet.result.MockMvcResultMatchers;%0A
 impo
@@ -781,16 +781,71 @@
 ers.is;%0A
+import static org.springframework.http.HttpMethod.GET;%0A
 import s
@@ -1089,104 +1089,9 @@
 ers.
-jsonPath;%0Aimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
+*
 ;%0Aim
@@ -1585,14 +1585,666 @@
  get
-AllPos
+UnitTest() throws Exception %7B%0A        repository.deleteAll();%0A        Unit unit = new Unit(%22Label%22, %22URL to avatar%22, %22Short MD description%22);%0A        String id = repository.save(unit).getId();%0A%0A        mvc.perform(request(GET, UNIT_API + %22/%22 + id)%0A                .accept(APPLICATION_JSON_UTF8_VALUE)%0A                .contentType(APPLICATION_JSON_UTF8_VALUE))%0A                .andExpect(status().isOk())%0A                .andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE))%0A                .andExpect(jsonPath(%22$.label%22, is(%22Label%22)))%0A                .andExpect(jsonPath(%22$.avatar%22, is(%22URL to avatar%22)));;%0A    %7D%0A%0A    @Test%0A    public void getAllUni
 tsTe
@@ -2439,27 +2439,16 @@
 request(
-HttpMethod.
 GET, UNI
@@ -2637,38 +2637,95 @@
 dExpect(
-MockMvcResultMatchers.
+content().contentType(APPLICATION_JSON_UTF8_VALUE))%0A                .andExpect(
 jsonPath

Write one more unit controller test: - optimize imports - add one more content type expect