Last active
July 3, 2017 07:59
-
-
Save piotrmadry/567697bb5606bc2c3434314ffea1c30e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestsApp extends App { | |
@Override | |
protected AppComponent initializeAppComponent() { | |
return DaggerAppComponent.builder() | |
.applicationModule(new MockApplicationModule(this)) | |
.databaseModule(new DatabaseModule()) | |
.networkModule(new MockNetworkModule()) | |
.picassoModule(new PicassoModule()) | |
.androidModule(new AndroidModule()) | |
.androidImplModule(new AndroidImplModule()) | |
.schedulersModule(new SchedulersModule()) | |
.daoModule(new DaoModule()) | |
.utilsModule(new UtilsModule()) | |
.build(); | |
} | |
@Module | |
private class MockApplicationModule extends ApplicationModule { | |
MockApplicationModule(@Nonnull final App app) { | |
super(app); | |
} | |
@Override | |
public AppPreferences appPreferences(@Dagger.ForApplication final Context context) { | |
final AppPreferences mock = Mockito.mock(AppPreferences.class); | |
when(mock.isUserValid()).thenReturn(true); | |
return mock; | |
} | |
} | |
@Module | |
private class MockNetworkModule extends NetworkModule { | |
@Override | |
public ApiService provideApiService(@Nonnull final Retrofit retrofit, | |
@Nonnull final Gson gson) { | |
return new ApiService() { | |
@Override | |
public Observable<UserResponse> user() { | |
return Observable.fromCallable((Func0<UserResponse>) () -> | |
gson.fromJson(TestUtils.getFromAssets(context, "user.json"), UserResponse.class)); | |
} | |
@Override | |
public Observable<LoginResponse> login(@Field("username") final String userName, | |
@Field("password") final String password, | |
@Field("scope") final String scope) { | |
return userName.equals("user123") ? | |
Observable.just(gson.fromJson(TestUtils.getFromAssets(context, "sing_in.json"), UserResponse.class)) : | |
Observable.error(new Throwable("Error")); | |
} | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment