Repository: square/retrofit
Issue: Retrofit.Builder.validateEagerly() accept boolean

`validateEagerly` is a great option. But at the moment developer should explicitly store a reference to  `Retrofit.Builder` to conditionally enable/disable it.

Example:

Today:

``` java
@Provides @NonNull @Singleton
public SomeApi provideSomeApi(@NonNull OkHttpClient okHttpClient, @NonNull Moshi moshi) {
  Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
    .baseUrl("https://someapi/v1/")
    .client(okHttpClient)
    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
    .addConverterFactory(MoshiConverterFactory.create(moshi));

  if (BuildConfig.DEBUG) { // or some other config value
    retrofitBuilder.validateEagerly();
  }

  return retrofitBuilder.build().create(SomeApi.class);
}
```

A Better Tomorrow:

``` java
@Provides @NonNull @Singleton
public SomeApi provideSomeApi(@NonNull OkHttpClient okHttpClient, @NonNull Moshi moshi) {
  return new Retrofit.Builder()
    .baseUrl("https://someapi/v1/")
    .client(okHttpClient)
    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
    .addConverterFactory(MoshiConverterFactory.create(moshi))
    .validateEagerly(BuildConfig.DEBUG)
    .build()
    .create(SomeApi.class);
}
```

Wouldn't you be mind of PR which will change signature of `validateEagerly` so it could accept `boolean`?

Related to #1023.


Issue comments:
That's fine.

On Wed, Oct 28, 2015, 7:53 AM Artem Zinnatullin notifications@github.com
wrote:

> validateEagerly is a great option. But at the moment developer should
> explicitly store a reference to Retrofit.Builder to conditionally
> enable/disable it.
> 
> Example:
> 
> Today:
> 
> @Provides @NonNull @Singletonpublic SomeApi provideSomeApi(@NonNull OkHttpClient okHttpClient, @NonNull Moshi moshi) {
>   Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
>     .baseUrl("https://someapi/v1/")
>     .client(okHttpClient)
>     .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
>     .addConverterFactory(MoshiConverterFactory.create(moshi));
> 
>   if (BuildConfig.DEBUG) { // or some other config value
>     retrofitBuilder.validateEagerly();
>   }
> 
>   return retrofitBuilder.build().create(SomeApi.class);
> }
> 
> A Better Tomorrow:
> 
> @Provides @NonNull @Singletonpublic SomeApi provideSomeApi(@NonNull OkHttpClient okHttpClient, @NonNull Moshi moshi) {
>   return new Retrofit.Builder()
>     .baseUrl("https://someapi/v1/")
>     .client(okHttpClient)
>     .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
>     .addConverterFactory(MoshiConverterFactory.create(moshi))
>     .validateEagerly(BuildConfig.DEBUG)
>     .build()
>     .create(SomeApi.class);
> }
> 
> Wouldn't you be mind of PR which will change signature of validateEagerly
> so it could accept boolean?
> 
> Related to #1023 https://github.com/square/retrofit/issues/1023.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/square/retrofit/issues/1240.


Pull request review comments:
Missing a period here and above. [Comments should be sentences](nedbatchelder.com/blog/201401/comments_should_be_sentences.html).

Good point, thanks for the link.


Patch that resolved the issue:
diff --git a/retrofit/src/main/java/retrofit/Retrofit.java b/retrofit/src/main/java/retrofit/Retrofit.java
index 4d2b040710..f6355ce89d 100644
--- a/retrofit/src/main/java/retrofit/Retrofit.java
+++ b/retrofit/src/main/java/retrofit/Retrofit.java
@@ -349,8 +349,8 @@ public Builder callbackExecutor(Executor callbackExecutor) {
      * When calling {@link #create} on the resulting {@link Retrofit} instance, eagerly validate
      * the configuration of all methods in the supplied interface.
      */
-    public Builder validateEagerly() {
-      validateEagerly = true;
+    public Builder validateEagerly(boolean validateEagerly) {
+      this.validateEagerly = validateEagerly;
       return this;
     }
 


Test patch:
diff --git a/retrofit/src/test/java/retrofit/RetrofitTest.java b/retrofit/src/test/java/retrofit/RetrofitTest.java
index b129d735f4..ecfb3d91b8 100644
--- a/retrofit/src/test/java/retrofit/RetrofitTest.java
+++ b/retrofit/src/test/java/retrofit/RetrofitTest.java
@@ -115,10 +115,29 @@ interface Annotated {
     }
   }
 
+  @Test public void validateEagerlyDisabledByDefault() {
+    Retrofit retrofit = new Retrofit.Builder()
+        .baseUrl(server.url("/"))
+        .build();
+
+    // Should not throw exception about incorrect configuration of the VoidService
+    retrofit.create(VoidService.class);
+  }
+
+  @Test public void validateEagerlyDisabledByUser() {
+    Retrofit retrofit = new Retrofit.Builder()
+        .baseUrl(server.url("/"))
+        .validateEagerly(false)
+        .build();
+
+    // Should not throw exception about incorrect configuration of the VoidService
+    retrofit.create(VoidService.class);
+  }
+
   @Test public void validateEagerlyFailsAtCreation() {
     Retrofit retrofit = new Retrofit.Builder()
         .baseUrl(server.url("/"))
-        .validateEagerly()
+        .validateEagerly(true)
         .build();
 
     try {