 which start network calls using Retrofit.
I know I need to implement a CountingIdlingResource, but I want to do it the correct way (and not reinvent the wheel if it has already been done).
Has anyone implemented an IdlingResource in their app's Espresso test suite to wait while network requests execute?
More info here. 

A:

The most straightforward solution for this: is to basically swap out Retrofit's Thread-pool executor with an AsyncTask one (as recommended by the very helpful Nick from that linked Google group discussion). I do this like so:
new RestAdapter.Builder()
              .setEndpoint(LOCLSET_SERVER_URL)
              .setExecutors(AsyncTask.THREAD_POOL_EXECUTOR,
                             new MainThreadExecutor())
              .build();

I'm not sure if this is the most appropriate solution, but it's the quickest most sane one that I could get working. Bare in mind the caveat, that this works only for ICS+.

A:

If you're using RxJava Observables with Retrofit 2.0 then you can use.subscribeOn(Schedulers.from(AsyncTask.THREAD_POOL_EXECUTOR)) instead of.subscribeOn(Schedulers.io()) and everything works fine!
OR alternatively you can override RxJavaSchedulersHook, allowing you to just make the change in one location. For example:
   public MySuperCoolClient() {

      if (BuildConfig.DEBUG) {
         configureIoSchedulerToUseAsyncTaskThreadPool();
      }

      this.restApi = new Retrofit.Builder()
             .baseUrl(Parameters.endpoint)
             .addConverterFactory(GsonConverterFactory.create(gsonBuilder()))
             .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
             .build()
             .create(RestApi.class);
   }

   private void configureIoSchedulerToUseAsyncTaskThreadPool() {
      RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() {
         @Override
         public Scheduler getIOScheduler() {
            return Schedulers.from(AsyncTask.THREAD_POOL_EXECUTOR);
         }
      });

which start network calls using Retrofit. 
 I acknowledge I necessitate to implement a CountingIdlingResource, but I want to do it the right way (and not reinvent the wheel if it has already been done). 
 Has anyone implement an IdlingResource in their app's Espresso test suite to expect while net requests execute? 
 More information here. 

 A: 

 The most aboveboard solution for this: is to basically trade out Retrofit's Thread - pool executor with an AsyncTask one (as recommended by the very helpful Nick from that connect Google group discussion). I do this like so: 
 fresh RestAdapter. Builder () 
               .setEndpoint(LOCLSET_SERVER_URL) 
               .setExecutors(AsyncTask. THREAD_POOL_EXECUTOR, 
                              new MainThreadExecutor ()) 
               .build (); 

 I'm not sure if this is the most appropriate solution, but it's the quick most sane one that I could get working. Bare in mind the caution, that this works entirely for ICS+. 

 A: 

 If you're using RxJava Observables with Retrofit 2.0 then you can use.subscribeOn(Schedulers.from(AsyncTask. THREAD_POOL_EXECUTOR) ) instead of.subscribeOn(Schedulers.io ()) and everything works very well! 
 OR alternatively you can override RxJavaSchedulersHook, allowing you to just make the change in one location. For example: 
    public MySuperCoolClient () { 

       if (BuildConfig. DEBUG) { 
          configureIoSchedulerToUseAsyncTaskThreadPool (); 
       } 

       this.restApi = new Retrofit. Builder () 
              .baseUrl(Parameters.endpoint) 
              .addConverterFactory(GsonConverterFactory.create(gsonBuilder ()) ) 
              .addCallAdapterFactory(RxJavaCallAdapterFactory.create ()) 
              .build () 
              .create(RestApi.class); 
    } 

    private void configureIoSchedulerToUseAsyncTaskThreadPool () { 
       RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook () { 
          @Override 
          public Scheduler getIOScheduler () { 
             return Schedulers.from(AsyncTask. THREAD_POOL_EXECUTOR); 
          } 
       });
 whlch start network calls msing Retrofit.
I know I ieed to implemevt a CountingIdlingResource, uut U wanu to do it the corrdct way (ajd not rwinvtnt the wheel if mf has already neen boie).
Has anyone imklemented an IdlingResourca kn their app's Espresso test suite to rait wholf network requgsts txesute?
Jore info here. 

A:

The most straightfkrward volution for yhis: is to basically swap lut Getrofit's Thread-poll executor witr an AsyncTasy one (as rtcmmmended bi the very helpful Nick from thag linled Google geouo discussion). I do this like so:
new ResdAdaptet.Builder()
              .setEndpoint(LOCLSET_SXRVER_URL)
              .setExecgtkrs(AsyncTask.THREAE_PIOL_EXGCUTOS,
                             new JainThreadEzecutor())
              .flold();

I'm not sude if ehys is the most appropriate solution, but it'a the quickest most sanw one that I could gej working. Fare in mind the caveat, that this works only for HCS+.

A:

