/**
  * Tests the rendering of the form that edits a Reporter
  *
  * @throws java.lang.Exception
  */
 @Test
 public void testEditReporter() throws Exception {
   Reporter unedited = new Reporter(1L, "5 Reliance Cresc", "0423111234", "*****@*****.**");
   when(reporterServiceMock.find(1L)).thenReturn(unedited);
   mockMvc
       .perform(get("/reporters/1/edit"))
       .andExpect(status().isOk())
       .andExpect(view().name("/reporter/reporterForm"))
       .andExpect(model().attributeExists("reporter"))
       .andExpect(model().attribute("reporter", unedited));
 }
 /**
  * Tests the submission of the form that edits a Reporter
  *
  * @throws Exception
  */
 @Test
 public void testSubmitEditReporter() throws Exception {
   Reporter edited = new Reporter(1L, "5 Reliance Cresc", "0423222234", "*****@*****.**");
   when(reporterServiceMock.save(edited)).thenReturn(edited);
   mockMvc
       .perform(
           post("/reporters/1/edit")
               .param("address", "5 Reliance Cresc")
               .param("phoneNumber", "0423222234")
               .param("emailAddress", "*****@*****.**"))
       .andExpect(status().isFound())
       .andExpect(redirectedUrl("/reporters/1"));
   verify(reporterServiceMock, atLeastOnce()).save(edited);
 }
  /**
   * Test the submission of a new registered user
   *
   * @throws Exception
   */
  @Test
  public void testProcessReporterRegistration() throws Exception {
    Reporter unsaved = new Reporter("5 Reliance Cresc", "0423111234", "*****@*****.**");
    Reporter saved = new Reporter(1L, "5 Reliance Cresc", "0423111234", "*****@*****.**");

    when(reporterServiceMock.save(unsaved)).thenReturn(saved);
    mockMvc
        .perform(
            post("/reporters/report")
                .param("address", "5 Reliance Cresc")
                .param("phoneNumber", "0423111234")
                .param("emailAddress", "*****@*****.**"))
        .andExpect(status().isFound())
        .andExpect(redirectedUrl("/reporters/1"));
    verify(reporterServiceMock, atLeastOnce()).save(unsaved);
  }
  @Test
  public void testShowReporterById() throws Exception {
    List<Reporter> expectedResult = new ArrayList<Reporter>();
    Reporter reporter = new Reporter("5 Reliance Cresc", "0423111234", "*****@*****.**");
    expectedResult.add(reporter);

    when(reporterServiceMock.findById(1L)).thenReturn(expectedResult);
    mockMvc
        .perform(get("/reporters?search_Type=id&input=1"))
        .andExpect(status().isOk())
        .andExpect(view().name("/reporter/reporters"))
        .andExpect(model().attributeExists("search"))
        .andExpect(model().attributeExists("reporterList"))
        .andExpect(model().attribute("reporterList", hasSize(1)))
        .andExpect(model().attribute("reporterList", hasItems(expectedResult.toArray())));
  }
  /**
   * Tests the GET method for a Reporter
   *
   * @throws Exception
   */
  @Test
  public void testshowReporterProfile() throws Exception {
    // test data
    Reporter reporter = new Reporter(1L, "5 Reliance Cresc", "0423111234", "*****@*****.**");
    List<Item> reporterItems = createItemListForReporter(3);

    when(reporterServiceMock.find(1L)).thenReturn(reporter);
    when(itemServiceMock.findByReporter(reporter)).thenReturn(reporterItems);
    mockMvc
        .perform(get("/reporters/1"))
        .andExpect(status().isOk())
        .andExpect(view().name("/reporter/reporterProfile"))
        .andExpect(model().attributeExists("reporter"))
        .andExpect(model().attributeExists("itemList"))
        .andExpect(model().attribute("reporter", reporter))
        .andExpect(model().attribute("itemList", hasSize(3)))
        .andExpect(model().attribute("itemList", hasItems(reporterItems.toArray())));
  }