@Test public void resolveArgument() throws Exception { MultiValueMap<String, String> params = getVariablesFor("cars"); params.add("colors", "red"); params.add("colors", "green"); params.add("colors", "blue"); MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class); assertEquals(Arrays.asList("red", "green", "blue"), this.resolver.resolveArgument(param, this.mavContainer, this.webRequest, null)); }
@Test(expected = ServletRequestBindingException.class) public void resolveArgumentMultipleMatches() throws Exception { getVariablesFor("var1").add("colors", "red"); getVariablesFor("var2").add("colors", "green"); MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class); this.resolver.resolveArgument(param, this.mavContainer, this.webRequest, null); }
@Test public void resolveArgumentPathVariable() throws Exception { getVariablesFor("cars").add("year", "2006"); getVariablesFor("bikes").add("year", "2005"); MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class); assertEquals("2006", this.resolver.resolveArgument(param, this.mavContainer, this.webRequest, null)); }
@Test(expected = ServletRequestBindingException.class) public void resolveArgumentRequired() throws Exception { MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class); this.resolver.resolveArgument(param, this.mavContainer, this.webRequest, null); }
@Test public void resolveArgumentNoMatch() throws Exception { MultiValueMap<String, String> params = getVariablesFor("cars"); params.add("anotherYear", "2012"); MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class); assertEquals("2013", this.resolver.resolveArgument(param, this.mavContainer, this.webRequest, null)); }
@Test public void resolveArgumentDefaultValue() throws Exception { MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class); assertEquals("2013", resolver.resolveArgument(param, this.mavContainer, this.webRequest, null)); }