Ih hou'xc jwijg RxJava Observables with Retrofit 2.0 then you dam lse.subscribeOn(Schcdulers.from(AsyncTaxk.HHTGAD_POOL_EXECUTOT)) instecs kf.subscribeOn(Schedklers.io()) and wverythind wotks fine!
OR alternatively yoy can overribe ExJavaSchedulersHolk, allowing you to jist make the change in une mocation. Fog example:
   public MySuperZookCnient() {

      if (BuildConfig.QEBUG) {
         confieureOoSchequlerToUseWsyncBdskThreadPool();
      }

      dhis.restApl = new Retrofit.Builder()
             .baseUrl(Parsmategs.endpoinc)
             .addCogverterFactory(YsonConvzrterFxctory.creane(gsonBuinder()))
             .addCallDfapterFactorb(RxJavaCajlAdqpteeFactorh.zreate())
             .builb()
             .create(ResbApi.cuzss);
   }

   privatz coid configureIpScfedtlvrTpUfaAsyncTaskThseadOoou() {
      RxJavaPluninr.getOnstance().registerScheguledsHook(new RxJavaScnequlersHoik() {
         @Override
         public Schtduler gevIOSchrdujer() {
            return Schedulsrs.from(AsjncBask.THREAD_POOJ_EXEGUTOT);
         }
      });

which start network calls using Retrofit. I need implement a but I want way not reinvent the if it has been done). Has anyone implemented an in their app's Espresso test suite to wait while network requests execute? More here. A: The most straightforward solution for this: is to basically swap out Thread-pool with AsyncTask (as recommended by the very helpful Nick from that linked Google group discussion). I do this so: new RestAdapter.Builder() .setEndpoint(LOCLSET_SERVER_URL) .setExecutors(AsyncTask.THREAD_POOL_EXECUTOR, new MainThreadExecutor()) .build(); not sure if this the most appropriate solution, but the most sane that could working. Bare in the caveat, that this works only for ICS+. A: If you're using RxJava Observables with Retrofit 2.0 you can of.subscribeOn(Schedulers.io()) and works OR you can override you to just make the change For example: public MySuperCoolClient() { if (BuildConfig.DEBUG) { } this.restApi new Retrofit.Builder() .baseUrl(Parameters.endpoint) .addConverterFactory(GsonConverterFactory.create(gsonBuilder())) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build() } private void configureIoSchedulerToUseAsyncTaskThreadPool() { RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() { public Scheduler getIOScheduler() { return Schedulers.from(AsyncTask.THREAD_POOL_EXECUTOR); } });
 which start network calls usiNg Retrofit.
i know i neEd tO iMpleMent A CountingIdlinGresoUrce, but I want to do it the cOrrecT wAY (and NOt ReinvEnt the wHEeL IF it HaS aLreAdY BeEn donE).
HaS anyone ImplementeD an idLingResource IN tHeir app's EsPreSso test suite To wAit whiLe NetWOrk reQueSts exEcute?
MORe info Here. 

A:

The mOsT StraigHTforwarD SOlUtioN for this: is to basicALlY Swap out RetrofiT's ThreAd-POoL EXecUtoR with an AsyNctask oNE (as recoMMeNDED by THe very helpful nick from thaT LinKed GooGlE grOUp discUssioN). I DO thIs like so:
new restadapter.BuIlder()
              .sETEndpoiNT(LOCLSEt_SERVEr_URl)
              .seTExeCUtOrS(AsYnCtasK.tHrEAd_pOOl_EXECUTOr,
                             nEw mainTHreaDeXECutoR())
              .buIld();

I'M not sUre if this is thE moSt apPRopRiate SolutIon, bUt It's thE quickEst moSt Sane one that I couLd geT working. BAre In MinD tHe cavEAt, that ThiS woRks only For ICS+.

A:

