Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,15 +16,13 @@
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -41,6 +39,8 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||
import org.springframework.web.servlet.FlashMap;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RequestMappingHandlerAdapter}.
|
||||
*
|
||||
@@ -66,6 +66,7 @@ public class RequestMappingHandlerAdapterTests {
|
||||
|
||||
private StaticWebApplicationContext webAppContext;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setupOnce() {
|
||||
RequestMappingHandlerAdapter adapter = new RequestMappingHandlerAdapter();
|
||||
@@ -86,23 +87,24 @@ public class RequestMappingHandlerAdapterTests {
|
||||
this.response = new MockHttpServletResponse();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void cacheControlWithoutSessionAttributes() throws Exception {
|
||||
HandlerMethod handlerMethod = handlerMethod(new SimpleController(), "handle");
|
||||
this.handlerAdapter.afterPropertiesSet();
|
||||
this.handlerAdapter.setCacheSeconds(100);
|
||||
this.handlerAdapter.handle(this.request, this.response, handlerMethod);
|
||||
this.handlerAdapter.afterPropertiesSet();
|
||||
|
||||
assertTrue(response.getHeader("Cache-Control").toString().contains("max-age"));
|
||||
this.handlerAdapter.handle(this.request, this.response, handlerMethod);
|
||||
assertTrue(response.getHeader("Cache-Control").contains("max-age"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheControlWithSessionAttributes() throws Exception {
|
||||
SessionAttributeController handler = new SessionAttributeController();
|
||||
this.handlerAdapter.afterPropertiesSet();
|
||||
this.handlerAdapter.setCacheSeconds(100);
|
||||
this.handlerAdapter.handle(this.request, this.response, handlerMethod(handler, "handle"));
|
||||
this.handlerAdapter.afterPropertiesSet();
|
||||
|
||||
this.handlerAdapter.handle(this.request, this.response, handlerMethod(handler, "handle"));
|
||||
assertEquals("no-cache", this.response.getHeader("Cache-Control"));
|
||||
}
|
||||
|
||||
@@ -211,6 +213,7 @@ public class RequestMappingHandlerAdapterTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SessionAttributes("attr1")
|
||||
private static class SessionAttributeController {
|
||||
|
||||
@@ -219,6 +222,7 @@ public class RequestMappingHandlerAdapterTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class RedirectAttributeController {
|
||||
|
||||
@@ -228,6 +232,7 @@ public class RequestMappingHandlerAdapterTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ControllerAdvice
|
||||
private static class ModelAttributeAdvice {
|
||||
|
||||
@@ -238,4 +243,4 @@ public class RequestMappingHandlerAdapterTests {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user