Skip to content

Commit

Permalink
Add UserControllerTest skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
MisaghM committed Nov 25, 2023
1 parent 9dcc487 commit 1c15d55
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Baloot1/src/test/java/controllers/UserControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package controllers;

import application.BalootApplication;
import model.User;
import org.junit.jupiter.api.*;
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.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import service.Baloot;

import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@AutoConfigureMockMvc
@SpringBootTest(classes = BalootApplication.class)
public class UserControllerTest {
@MockBean
private Baloot baloot;
@Autowired
private UserController userController;
@Autowired
private MockMvc mockMvc;

@BeforeEach
public void setUp() {
userController.setBaloot(baloot);
}

@Test
@DisplayName("Test")
public void test() throws Exception {
User user = new User("username", "password", "[email protected]", "2023-01-01", "address");
when(baloot.getUserById("username")).thenReturn(user);
mockMvc.perform(get("/users/{id}", "username")).andExpect(status().isOk());
}
}

0 comments on commit 1c15d55

Please sign in to comment.