urbanairship-core/src/test/java/com/urbanairship/iam/tags/TagGroupManagerTest.java
@Test
    public void testRefreshCache() {
        manager.setCacheMaxAgeTime(TagGroupManager.MIN_CACHE_MAX_AGE_TIME_MS, TimeUnit.MILLISECONDS);

        TagGroupResponse response = new TagGroupResponse(200, clientResponseTags, "lastModifiedTime");

        // Set up a response that returns all the tags
        when(mockClient.lookupTagGroups(channelId, UAirship.ANDROID_PLATFORM, getExpectedClientRequestTags(), null))
                .thenReturn(response);


        TagGroupResult result = manager.getTags(requestTags);
        assertTrue(result.success);

        verify(mockClient, times(1)).lookupTagGroups(channelId, UAirship.ANDROID_PLATFORM, getExpectedClientRequestTags(), null);

        // Time travel past the cache max age
        clock.currentTimeMillis += TagGroupManager.MIN_CACHE_MAX_AGE_TIME_MS + 1;

        // Set up a response that returns all the tags
        when(mockClient.lookupTagGroups(channelId, UAirship.ANDROID_PLATFORM, getExpectedClientRequestTags(), response))
                .thenReturn(response);

        // Fetch tag again
        result = manager.getTags(requestTags);
        assertTrue(result.success);

        // Verify the second call was made with the previous cached response
        verify(mockClient, times(1)).lookupTagGroups(channelId, UAirship.ANDROID_PLATFORM, getExpectedClientRequestTags(), response);
    }
/**
     * Test requesting tags will refresh the cache if its been longer than the max cache age.
     */
Test requesting tags will refresh the cache if its been longer than the max cache age.
Test requesting tags will refresh the cache if its been longer than the max cache age .
@Test
    public void testRefreshCache() {
        manager.setCacheMaxAgeTime(TagGroupManager.MIN_CACHE_MAX_AGE_TIME_MS, TimeUnit.MILLISECONDS);
        TagGroupResponse response = new TagGroupResponse(200, clientResponseTags, "lastModifiedTime");
        when(mockClient.lookupTagGroups(channelId, UAirship.ANDROID_PLATFORM, getExpectedClientRequestTags(), null))
                .thenReturn(response);
        TagGroupResult result = manager.getTags(requestTags);
        assertTrue(result.success);
        verify(mockClient, times(1)).lookupTagGroups(channelId, UAirship.ANDROID_PLATFORM, getExpectedClientRequestTags(), null);
        clock.currentTimeMillis += TagGroupManager.MIN_CACHE_MAX_AGE_TIME_MS + 1;
        when(mockClient.lookupTagGroups(channelId, UAirship.ANDROID_PLATFORM, getExpectedClientRequestTags(), response))
                .thenReturn(response);
        result = manager.getTags(requestTags);
        assertTrue(result.success);
        verify(mockClient, times(1)).lookupTagGroups(channelId, UAirship.ANDROID_PLATFORM, getExpectedClientRequestTags(), response);
    }
@ Test public void testRefreshCache ( ) { manager . setCacheMaxAgeTime ( TagGroupManager . MIN_CACHE_MAX_AGE_TIME_MS , TimeUnit . MILLISECONDS ) ; TagGroupResponse response = new TagGroupResponse ( 200 , clientResponseTags , "lastModifiedTime" ) ; when ( mockClient . lookupTagGroups ( channelId , UAirship . ANDROID_PLATFORM , getExpectedClientRequestTags ( ) , null ) ) . thenReturn ( response ) ; TagGroupResult result = manager . getTags ( requestTags ) ; assertTrue ( result . success ) ; verify ( mockClient , times ( 1 ) ) . lookupTagGroups ( channelId , UAirship . ANDROID_PLATFORM , getExpectedClientRequestTags ( ) , null ) ; clock . currentTimeMillis += TagGroupManager . MIN_CACHE_MAX_AGE_TIME_MS + 1 ; when ( mockClient . lookupTagGroups ( channelId , UAirship . ANDROID_PLATFORM , getExpectedClientRequestTags ( ) , response ) ) . thenReturn ( response ) ; result = manager . getTags ( requestTags ) ; assertTrue ( result . success ) ; verify ( mockClient , times ( 1 ) ) . lookupTagGroups ( channelId , UAirship . ANDROID_PLATFORM , getExpectedClientRequestTags ( ) , response ) ; }
Test requesting tags will refresh the cache if its been longer than the max cache age.
Test requesting tags will refresh the cache if its been longer than the max cache age .
// Set up a response that returns all the tags // Time travel past the cache max age // Set up a response that returns all the tags // Fetch tag again // Verify the second call was made with the previous cached response