GithubHelp home page GithubHelp logo

adavis / adept-android Goto Github PK

View Code? Open in Web Editor NEW
130.0 13.0 46.0 752 KB

Source code for Developing High Quality Android Applications.

Home Page: http://goo.gl/xuIOvv

Java 100.00%
android quality-android-applications

adept-android's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adept-android's Issues

Retrofit + OkHTTP - response cache not working

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(); }

Question: Clarification on use of ArgumentCaptor: captor.getValue().onResponse(null, res)

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.

cache not woking when offline

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.