### Question:
AddOnloadFunctionProcessor implements JsProcessor { public boolean process(JsRequest request, JsResponseBuilder builder) throws JsException { JsUri jsUri = request.getJsUri(); String onloadStr = jsUri.getOnload(); if (onloadStr != null) { if (!ONLOAD_FN_PATTERN.matcher(onloadStr).matches()) { throw new JsException(HttpServletResponse.SC_BAD_REQUEST, ONLOAD_FUNCTION_NAME_ERROR); } builder.appendJs(createOnloadScript(onloadStr), ONLOAD_CODE_ID); } else if (jsUri.isNohint()) { builder.appendJs(JSL_CALLBACK_JS, JSL_CODE_ID, true); } return true; }  boolean process(JsRequest request, JsResponseBuilder builder); @VisibleForTesting
  static final String ONLOAD_FUNCTION_NAME_ERROR; @VisibleForTesting
  static final String ONLOAD_JS_TPL; }### Answer:
@Test public void testSkipsWhenNoOnloadAndWithHintSpecified() throws Exception { EasyMock.expect(jsUri.getOnload()).andReturn(null); EasyMock.expect(jsUri.isNohint()).andReturn(false); response = control.createMock(JsResponseBuilder.class); control.replay(); assertTrue(processor.process(request, response)); control.verify(); }
@Test public void testFailsWithInvalidFunctionName() throws Exception { EasyMock.expect(jsUri.getOnload()).andReturn("!!%%!!%%"); control.replay(); try { processor.process(request, response); fail("A JsException should have been thrown by the processor."); } catch (JsException e) { assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); assertEquals(AddOnloadFunctionProcessor.ONLOAD_FUNCTION_NAME_ERROR, e.getMessage()); } control.verify(); }
@Test public void testGeneratesCallbackCode() throws Exception { EasyMock.expect(jsUri.getOnload()).andReturn(ONLOAD_FUNCTION); control.replay(); assertTrue(processor.process(request, response)); assertEquals(HttpServletResponse.SC_OK, response.getStatusCode()); String expectedBody = String.format(AddOnloadFunctionProcessor.ONLOAD_JS_TPL, ONLOAD_FUNCTION); assertEquals(expectedBody, response.build().toJsString()); control.verify(); }
@Test public void testWithoutHint() throws Exception { EasyMock.expect(jsUri.getOnload()).andReturn(null); EasyMock.expect(jsUri.isNohint()).andReturn(true); control.replay(); assertTrue(processor.process(request, response)); assertEquals(AddOnloadFunctionProcessor.JSL_CALLBACK_JS, response.build().toJsString()); control.verify(); }
@Test public void testWithHint() throws Exception { EasyMock.expect(jsUri.getOnload()).andReturn(null); EasyMock.expect(jsUri.isNohint()).andReturn(false); control.replay(); assertTrue(processor.process(request, response)); assertEquals("", response.build().toJsString()); control.verify(); }