Android Open Source - mobile-connector-sdk-android Engage Expiration Parser Tests






From Project

Back to project page mobile-connector-sdk-android.

License

The source code is released under:

Apache License

If you think the Android project mobile-connector-sdk-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.silverpop.engage.util;
/* ww  w  .ja  v a 2 s  .c  o  m*/
import android.test.AndroidTestCase;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * Created by jeremydyer on 6/2/14.
 */
public class EngageExpirationParserTests
    extends AndroidTestCase {

    private Date beforeDate;

    protected void setUp() throws Exception {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.set(Calendar.YEAR, 2014);
        cal.set(Calendar.MONTH, 0);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        beforeDate = cal.getTime();
    }

    public void testEngageExpirationParserFullString () {
        EngageExpirationParser parser = new EngageExpirationParser("1 day 7 hours 23 minutes 15 seconds", beforeDate);

        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.setTime(parser.expirationDate());

        assertTrue(cal.get(Calendar.YEAR) == 2014);
        assertTrue(cal.get(Calendar.MONTH) == 0);
        assertTrue(cal.get(Calendar.DAY_OF_MONTH) == 2);
        assertTrue(cal.get(Calendar.HOUR_OF_DAY) == 7);
        assertTrue(cal.get(Calendar.MINUTE) == 23);
        assertTrue(cal.get(Calendar.SECOND) == 15);
    }

    public void testEngageExpirationParserFullStringAbr () {
        EngageExpirationParser parser = new EngageExpirationParser("1 d 7 h 23 m 15 s", beforeDate);

        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.setTime(parser.expirationDate());

        assertTrue(cal.get(Calendar.YEAR) == 2014);
        assertTrue(cal.get(Calendar.MONTH) == 0);
        assertTrue(cal.get(Calendar.DAY_OF_MONTH) == 2);
        assertTrue(cal.get(Calendar.HOUR_OF_DAY) == 7);
        assertTrue(cal.get(Calendar.MINUTE) == 23);
        assertTrue(cal.get(Calendar.SECOND) == 15);
    }

    public void testEngageExpirationParserDayOnly () {
        EngageExpirationParser parser = new EngageExpirationParser("1 d", beforeDate);

        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.setTime(parser.expirationDate());

        assertTrue(cal.get(Calendar.YEAR) == 2014);
        assertTrue(cal.get(Calendar.MONTH) == 0);
        assertTrue(cal.get(Calendar.DAY_OF_MONTH) == 2);
        assertTrue(cal.get(Calendar.HOUR_OF_DAY) == 0);
        assertTrue(cal.get(Calendar.MINUTE) == 0);
        assertTrue(cal.get(Calendar.SECOND) == 0);
    }

    public void testEngageExpirationParserHourOnly () {
        EngageExpirationParser parser = new EngageExpirationParser("14h", beforeDate);

        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.setTime(parser.expirationDate());

        assertTrue(cal.get(Calendar.YEAR) == 2014);
        assertTrue(cal.get(Calendar.MONTH) == 0);
        assertTrue(cal.get(Calendar.DAY_OF_MONTH) == 1);
        assertTrue(cal.get(Calendar.HOUR_OF_DAY) == 14);
        assertTrue(cal.get(Calendar.MINUTE) == 0);
        assertTrue(cal.get(Calendar.SECOND) == 0);
    }

    public void testEngageExpirationParserMinuteOnly () {
        EngageExpirationParser parser = new EngageExpirationParser("12m", beforeDate);

        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.setTime(parser.expirationDate());

        assertTrue(cal.get(Calendar.YEAR) == 2014);
        assertTrue(cal.get(Calendar.MONTH) == 0);
        assertTrue(cal.get(Calendar.DAY_OF_MONTH) == 1);
        assertTrue(cal.get(Calendar.HOUR_OF_DAY) == 0);
        assertTrue(cal.get(Calendar.MINUTE) == 12);
        assertTrue(cal.get(Calendar.SECOND) == 0);
    }

    public void testEngageExpirationParserSecondOnly () {
        EngageExpirationParser parser = new EngageExpirationParser("47 secs", beforeDate);

        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.setTime(parser.expirationDate());

        assertTrue(cal.get(Calendar.YEAR) == 2014);
        assertTrue(cal.get(Calendar.MONTH) == 0);
        assertTrue(cal.get(Calendar.DAY_OF_MONTH) == 1);
        assertTrue(cal.get(Calendar.HOUR_OF_DAY) == 0);
        assertTrue(cal.get(Calendar.MINUTE) == 0);
        assertTrue(cal.get(Calendar.SECOND) == 47);
    }

    public void testEngageExpirationParserMinuteRollover () {
        EngageExpirationParser parser = new EngageExpirationParser("67 mins 47s", beforeDate);

        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.setTime(parser.expirationDate());

        assertTrue(cal.get(Calendar.YEAR) == 2014);
        assertTrue(cal.get(Calendar.MONTH) == 0);
        assertTrue(cal.get(Calendar.DAY_OF_MONTH) == 1);
        assertTrue(cal.get(Calendar.HOUR_OF_DAY) == 1);
        assertTrue(cal.get(Calendar.MINUTE) == 7);
        assertTrue(cal.get(Calendar.SECOND) == 47);
    }

    public void testEngageExpirationParserExpiresAtDate () {
        EngageExpirationParser parser = new EngageExpirationParser("2014/02/14 16:25:43 ", beforeDate);

        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.setTime(parser.expirationDate());

        assertTrue(cal.get(Calendar.YEAR) == 2014);
        assertTrue(cal.get(Calendar.MONTH) == 1);
        assertTrue(cal.get(Calendar.DAY_OF_MONTH) == 14);
        assertTrue(cal.get(Calendar.HOUR_OF_DAY) == 16);
        assertTrue(cal.get(Calendar.MINUTE) == 25);
        assertTrue(cal.get(Calendar.SECOND) == 43);
    }


}




