Skip to content

Instantly share code, notes, and snippets.

View mohsenoid's full-sized avatar
:octocat:
What can go wrong?!

Mohsen Mirhoseini mohsenoid

:octocat:
What can go wrong?!
View GitHub Profile
@Singleton
@Provides
@Named("retryInterceptor")
public Interceptor provideRetryInterceptor(@Named("retryCount") int retryCount) {
return chain -> {
Request request = chain.request();
Response response = null;
IOException exception = null;
int tryCount = 0;
package com.mirhoseini.stylight.domain;
/*...*/
@Module
public class ClientModule {
/*...*/
@Singleton
@Provides
package com.mirhoseini.marvel.domain;
/*...*/
@Module
public class ApiModule {
@Provides
@Singleton
public MarvelApi provideMarvelApi(Retrofit retrofit) {
@Override
public void doSearch(boolean isConnected, String query, long timestamp) {
if (null != view) {
view.showProgress();
}
subscription = interactor.loadCharacter(query, Constants.PRIVATE_KEY, Constants.PUBLIC_KEY, timestamp)
// check if result code is OK
.map(charactersResponse -> {
if (Constants.CODE_OK == charactersResponse.getCode())
package com.mirhoseini.marvel.util;
import javax.inject.Inject;
import rx.Scheduler;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class AppSchedulerProvider implements SchedulerProvider {
@Inject
package com.mirhoseini.marvel.character.search;
/*...*/
import org.junit.Before;
import org.junit.Test;
import java.util.Collections;
import rx.Observable;
package com.mirhoseini.marvel.activity;
/*...*/
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, shadows = {ShadowSnackbar.class})
public class MainActivityRobolectricTest {
private final static String TEST_TEXT = "This is a test text.";
private MainActivity activity;
package com.mirhoseini.marvel;
/*...*/
public class MarvelTestRunner extends AndroidJUnitRunner {
@Override
public Application newApplication(ClassLoader classLoader, String className, Context context)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
// replace Application class with mock one
package com.mirhoseini.marvel;
/*...*/
public class MarvelTestApplication extends MarvelApplicationImpl {
@Override
public ApplicationTestComponent createComponent() {
return DaggerApplicationTestComponent
.builder()
package com.mirhoseini.marvel.activity;
/*...*/
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
private static final String TEST_CHARACTER_NAME = "Test Name";
private static final String TEST_CHARACTER_DESCRIPTION = "Test Description";
private static final String TEST_CHARACTER_THUMBNAIL_PATH = "Test Thumbnail";