コード例 #1
0
  @Test
  public void testSpannerNotFound() throws Exception {

    // Stub behaviours = spanner not found
    when(spannersService.findOne(SPANNER_ID)).thenReturn(null);

    // Request the page for the given spanner id - this should generate exception
    try {
      controller.displayDetail(SPANNER_ID);
      fail("Expected: SpannerNotFoundException");
    } catch (SpannerNotFoundException notFoundEx) {
      assertEquals("Exception spanner id", SPANNER_ID, notFoundEx.getSpannerId());
    }
  }
コード例 #2
0
  @Test
  public void testDisplayPage() throws Exception {

    // Stub behaviours - dao returns spanner detail
    when(spannersService.findOne(SPANNER_ID)).thenReturn(SPANNER);

    // Request the page for the given spanner id
    ModelAndView response = controller.displayDetail(SPANNER_ID);
    assertNotNull("no response", response);

    // Assert that we forward to correct view
    assertEquals(VIEW_DETAIL_SPANNER, response.getViewName());

    // Assert that spanner detail is available to view
    Spanner spannerInModel = (Spanner) response.getModelMap().get(MODEL_SPANNER);
    assertSpannerEquals(SPANNER, spannerInModel);
  }