### Question:
RpcServiceFileGenerator extends SpecialFileGenerator { @Override public JavaScriptResult generate(Class<?> javaClass) throws SingleFileGeneratorException { StjsJavaScriptClassBuilder builder = new StjsJavaScriptClassBuilder(javaClass) .constructor(javaClass) ._constructor(); for(Method method : javaClass.getDeclaredMethods()) { builder .function(javaClass, method) .code("document.cookie = '%s=%s; path=%s'", RpcCaller.CSRF_PROTECTION_COOKIE_NAME, csrfProtectionToken, csrfProtectionCookiePath).newLine() .code("var args = Array.prototype.slice.call(arguments);").newLine() .code("var scope = args.pop();").newLine() .code("var callback = args.pop();").newLine() .newLine() .jQueryPost() .property("url").literal(rpcUrl).comma().newLine() .property("data") .noIndent().jsonStringifyObjectLiteral()._noIndent() .newLine() .property(SERVICE_NAME_PROPERTY).literal(javaClass.getName()).comma().newLine() .property(METHOD_NAME_PROPERTY).literal(method.getName()).comma().newLine() .property(CSRF_PROTECTION_TOKEN_PROPERTY).literal(csrfProtectionToken).comma().newLine() .property(ARGUMENTS_PROPERTY).noIndent().code("args")._noIndent().newLine() ._jsonStringifyObjectLiteral().comma().newLine() .property("success") .anonymousFunction("jsonData") .code("var data = JSON.parse(jsonData, %s);", JsonHelper.PARSE_REVIVER_FUNCTION).newLine() .if$("data.status === '" + RpcResult.Status.EXCEPTION.name() + "'") .code("%s.displayRuntimeError(data.%s.%s, data.%s.%s, data.%s.%s, data.%s.%s);", ErrorHandler.INSTANCE_NAME, RpcResult.JSON_RESULT_PROPERTY, VerboseExceptionMarshaller.MESSAGE_PROPERTY, RpcResult.JSON_RESULT_PROPERTY, VerboseExceptionMarshaller.NAME_PROPERTY, RpcResult.JSON_RESULT_PROPERTY, VerboseExceptionMarshaller.LINE_NUMER_PROPERTY, RpcResult.JSON_RESULT_PROPERTY, VerboseExceptionMarshaller.STACK_TRACE_PROPERTY).newLine() .else$() .code("callback.call(scope, data.%s);", RpcResult.JSON_RESULT_PROPERTY).newLine() ._if() ._function() ._jQueryPost() ._function(); } return new JavaScriptResult(builder.create()); } RpcServiceFileGenerator(String csrfProtectionCookiePath, String rpcUrl); @Override JavaScriptResult generate(Class<?> javaClass); @Override boolean isGeneratable(Class<?> javaClass);  }### Answer:
@Test public void generate() throws SingleFileGeneratorException { RpcServiceFileGenerator generator = new RpcServiceFileGenerator("/csrfProtectionCookiePath", "/rpcUrl"); String source = generator.generate(TestService.class).getSource(); assertThat(source, containsString(".prototype.getById")); assertThat(source, containsString(TestService.class.getName())); assertThat(source, containsString("JSON.parse")); }