Java Source Code List

com.silverpop.engage.EngageApplication.java
com.silverpop.engage.UBFManager.java
com.silverpop.engage.XMLAPIManager.java
com.silverpop.engage.augmentation.UBFAugmentationServiceImpl.java
com.silverpop.engage.augmentation.UBFAugmentationService.java
com.silverpop.engage.augmentation.plugin.UBFAddressAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFCoordinatesAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFLocationNameAugmentationPlugin.java
com.silverpop.engage.config.EngageConfigManagerTests.java
com.silverpop.engage.config.EngageConfigManager.java
com.silverpop.engage.config.EngageConfigTest.java
com.silverpop.engage.config.EngageConfig.java
com.silverpop.engage.deeplinking.EngageDeepLinkManager.java
com.silverpop.engage.demo.engagetest.Application.java
com.silverpop.engage.demo.engagetest.EngageNotificationReceiver.java
com.silverpop.engage.demo.engagetest.MainActivity.java
com.silverpop.engage.demo.engagetest.PushReceiver.java
com.silverpop.engage.demo.engagetest.fragment.EngageConfigFragment.java
com.silverpop.engage.demo.engagetest.fragment.UBFAPIFragment.java
com.silverpop.engage.demo.engagetest.fragment.XMLAPIFragment.java
com.silverpop.engage.domain.EngageEvent.java
com.silverpop.engage.domain.JSONable.java
com.silverpop.engage.domain.UBFTests.java
com.silverpop.engage.domain.UBF.java
com.silverpop.engage.domain.XMLAPIEnum.java
com.silverpop.engage.domain.XMLAPITest.java
com.silverpop.engage.domain.XMLAPI.java
com.silverpop.engage.exception.XMLResponseParseException.java
com.silverpop.engage.location.manager.EngageLocationManager.java
com.silverpop.engage.location.manager.plugin.EngageLocationManagerDefault.java
com.silverpop.engage.location.receiver.EngageLocationReceiver.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverBase.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverGeocode.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverHardcodeTest.java
com.silverpop.engage.network.Credential.java
com.silverpop.engage.network.EngageClient.java
com.silverpop.engage.network.RequestCacheWrapper.java
com.silverpop.engage.network.UBFClient.java
com.silverpop.engage.network.XMLAPIClient.java
com.silverpop.engage.response.EngageResponseXMLTests.java
com.silverpop.engage.response.EngageResponseXML.java
com.silverpop.engage.response.XMLAPIResponseNode.java
com.silverpop.engage.store.EngageLocalEventStoreTest.java
com.silverpop.engage.store.EngageLocalEventStore.java
com.silverpop.engage.store.EngageSQLiteHelper.java
com.silverpop.engage.util.EngageExpirationParserTests.java
com.silverpop.engage.util.EngageExpirationParser.java
com.silverpop.engage.util.TimedAsyncTask.java