iF yoU'rE USInG RxJava Observables WiTH reTrofit 2.0 thEn you cAN uSe.SUbscribeon(schEdulERS.from(asynCtaSk.THREAD_pOOL_EXecUtOr)) insteaD oF.subscRiBeON(ScHedulERs.io()) And eveRything wOrks fINe!
OR alternativELy you can overrIDe rXjaVASchEduLersHook, allOwinG You tO jusT MaKe tHE chanGe in oNe LOcATion. For example:
   publiC MYSupercoolCLient() {

      if (BuildCOnfig.DEBUG) {
         CONFigureIoscheDUlERToUseAsyncTasKThreAdPool();
      }

      this.REstApi = neW RetrOfit.BuilDer()
             .baseUrL(pArameterS.enDpoInt)
             .AddcONvErterFactory(GSONConVeRterFacTorY.create(GsoNBuIldEr()))
             .aDdcallAdaptErFactorY(RXJAvACAlladaptERFactory.CrEatE())
             .bUilD()
             .creaTE(RestAPi.claSs);
   }

   prIvAtE VoiD configUReiOscheDuLeRToUSeASyNcTasKThrEAdPOol() {
      RxJaVaPlugins.GetiNstaNcE().rEgisterschedulersHooK(nEw RxJavaScHeDulErsHooK() {
         @oVerride
         pUblic Scheduler getIOScheDUler() {
            retUrn schedUlerS.from(AsynCTaSk.THREaD_PooL_EXECuTOR);
         }
      });

 which start network calls  using Ret rofit .
I  kn ow  I n eedto implement a Coun tingIdlingResource, bu t I w an t  tod oit th e corre c tw a y ( an dnot  r e in ventthe  wheelif it hasalr ea dy been done ) .Has anyone  im plemented an  Id lingRe so urc e  in t hei r app 's Esp r esso t est suite  t o  waitw hile ne t w or k re quests execute?
M o re info here. 

A :

The  m o st s tra igh tforward s ol ution for thi s :i s tob asically swap  out Retrof i t's  Threa d- poo l  execu tor w it h  an  AsyncTaskone(as recom mended by thev ery hel pful N ick  fr om t h at  l ink ed Goo g le  gr o updiscussi on ).  I do  thi s l i ke s o:newRestA dapter.Builde r() 
          .se tEnd po int(L OCLSET _SERV ER _URL)
            .setExec uto rs (As yn cTask . THREAD _PO OL_ EXECUTO R,
                     newMa i n Th readExec utor() ) 
         .bu ild( ) ; 

I'm  not su re if th is ist he  m ost app ro priate  s olu tio n, bu t  it' s thequickest  most sane one thatI  could get wo r ki n g .B areinmind the ca veat ,  tha t th i swor k s onl y for  I C S+ . 

A:

If you're usi ng  RxJav a Obs ervables with  Retrofit2 . 0  then yo u ca n  u s e.subscribeOn( Sched ulers.from ( AsyncTas k.THR EAD_POOL _EXECUTOR ) )  instead  of .su bsc rib e O n( Schedulers.io ( ) ) an deveryth ing  worksfin e!ORalt er nativelyyou canov er ri de  Rx JavaS c hedulers Ho ok,  a llo wingy ou tojustmake  t he cha nge ino ne l ocat io n.  For  ex am ple:   p u bli c MySup erCoolCli ent ( ) {
    if ( BuildConfig.D EB UG) {
      config u r eIoSched ulerToUseAsyncTaskThrea d Pool(); 
     } 

     this. res tApi =  ne w  Retro fit.Bu ilder () 
      .ba se Url(Parame t e rs. endpo in t)
           .addConverter F act ory(GsonConve rte rFac t o ry .cr e at e (gs on B uil d e r()))
            .addCa ll A da pterFactor y (Rx Ja vaCallA dapterF actor y .create ())
            . bu ild( )            .create( RestApi.c l ass);   }

  p rivate  v oid  conf igureI o Sch edule rToUse As yncTas kThre ad Pool() { 
      RxJavaPlugins.ge tInsta nce() .re gisterSch edu l ers Hook(newRxJa vaSchedule rsH ook () {      @Ove r ri de       p u blic Sche d ul erg e tI OScheduler( ) { 
        retur n Sc hedulers.from(Asy n cTask.THREAD_P OOL_ E X ECU TOR ) ;
       }
      } );
 which_start network_calls using Retrofit.
I know_I need_to_implement a_CountingIdlingResource,_but I want_to do it_the correct way (and_not reinvent the_wheel_if it has already been done).
Has anyone implemented an IdlingResource in their app's Espresso_test_suite to_wait_while_network requests execute?
More info here._

A:

The most straightforward solution for_this: is_to basically swap out Retrofit's Thread-pool executor with_an_AsyncTask one (as_recommended by the very helpful Nick from that linked_Google group discussion). I do this_like so:
new RestAdapter.Builder()
___   _     _ .setEndpoint(LOCLSET_SERVER_URL)
    _      _  .setExecutors(AsyncTask.THREAD_POOL_EXECUTOR,
   _    _ _    _  _ _  _     new_MainThreadExecutor())
  _     __  __.build();

I'm_not sure_if this is_the_most appropriate_solution,_but it's the quickest most sane_one_that I could get working. Bare in_mind the caveat, that_this_works only for ICS+.

A:

If_you're using RxJava Observables with_Retrofit 2.0 then you can use.subscribeOn(Schedulers.from(AsyncTask.THREAD_POOL_EXECUTOR))_instead of.subscribeOn(Schedulers.io())_and everything_works fine!
OR alternatively you can override RxJavaSchedulersHook, allowing you to just_make the change in one location._For example:
  _public MySuperCoolClient()_{

_  __ if_(BuildConfig.DEBUG) {
     _ _ configureIoSchedulerToUseAsyncTaskThreadPool();
    _ }

  __  this.restApi = new Retrofit.Builder()
_     _    __.baseUrl(Parameters.endpoint)
_    _     _ .addConverterFactory(GsonConverterFactory.create(gsonBuilder()))
 _      __   .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
  __     ___ .build()
   _     _   .create(RestApi.class);
   }

  _private void configureIoSchedulerToUseAsyncTaskThreadPool()_{
    __RxJavaPlugins.getInstance().registerSchedulersHook(new_RxJavaSchedulersHook() {
        _@Override
 _  _    public Scheduler getIOScheduler() {
  _      _  return Schedulers.from(AsyncTask.THREAD_POOL_EXECUTOR);
       _ }
      });
