public void shouldNotExecuteInHeaderMode() throws Exception {
    // given
    ModelAndView modelAndView = new ModelAndView("test-view");
    interceptor.setMode(RepInterceptor.RepMode.HEADER);

    // when
    interceptor.postHandle(mockRequest, mockResponse, mockHandlerMethod, modelAndView);

    // then
    assertTrue("Model should be empty", modelAndView.getModel().isEmpty());
    verifyZeroInteractions(mockMetaFormatter, mockCombinatorStrategy);
  }
  @Test(expectedExceptions = IllegalArgumentException.class)
  public void shouldThrowExceptionIfHandlerIsNotHandlerMethod() throws Exception {
    // given

    // when
    interceptor.preHandle(mockRequest, mockResponse, new Object());

    // then
  }
  public void shouldNotExecuteIfModelAndViewIsNull() throws Exception {
    // given

    // when
    interceptor.postHandle(mockRequest, mockResponse, mockHandlerMethod, null);

    // then
    verifyZeroInteractions(mockMetaFormatter, mockCombinatorStrategy);
  }
  public void shouldWriteAttributeNotHeadersInMetaMode() throws Exception {
    // given
    interceptor.setMode(RepInterceptor.RepMode.META);
    when(mockCombinatorStrategy.combine(testMethod))
        .thenReturn(Lists.newArrayList(new RobotInfo("ua")));

    // when
    final boolean result = interceptor.preHandle(mockRequest, mockResponse, mockHandlerMethod);

    // then
    assertTrue("Interceptor should always return true", result);

    final Object attribute = mockRequest.getAttribute(RepInterceptor.ROBOTS_REQUEST_ATTRIBUTE);
    assertNotNull("Request attribute should be set", attribute);

    final List<String> headers = mockResponse.getHeaders(RepInterceptor.ROBOTS_HEADER_NAME);
    assertTrue("No headers should be written", headers.isEmpty());

    verify(mockCombinatorStrategy).combine(testMethod);
    verifyZeroInteractions(mockHeaderFormatter);
  }
  public void shouldWriteAttributeAndHeadersInHeaderMode() throws Exception {
    // given
    interceptor.setMode(RepInterceptor.RepMode.HEADER);
    when(mockCombinatorStrategy.combine(testMethod))
        .thenReturn(Lists.newArrayList(new RobotInfo("ua")));

    // when
    final boolean result = interceptor.preHandle(mockRequest, mockResponse, mockHandlerMethod);

    // then
    assertTrue("Interceptor should always return true", result);

    final Object attribute = mockRequest.getAttribute(RepInterceptor.ROBOTS_REQUEST_ATTRIBUTE);
    assertNotNull("Request attribute should be set", attribute);

    final List<String> headers = mockResponse.getHeaders(RepInterceptor.ROBOTS_HEADER_NAME);
    assertEquals(1, headers.size());
    assertEquals("header-value", headers.get(0));

    verify(mockCombinatorStrategy).combine(testMethod);
    verify(mockHeaderFormatter).format(any(RobotInfo.class));
  }
  public void shouldImmediatelyReturnIfNoRobotInfoFound() throws Exception {
    // given
    when(mockCombinatorStrategy.combine(testMethod)).thenReturn(Collections.<RobotInfo>emptyList());

    // when
    final boolean result = interceptor.preHandle(mockRequest, mockResponse, mockHandlerMethod);

    // then
    assertTrue("Interceptor should always return true", result);
    assertNull(
        "Request attribute should not be set",
        mockRequest.getAttribute(RepInterceptor.ROBOTS_REQUEST_ATTRIBUTE));
    assertFalse("No headers should be added", mockRequest.getHeaderNames().hasMoreElements());

    verify(mockCombinatorStrategy).combine(testMethod);
  }
  public void shouldAddModelDataInMetaMode() throws Exception {
    // given
    ModelAndView modelAndView = new ModelAndView("test-view");
    mockRequest.setAttribute(
        RepInterceptor.ROBOTS_REQUEST_ATTRIBUTE, Lists.newArrayList(new RobotInfo("ua")));

    // when
    interceptor.postHandle(mockRequest, mockResponse, mockHandlerMethod, modelAndView);

    // then
    List<MetaTag> metaTags =
        ModelAndViewAssert.assertAndReturnModelAttributeOfType(
            modelAndView, RepInterceptor.ROBOTS_META_TAGS_ATTRIBUTE_NAME, List.class);
    assertEquals(1, metaTags.size());
    assertEquals("meta-name", metaTags.get(0).getName());
    assertEquals("meta-content", metaTags.get(0).getContent());
  }