### Question:
PageBasedRedirect implements Redirect { @Override @SuppressWarnings("deprecation") public String to(Class<?> pageClass, Map<String, String> parameters) { At at = pageClass.getAnnotation(At.class); String uriTemplate; if (at == null) { PageBook.Page page = pageBook.forClass(pageClass); if (page == null) throw new IllegalArgumentException("No such page class was registered (missing @At annotation?): " + pageClass.getName()); uriTemplate = page.getUri(); } else uriTemplate = at.value(); if (uriTemplate.startsWith("/")) uriTemplate = request.get().context() + uriTemplate; String[] split = uriTemplate.split("/"); StringBuilder uri = new StringBuilder(); for (int i = 1 , splitLength = split.length; i < splitLength; i++) { String piece = split[i]; uri.append('/'); if (piece.startsWith(":")) { String value = parameters.get(piece.substring(1)); if (value == null) throw new IllegalArgumentException("Missing parameter " + piece + " in URI template for page class: " + pageClass.getName() + " '" + uriTemplate + "'"); uri.append(URLEncoder.encode(value)); } else uri.append(piece); } return uri.toString(); }  @Override @SuppressWarnings("deprecation") // For URL encoder. String to(Class<?> pageClass, Map<String, String> parameters); @Override String to(Class<?> page);  }### Answer:
@Test public void fillInUriTemplate() throws Exception { String uri = redirect.to(ProductIdList.class, ImmutableMap.of( "product", "Indie Game", "id", "Super Meat Boy")); assert "/Indie+Game/list/Super+Meat+Boy".equals(uri) : uri; }
@Test public void staticUri() throws Exception { String uri = redirect.to(StaticPage.class, ImmutableMap.of( "product", "Indie Game", "id", "Super Meat Boy")); assert "/product/list/id".equals(uri) : uri; assert "/product/list/id".equals(redirect.to(StaticPage.class)) : uri; }
@Test(expectedExceptions = IllegalArgumentException.class) public void badParameters() throws Exception { String uri = redirect.to(ProductIdList.class, ImmutableMap.of( "id", "Super Meat Boy")); assert "/Indie+Game/list/Super+Meat+Boy".equals(uri) : uri; }