adavis / adept-android Goto Github PK
View Code? Open in Web Editor NEWSource code for Developing High Quality Android Applications.
Home Page: http://goo.gl/xuIOvv
Source code for Developing High Quality Android Applications.
Home Page: http://goo.gl/xuIOvv
In this class :
https://github.com/adavis/adept-android/blob/retrofit2-cache/app/src/main/java/info/adavis/adeptandroid/di/Injector.java
It doesn't explicitly set the public
directive in the Cache-Control
header. Isn't this necessary to get caching to work properly in offline mode?
This implementation worked correctly to cache file to get from S3 using picasso and okhttp but it will not worked in case of POST request..
private Interceptor provideCacheInterceptor() {
return new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
// re-write response header to force use of cache
CacheControl cacheControl = new CacheControl.Builder().maxAge(2, TimeUnit.MINUTES).build();
return response.newBuilder().header(CACHE_CONTROL, cacheControl.toString()).build();
}
};
}
private Interceptor provideOfflineCacheInterceptor() {
return new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (!MyApplication.hasNetwork()) {
CacheControl cacheControl = new CacheControl.Builder().maxStale(7, TimeUnit.DAYS).build();
request = request.newBuilder().cacheControl(cacheControl).build();
}
return chain.proceed(request);
}
};
Here is the code of my OkHttpClient
@Provides public OkHttpClient okHttpClient(Cache cache, HttpLoggingInterceptor httpLoggingInterceptor, CustomInterceptors customInterceptors) { return new OkHttpClient().newBuilder().readTimeout(50, TimeUnit.SECONDS).writeTimeout(55, TimeUnit.SECONDS).connectTimeout(50, TimeUnit.SECONDS).cache(cache).addInterceptor(httpLoggingInterceptor) .addInterceptor(provideOfflineCacheInterceptor()).addNetworkInterceptor(provideCacheInterceptor()).build(); }
branch: retrofit2-testing
file link: https://github.com/adavis/adept-android/blob/retrofit2-testing/app/src/test/java/info/adavis/adeptandroid/books/books/BooksPresenterTest.java
I have been learning unit testing (Junit, Mockito) for a couple of months now. Found this repo while going through one of the videos on testing retrofit on caster.io. As caster.io is going to be closed soon(received an email regarding the same), so I thought of asking my question here.
My question is regarding ArgumentCaptor.
verify( mockCall ).enqueue( argumentCapture.capture() ); //Line 64
argumentCapture.getValue().onResponse( null, res ); //Line 65
I was going through some examples on StackOverflow and other articles and I couldn't found any example which uses ArgumentCaptor the way it is used here. Here, we are calling a method onResponse()
on captor.getValue()
(passing null
and res
as arguments to onResponse()
). Generally assertions are done on captor.getValue()
something like assertEquals("expected value", captor.getValue())
. Please correct me if I am wrong here.
I am not saying the way captor.getValue()
being used here(calling a method on captor.getValue()
) is wrong. I am just not sure whether ArgumentCaptor provides this additional capability also where you can pass the desired arguments to a function and later assert the behaviour of the test objects. I thought you can just capture the arguments with ArgumentCaptors and can only do assertion on them.
i try to create cache in retrofit2 like your code,
but cache not working when offline mode and max-age interceptor online set "0", because i want data always updated when online mode, can you help me solution about it ?
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.