Created
March 16, 2016 23:34
-
-
Save patrykpoborca/c17ecad34faac58fd7f6 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 ExampleUnitTest { | |
private boolean mResponseCached = false | |
public void testCachingStrategy(){ | |
MockManagerDelegate mockDelegate = new MockManagerDelegate(); | |
ApplicationFactory.setInstance(mockDelegate); | |
mockDelegate.setCachingManager(new CachingManager(){ | |
@Override | |
void cacheSimpleResponse(Response response) { | |
mResponseCached = true; | |
} | |
}); | |
MyViewModel testingModel = new MyViewModel(); | |
testingModel.retrieveSomeValue("someValue"); | |
Assert.assertTrue(mResponseCached); | |
} | |
public class MyViewModel { | |
private Retrofit retrofit = ApplicationFactory.getRetrofitClient(); | |
private ManagerDelegate managerDelegate = ApplicationFactory.getManagerDelegateImpl(); | |
private Observable<Response> retrieveSomeValue(String param) { | |
RetrofitClient client = retrofit.create(RetrofitClient.class); | |
Observable<Response> request = client.doRequest(param); | |
request.subscribe(response ->{ | |
managerDelegate.getCachingManager().cacheSimpleResponse(response); | |
}); | |
//by returning the "promise" of this network request we can allow some other component of the app to do the routing for us. | |
return request; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment