コード例 #1
0
  @Test
  public void resolveArgumentOrdering() throws Exception {
    String name = "testBean";
    Object testBean = new TestBean(name);
    mavContainer.addAttribute(name, testBean);
    mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, testBean);

    Object anotherTestBean = new TestBean();
    mavContainer.addAttribute("anotherTestBean", anotherTestBean);

    StubRequestDataBinder dataBinder = new StubRequestDataBinder(testBean, name);
    WebDataBinderFactory binderFactory = createMock(WebDataBinderFactory.class);
    expect(binderFactory.createBinder(webRequest, testBean, name)).andReturn(dataBinder);
    replay(binderFactory);

    processor.resolveArgument(paramModelAttr, mavContainer, webRequest, binderFactory);

    assertSame(
        "Resolved attribute should be updated to be last in the order",
        testBean,
        mavContainer.getModel().values().toArray()[1]);
    assertSame(
        "BindingResult of resolved attribute should be last in the order",
        dataBinder.getBindingResult(),
        mavContainer.getModel().values().toArray()[2]);
  }
コード例 #2
0
  @Test(expected = BindException.class)
  public void resovleArgumentBindException() throws Exception {
    String name = "testBean";
    Object target = new TestBean();
    mavContainer.getModel().addAttribute(target);

    StubRequestDataBinder dataBinder = new StubRequestDataBinder(target, name);
    dataBinder.getBindingResult().reject("error");

    WebDataBinderFactory binderFactory = createMock(WebDataBinderFactory.class);
    expect(binderFactory.createBinder(webRequest, target, name)).andReturn(dataBinder);
    replay(binderFactory);

    processor.resolveArgument(paramNonSimpleType, mavContainer, webRequest, binderFactory);
  }