### Question:
ParameterSpec implements Serializable { public void parseParameters(PageParameters params, T beanToPopulate) { parseParameters(params, beanToPopulate, true); } ParameterSpec(Class <? extends WebPage> page, String... expressions); ParameterSpec registerParameter(String parameter, String propExpr); BookmarkablePageLink createLink(String id, final IModel<T> model); void redirect(IModel<T> model); PageParameters createParameters(T bean); void parseParameters(PageParameters params, T beanToPopulate); void parseParameters(PageParameters params,
                                T beanToPopulate,
                                boolean throw404OnParseError);  }### Answer:
@Test public void testParseParameters_indexed() { ParameterSpec builder = new ParameterSpec<TestBean>(TestPage.class, "id", "name"); TestBean bean = new TestBean(); PageParameters params = new PageParameters(); params.set("id", "5"); params.set("name", "hello"); builder.parseParameters(params, bean); Assert.assertEquals((Long) 5L, (Long) bean.getId()); Assert.assertEquals("hello", bean.getName()); }
@Test public void testParseParameters_badformat404() { ParameterSpec builder = new ParameterSpec<TestBean>(TestPage.class, "id", "name"); TestBean bean = new TestBean(); PageParameters params = new PageParameters(); params.set("id", "notparseableaslong"); try { builder.parseParameters(params, bean); Assert.fail("AbortWithHttpErrorCodeException was not thrown."); } catch(AbortWithHttpErrorCodeException awhece) { Assert.assertEquals(404, awhece.getErrorCode()); } }
@Test public void testParseParameters_badformatnull() { ParameterSpec builder = new ParameterSpec<TestBean>(TestPage.class, "id", "name"); TestBean bean = new TestBean(); PageParameters params = new PageParameters(); params.set("id", "notparseableaslong"); builder.parseParameters(params, bean, false); Assert.assertNull(bean.getId()); }
@Test public void testParseParameters_missing() { ParameterSpec builder = new ParameterSpec<TestBean>(TestPage.class, "id", "name"); TestBean bean = new TestBean(); PageParameters params = new PageParameters(); builder.parseParameters(params, bean); Assert.assertNull(bean.getId()); Assert.assertNull(bean.getName()); }