spr7766
This commit is contained in:
parent
39e0c29d19
commit
da898faac9
|
|
@ -0,0 +1,20 @@
|
|||
package org.springframework.web.servlet.mvc.annotation;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@Controller
|
||||
public class Spr7766Controller {
|
||||
|
||||
@RequestMapping("/colors")
|
||||
public void handler(@RequestParam List<Color> colors) {
|
||||
Assert.isTrue(colors.size() == 2);
|
||||
Assert.isTrue(colors.get(0).equals(Color.WHITE));
|
||||
Assert.isTrue(colors.get(1).equals(Color.BLACK));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package org.springframework.web.servlet.mvc.annotation;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.ConversionServiceFactory;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
|
||||
public class Spr7766Tests {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter();
|
||||
ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer();
|
||||
GenericConversionService service = ConversionServiceFactory.createDefaultConversionService();
|
||||
service.addConverter(new ColorConverter());
|
||||
binder.setConversionService(service);
|
||||
adapter.setWebBindingInitializer(binder);
|
||||
Spr7766Controller controller = new Spr7766Controller();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setRequestURI("/colors");
|
||||
request.setPathInfo("/colors");
|
||||
request.addParameter("colors", "#ffffff,000000");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
adapter.handle(request, response, controller);
|
||||
}
|
||||
|
||||
public class ColorConverter implements Converter<String, Color> {
|
||||
public Color convert(String source) { if (!source.startsWith("#")) source = "#" + source; return Color.decode(source); }
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue