PersonResource extends HttpObject { @Override public Response get(Request req) { String name = req.path().valueFor("name"); if(name!=null && name.equals("stu")){ return OK(Text(name)); }else{ return NOT_FOUND(Text("No such person")); } } PersonResource(); @Override Response get(Request req);  }
@Test public void returns_stu(){ HttpObject subject = new PersonResource(); Request input = new MockRequest(subject, "/people/stu"); Response output = subject.get(input); assertTrue(responseCodeOf(output).isOK_200()); assertTrue(contentTypeOf(output).isPlainTextWithEncoding("utf-8")); assertTrue(bodyOf(output).equals("stu")); }
@Test public void returns_NOT_FOUND_when_name_is_missing(){ PersonResource subject = new PersonResource(); Request input = new MockRequest(subject, "/people/"); Response output = subject.get(input); assertTrue(responseCodeOf(output).isNOT_FOUND()); assertTrue(contentTypeOf(output).isPlainTextWithEncoding("utf-8")); assertEquals("No such person", bodyOf(output).asString()); }