Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ExtendWith(SpringExtension.class)
- @TestPropertySource("classpath:application-test.yml")
- public class RentalControllerTest {
- private MockMvc mockMvc;
- @Mock
- private RentalService rentalService;
- @Mock
- private RentalMapper rentalMapper;
- @BeforeEach
- public void setup() {
- mockMvc = MockMvcBuilders.standaloneSetup(new RentalController(rentalService, rentalMapper)).build();
- }
- @Test
- public void shouldReturnRentalByUsername() throws Exception {
- User user = new User(1L,"janek22", "janek", "janek2@wp.pl");
- Bike bike = new Bike("AB123", false);
- LocalDateTime dateTime = LocalDateTime.of(2019,5,24,1,0,0);
- Rental rental = new Rental(user, bike, dateTime , dateTime,
- "22.222", "33.444", "33.444", "33.444", "33.444" );
- given(rentalService.findByUsername(anyString())).willReturn(Collections.singletonList(rental));
- MvcResult mvcResult = mockMvc.perform(get("/rental/" + user.getUsername()))
- .andExpect(status().isOk())
- .andDo(print())
- .andReturn();
- String body = mvcResult.getResponse().getContentAsString();
- System.out.println("Test Body" + body);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement