@@ -0,0 +1,3039 @@
+package pl.mycalories.controller;%0D%0A%0D%0Aimport org.junit.Before;%0D%0Aimport org.junit.Test;%0D%0Aimport org.junit.runner.RunWith;%0D%0Aimport org.springframework.beans.factory.annotation.Autowired;%0D%0Aimport org.springframework.boot.test.context.SpringBootTest;%0D%0Aimport org.springframework.boot.test.mock.mockito.MockBean;%0D%0Aimport org.springframework.http.MediaType;%0D%0Aimport org.springframework.test.context.junit4.SpringRunner;%0D%0Aimport org.springframework.test.context.web.WebAppConfiguration;%0D%0Aimport org.springframework.test.web.servlet.MockMvc;%0D%0Aimport org.springframework.web.context.WebApplicationContext;%0D%0Aimport pl.mycalories.CalorieeCApplication;%0D%0Aimport pl.mycalories.model.Category;%0D%0Aimport pl.mycalories.service.CategoryService;%0D%0A%0D%0Aimport static org.mockito.Matchers.any;%0D%0Aimport static org.mockito.Mockito.when;%0D%0Aimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;%0D%0Aimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;%0D%0Aimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;%0D%0Aimport static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;%0D%0A%0D%0A@RunWith(SpringRunner.class)%0D%0A@SpringBootTest(classes = CalorieeCApplication.class)%0D%0A@WebAppConfiguration%0D%0Apublic class CategoryControllerTest %7B%0D%0A%0D%0A    private MockMvc mockMvc;%0D%0A%0D%0A    @Autowired%0D%0A    private WebApplicationContext webApplicationContext;%0D%0A%0D%0A    @MockBean%0D%0A    private CategoryService categoryServiceMock;%0D%0A%0D%0A    @Before%0D%0A    public void setUp() %7B%0D%0A        this.mockMvc = webAppContextSetup(webApplicationContext).build();%0D%0A    %7D%0D%0A%0D%0A    @Test%0D%0A    public void should_CreateAccount_When_ValidRequest() throws Exception %7B%0D%0A        Category category = new Category();%0D%0A        category.setId(123L);%0D%0A        category.setName(%22Category Test%22);%0D%0A        when(categoryServiceMock.save(any(Category.class))).thenReturn(category);%0D%0A%0D%0A        mockMvc.perform(post(%22/category%22)%0D%0A                .contentType(MediaType.APPLICATION_JSON)%0D%0A                .content(%22%7B %5C%22name%5C%22: %5C%22Category Test%5C%22 %7D%22)%0D%0A                .accept(MediaType.APPLICATION_JSON))%0D%0A                .andExpect(status().isCreated())%0D%0A                .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))%0D%0A                .andExpect(jsonPath(%22$.id%22).value(%22123%22))%0D%0A                .andExpect(jsonPath(%22$.name%22).value(%22Category Test%22));%0D%0A    %7D%0D%0A%0D%0A    @Test%0D%0A    public void should_GetCategory_When_ValidRequest() throws Exception %7B%0D%0A        Category category = new Category();%0D%0A        category.setId(1L);%0D%0A        category.setName(%22Category Test%22);%0D%0A        when(categoryServiceMock.findById(1L)).thenReturn(category);%0D%0A%0D%0A        mockMvc.perform(get(%22/category/1%22)%0D%0A                .accept(MediaType.APPLICATION_JSON))%0D%0A                .andExpect(status().isOk())%0D%0A                .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))%0D%0A                .andExpect(jsonPath(%22$.id%22).value(1))%0D%0A                .andExpect(jsonPath(%22$.name%22).value(%22Category Test%22));%0D%0A    %7D%0D%0A%0D%0A%7D%0D%0A

add integration tests for category controller