This file contains hidden or 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
@Component(modules = ApplicationModule.class) | |
@Singleton | |
public interface ApplicationComponent { | |
DataManager getDataManager(); | |
} |
This file contains hidden or 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
@Singleton | |
public class DataManager { | |
private BaseApiManager mBaseApiManager; | |
@Inject | |
public DataManager(BaseApiManager baseApiManager) { | |
mBaseApiManager = baseApiManager; | |
} |
This file contains hidden or 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 MyTestingApp extends Application { | |
ApplicationComponent applicationComponent; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
} | |
public ApplicationComponent getComponent() { |
This file contains hidden or 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
@Module | |
public class ApplicationModule { | |
private Application mApplication; | |
public ApplicationModule(Application application) { | |
mApplication = application; | |
} | |
@Provides |
This file contains hidden or 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 UiTestApp extends MyTestingApp { | |
@Override | |
public ApplicationComponent getComponent() { | |
return DaggerApplicationComponent.builder() | |
.applicationModule(new TestApplicationModule(this)) | |
.build(); | |
} | |
} |
This file contains hidden or 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 MockRunner extends AndroidJUnitRunner { | |
@Override | |
public void onCreate(Bundle arguments) { | |
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); | |
super.onCreate(arguments); | |
} | |
@Override | |
public Application newApplication(ClassLoader cl, String className, Context context) |
This file contains hidden or 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
@Module | |
public class TestApplicationModule extends ApplicationModule { | |
public TestApplicationModule(Application application) { | |
super(application); | |
} | |
@Provides | |
@Singleton | |
public Retrofit getRetrofit(OkHttpClient client) { |
This file contains hidden or 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
@RunWith(AndroidJUnit4.class) | |
public class MainActivityTest { | |
@Rule | |
public ActivityTestRule<MainActivity> activityRule = | |
new ActivityTestRule<>(MainActivity.class,false,false); | |
private MockWebServer webServer; | |
@Before |
This file contains hidden or 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
@Test | |
public void retryButton() { | |
webServer.setDispatcher(new MockServerDispatcher().new ErrorDispatcher()); | |
activityRule.launchActivity(new Intent()); | |
Espresso.onView(withId(R.id.btRetry)).perform(click()); | |
Espresso.onView(withId(R.id.data)).check(matches(not(isDisplayed()))); | |
Espresso.onView(withId(R.id.errorUI)).check(matches((isDisplayed()))); | |
} |
This file contains hidden or 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
class MockServerDispatcher { | |
/** | |
* Return ok response from mock server | |
*/ | |
class RequestDispatcher extends Dispatcher { | |
@Override | |
public MockResponse dispatch(RecordedRequest request) { | |
if(request.getPath().equals("api/data")){ |
OlderNewer