Created
February 16, 2017 15:48
-
-
Save dkhmelenko/e6231621113dee31254110fa12ceed66 to your computer and use it in GitHub Desktop.
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 Presenter { | |
private final NetworkApi api; | |
public Presenter(NetworkApi api) { | |
this.api = api; | |
} | |
public void loadData() { | |
view.showProgress(true); | |
api.loadData() | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(userProfile -> { | |
view.showProgress(false); | |
view.showUserProfile(userProfile); | |
}); | |
} | |
} |
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 TestPresenter { | |
private Presenter underTest; | |
private View mockView; | |
private NetworkApi mockNetworkApi; | |
private FileDataProvider fileReader = new FileDataProvider(); | |
@Before | |
public void setup() throws Exception { | |
mockView = mock(View.class); | |
mockNetworkApi = mock(NetworkApi.class); | |
underTest = new Presenter(mockNetworkApi, mockView); | |
RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() { | |
@Override | |
public Scheduler getMainThreadScheduler() { | |
return Schedulers.immediate(); | |
} | |
}); | |
RxJavaHooks.setOnIOScheduler(scheduler -> Schedulers.immediate()); | |
} | |
@After | |
public void tearDown() { | |
RxJavaHooks.reset(); | |
RxAndroidPlugins.getInstance().reset(); | |
} | |
@Test | |
public void testLoadData () throws IOException { | |
UserProfile response = fileReader.readUserProfile(); | |
when(mockNetworkApi.loadData()).thenReturn(Observable.just(response)); | |
underTest.loadData(); | |
verify(mockView).showUserProfile(any(UserProfile.class)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment