Save 37% off PRO during our Black Friday Sale! »

dagger2

8928b5277aa7234dbca4ff782952343a?s=47 funnelbit
April 20, 2015
440

 dagger2

8928b5277aa7234dbca4ff782952343a?s=128

funnelbit

April 20, 2015
Tweet

Transcript

  1. %BHHFS JEGVOOFMCJU

  2. ࣗݾ঺հ w JEGVOOFMCJU ๺ଜɹྋ  w גࣜձࣾ͸ͯͳ w ΞϓϦέʔγϣϯΤϯδχΞ w

    ڈ೥͔ΒΞϓϦ։ൃΛ࢝Ίͨ
  3. %BHHFS

  4. %BHHFS w IUUQTHJUIVCDPNHPPHMFEBHHFS w %*ίϯςφ w 4RVBSF͕։ൃͯͨ͠%BHHFSͷHPPHMFGPSL w ਖ਼ࣜ൛ ͍ͭઌ೔ϦϦʔε

     w ։ൃ൛ͷ4/"14)05
  5. %BHHFSͷϝϦοτ w ίϯύΠϧ࣌ʹίʔυੜ੒͠ґଘղܾ w KBWBYJOKFDU"OOPUBUJPOΛ࢖༻ w ։ൃ͕׆ൃ

  6. %BHHFS ࢖༻ྫ

  7. ߏ੒Πϝʔδ .PEVMF &OUSZ.BOBHFS "DUJWJUZ &OUSZ.BOBHFS "QQMJDBUJPO $PNQPOFOU "1*$MJFOU

  8. ௨৴෦෼ public class BkumaFormalServiceProvider implements BkumaServiceProvider {
 …
 @Override
 public

    BkumaService getService() {
 OkHttpClient client = new OkHttpClient();
 
 RestAdapter restAdapter = new RestAdapter.Builder()
 .setClient(new OkClient(client))
 .setEndpoint(BkumaService.END_POINT)
 .build();
 return restAdapter.create(BkumaService.class);
 } …
  9. .PEVMF͔Β*OKFDU @Module
 public class BkumaModule {
 private final BkumaService mBkumaService;


    public BkumaModule(BkumaGirlsApplication application) {
 mBkumaService = new BkumaFormalServiceProvider(application .getApplicationContext()).getService();
 
 @Provides @Singleton
 EntryManager provideEntryManager() {
 return new EntryManager(mBkumaService);
 } … public class MainActivity extends ActionBarActivity { @Inject EntryManager mEntryManager; @Override
 protected void onCreate(Bundle savedInstanceState) {
 … ((BkumaGirlsApplication)getApplication()).component() .inject(this); } … ௨৴෦෼
  10. $PNQPOFOUΛ࡞Δ public class BKUMAGirlsApplication extends Application {
 @Singleton
 @Component(modules =

    BkumaModule.class)
 public interface ApplicationComponent {
 void inject(MainActivity mainActivity);
 }
 
 private ApplicationComponent mComponent;
 
 @Override
 public void onCreate() {
 mComponent = DaggerBKUMAGirlsApplication_ApplicationComponent.builder()
 .bkumaModule(new BkumaModule(this))
 .build();
 }
 
 public ApplicationComponent component() {
 return mComponent;
 }
 }
  11. %BHHFS ࢖༻ྫ ςετ

  12. .PEVMF ςετ @Module
 public class BkumaTestModule {
 private final BkumaService

    mBkumaService; …
 public BkumaTestModule(InstrumentationTestCase instrumentationTestCase) { mBkumaService = new BkumaMockServiceProvider(mInstrumentationTestCase .getInstrumentation().getContext()).getService();
 }
 
 @Provides
 EntryManager provideEntryManager() {
 return new EntryManager(mBkumaService);
 } … 5FTU༻ #LVNB4FSWJDF
  13. ௨৴෦෼ʢςετʣ @Override
 public BkumaService getService() {
 RestAdapter restAdapter = new

    RestAdapter
 .Builder()
 .setEndpoint(BkumaService.END_POINT)
 .build();
 
 MockRestAdapter mockRestAdapter = MockRestAdapter.from(restAdapter);
 mockRestAdapter.setDelay(0); …(ଓ͖·͢) 5FTU༻.PDL
  14. ௨৴෦෼ʢςετʣ …
 BkumaService bkumaService = new BkumaService() {
 @Override
 public

    void getTopEntries(@Query("limit") int limit, Callback<List<EntryResponse>> callback) {
 callback.success( TestUtils.createDummyEntry(mContext, limit),
 createDummyJsonResponse()
 );
 } }); return mockRestAdapter.create( BkumaService.class, bkumaService ); %VNNZ 3FTQPOTF
  15. *OKFDU ςετ public class BkumaEntryManagerTest extends InstrumentationTestCase {
 …
 @Inject


    EntryManager mEntryManager;
 … public testGetEntries() { assertEquals( "ΤϯτϦऔಘͰ͖͍ͯΔ", false, mEntryManager.getEntries().isEmpty()); }
 }
  16. ·ͱΊ w ςελϒϧͳίʔυ͕࡞Γ΍͍͢ w *OTUBODF؅ཧ͕͠΍͘͢ͳΔ w "DUJWJUZͷ࠶ੜ੒࣌ͳͲʹޮ͍ͯ͘Δ

  17. ͋Γ͕ͱ͏͍͟͝·ͨ͠