ConfigurationFormController { @RequestMapping(method = GET) public ModelAndView setUpForm(ModelAndView modelAndView) throws Exception { modelAndView.getModel().put("addedRepositories", application.getRepositoryNames()); modelAndView.getModel().put("command", new ConfigCommand()); modelAndView.setViewName("config/configForm"); return modelAndView; } @Autowired  ConfigurationFormController(final Application application); @Autowired void setValidator(ConfigCommandValidator validator); @InitBinder("command") void bindValidator(WebDataBinder binder); @RequestMapping(method = GET) ModelAndView setUpForm(ModelAndView modelAndView); @RequestMapping(method = POST) String onFormSubmit(@ModelAttribute("command") @Valid ConfigCommand command, BindingResult result, Model model);  }
@Test public void setUpForm() throws Exception { Application application = mock(Application.class); HashSet<RepositoryName> repositoryNames = new HashSet<RepositoryName>(); repositoryNames.add(new RepositoryName("sventon")); repositoryNames.add(new RepositoryName("nordpolen")); when(application.getRepositoryNames()).thenReturn(repositoryNames); ConfigurationFormController controller = new ConfigurationFormController(application); ModelAndView modelAndView = controller.setUpForm(new ModelAndView()); Map expectedModel = new HashMap(); expectedModel.put("addedRepositories", repositoryNames); expectedModel.put("command", new ConfigCommand()); assertModelAttributeValues(modelAndView, expectedModel); assertViewName(modelAndView, CONFIG_FORM_VIEW_NAME); }
@Test public void setUpFormWhereThereAreNowReposConfigured() throws Exception { Application application = mock(Application.class); HashSet<RepositoryName> emptyRepoNames = new HashSet<RepositoryName>(); when(application.getRepositoryNames()).thenReturn(emptyRepoNames); ConfigurationFormController controller = new ConfigurationFormController(application); ModelAndView modelAndView = controller.setUpForm(new ModelAndView()); Map expectedModel = new HashMap(); expectedModel.put("addedRepositories", emptyRepoNames); expectedModel.put("command", new ConfigCommand()); assertModelAttributeValues(modelAndView, expectedModel); assertViewName(modelAndView, CONFIG_FORM_VIEW_NAME); }