Share
Embed
Transcript
35 slides
-
खಈ%*ͷ w ґଘؔΛखಈͰཧ͢Δ͜ͱʹͳΔ w ґଘΛ"DUJWJUZ͔Β"DUJWJUZؾΛ͚ͭͯ͢ ࣄʹͳΔ Intent intent = new
Intent(context, BookmarkActivity.class); intent.putExtra(Intent.EXTRA_API_CLIENT, mAPIClient); startActivity(intent); -
3FUSPpU w 4RVBSF3&45ΫϥΠΞϯτϥΠϒϥϦ w JOUFSGBDFΛఆٛ͢Δͱ࣮ͯ͘͠ΕΔ public interface GitHubService { @GET("/users/{user}/repos")
List<Repo> listRepos(@Path("user") String user); } -
௨৴෦ 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); } … -
.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); } … -
$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; } } -
௨৴෦ʢςετʣ @Override public BkumaService getService() { RestAdapter restAdapter = new
RestAdapter .Builder() .setEndpoint(BkumaService.END_POINT) .build(); MockRestAdapter mockRestAdapter = MockRestAdapter.from(restAdapter); mockRestAdapter.setDelay(0); …(ଓ͖·͢) -
௨৴෦ʢςετʣ … 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 ); -
.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); } … -
*OKFDUΛ͢Δ ςετ public class BkumaEntryManagerTest extends InstrumentationTestCase { … @Inject
EntryManager mEntryManager; … public testGetEntries() { assertEquals( "ΤϯτϦऔಘͰ͖͍ͯΔ", false, mEntryManager.getEntries().isEmpty()); } } -
&OUSZ.BOBHFSͷΩϟογϡ public class EntryManagerProvider { private final int MAX_SIZE =
4; private final LruCache<String, EntryManager> mCache = new LruCache<>(MAX_SIZE); … } -
&OUSZ.BOBHFSͷΩϟογϡ public EntryManager getEntryManager(@NonNull String key) { EntryManager entryManager; entryManager
= mCache.get(key); if (entryManager == null) { entryManager = new EntryManager(mBkumaService); mCache.put(key, entryManager); } return entryManager; }