title: Test a controller with Junit?
body: <p>I had some trouble setting up unit test with my spring boot application. My main issue is with the "model" object that's needed in my controller, but I can't find a way to recreate it in my test, which is required to use my function. </p>
  
  <p>here are the function I want to test</p>
  
  <pre><code>@Controller
  public class AjoutAbscenceControler {
  
    @Autowired
    private AbsenceRepository absenceRepository;
  
    @RequestMapping(value = { "/addAbsence" }, method = RequestMethod.GET)
    public String showAddAbsencePage(Model model) {
  
      Absence absence = new Absence();
      model.addAttribute("Absence", absence);
  
      return "addAbsence";
    }
  
    @RequestMapping(value = { "/addingAbsence" }, method = RequestMethod.POST)
    public String saveAbsence(Model model, @ModelAttribute("absence") Absence absence) {
  
      if (absence.getName() != null &amp;&amp; absence.getName().length() &gt; 0) {
        absenceRepository.save(absence);
      }
      return "redirect:/userList";
    }
  
  }
  </code></pre>
  
  <p>I did try something like that</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class AjoutAbscenceControlerTest {
  
    @Mock
    VacationRepository vacationRepository;
    @Mock
    CategoryRepository categoryRepository;
    @InjectMocks
    AjoutAbscenceControler controler;
    public MockMvc mockMvc;
    @Before
    public  void  setUp() throws Exception{
      mockMvc = MockMvcBuilders.standaloneSetup(controler).build();
    }
    @Test
    public void showAddAbsencePagetest() {
    AjoutAbscenceControler ajoutAbscenceControler =new AjoutAbscenceControler();
  
      assertEquals("addAbsence",ajoutAbscenceControler.showAddAbsencePage(controler));
    }
  }
  </code></pre>
  
  <p>but I don't find any way to create a <code>springfarmwork.ui.Model</code></p>