RetrofitServiceMethod { public List<MethodSpec> generateCodeWithRetryStaleIfRequired() { MethodSpec methodSpec = generateCode(false); if (!canAppendStaleHeader()) { return singletonList(methodSpec); } return asList(methodSpec, generateCode(true)); } RetrofitServiceMethod(ExecutableElement methodElement); List<MethodSpec> generateCodeWithRetryStaleIfRequired();  }
@Test public void generateCodeWithRetryStaleIfRequired_normal() throws Exception { List<MethodSpec> methodSpecs = singleMethodInfo(Foo1.class).generateCodeWithRetryStaleIfRequired(); assertEquals("public abstract java.lang.String bar(java.lang.String arg0);", methodSpecs.get(0).toString().trim()); }
@Test public void generateCodeWithRetryStaleIfRequired_generic_return() throws Exception { List<MethodSpec> methodSpecs = singleMethodInfo(Foo2.class).generateCodeWithRetryStaleIfRequired(); assertEquals( "public abstract java.util.List<java.lang.String> bar(java.lang.String arg0, int arg1);", methodSpecs.get(0).toString().trim()); }
@Test public void generateCodeWithRetryStaleIfRequired_generic_params() throws Exception { List<MethodSpec> methodSpecs = singleMethodInfo(Foo3.class).generateCodeWithRetryStaleIfRequired(); assertEquals( "public abstract java.util.List<java.lang.String> bar(java.util.List<java.lang.String> arg0, int arg1);", methodSpecs.get(0).toString().trim()); }
@Test public void generateCodeWithRetryStaleIfRequired_annotations() throws Exception { List<MethodSpec> methodSpecs = singleMethodInfo(Foo4.class).generateCodeWithRetryStaleIfRequired(); assertEquals("@retrofit.http.GET(\"/hoge\")\n" + "@retrofit.http.Headers({\n" + " \"A: B\",\n" + " \"C: D\"\n" + "})\n" + "public abstract java.util.List<java.lang.String> bar(java.util.List<java.lang.String> arg0, @retrofit.http.Query(\"bar\") int arg1);", methodSpecs.get(0).toString().trim()); }
@Test public void generateCodeWithRetryStaleIfRequired_rx_get() throws Exception { List<MethodSpec> methodSpecs = singleMethodInfo(Foo5.class).generateCodeWithRetryStaleIfRequired(); assertEquals("@retrofit.http.GET(\"/hoge\")\n" + "@retrofit.http.Headers(\"Cache-Control: max-stale=86400\")\n" + "public abstract rx.Observable<java.lang.String> bar$$RetryStale(java.util.List<java.lang.String> arg0, int arg1);", methodSpecs.get(1).toString().trim()); }
@Test public void generateCodeWithRetryStaleIfRequired_rx_get_with_header() throws Exception { List<MethodSpec> methodSpecs = singleMethodInfo(Foo6.class).generateCodeWithRetryStaleIfRequired(); assertEquals("@retrofit.http.GET(\"/hoge\")\n" + "@retrofit.http.Headers({\n" + " \"A: B\",\n" + " \"C: D\",\n" + " \"Cache-Control: max-stale=86400\"\n" + "})\n" + "public abstract rx.Observable<java.lang.String> bar$$RetryStale(java.util.List<java.lang.String> arg0, int arg1);", methodSpecs.get(1).toString().trim()); }