Hi!
One of the things I like about the Restlet approach is that request
routing is a separable piece of logic, rather than something mysterious
that happens based on an XML file.
One of the many nice things about that is that it's testable. However, my
test is looking a little weird, and I wondered if I was going about things
the wrong way.
Suppose I start out with a Router that has just one path, "/", which maps
to my HomePageRestlet. After some fiddling, the passing test I ended up
with is like this:
@Test
public void testHomePage() {
Router router = new MyRouter();
Request request = new Request(Method.GET, new Reference(new
Reference("http://example.com"),"http://example.com/"));
Route restlet = (Route) router.getNext(request, new
Response(request));
assertThat(restlet.getNext(),is(HomePageRestlet.class));
}
However, I was expecting that request construction line to look more like
this:
Request request = new Request(Method.GET, "http://example.com/");
Or I could squeak by with this, but is it kosher?
Request request = new Request(Method.GET, "/");
Turning to the last two lines, they look funny to me with that cast.
Ideally I'd like something more like
Restlet restlet = router.getNext(request, new Response(request));
assertThat(restlet, is(HomePageRestlet.class));
Or even
assertThat(router.route(request), is(HomePageRestlet.class));
I could of course hide the extra stuff in a helper method, but before I do
that I thought I'd see if I was missing a better way to write the tests.
Thanks,
William