SHARE
TWEET

Untitled

a guest Jan 24th, 2020 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.springframework.transaction.annotation.Transactional;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import static org.mockito.Mockito.when;
  6. import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
  7. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
  8.  
  9. @RunWith(SpringRunner.class)
  10. @AutoConfigureMockMvc
  11. @SpringBootTest
  12. public class CompanyControllerUnitTest {
  13.  
  14.     @Autowired
  15.     private MockMvc mockMvc;
  16.  
  17.     @MockBean
  18.     private CompanyService service;
  19.  
  20.     @Test
  21.     @Transactional
  22.     @WithMockUser(username = "user", authorities = "COMPANY_LIST_READ")
  23.     public void getAllCompaniesShouldReturnCompanies() throws Exception {
  24.         when(service.getAllCompanies()).thenReturn(new ArrayList<>());
  25.         this.mockMvc.perform(get("/secured/structure/company")).andExpect(status().isOk());
  26. //                .andExpect(content().string(containsString("Hello, Mock")));
  27.     }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top