Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.contacts.common.util;
     18 
     19 import junit.framework.TestCase;
     20 
     21 import android.test.suitebuilder.annotation.SmallTest;
     22 import android.text.format.Time;
     23 
     24 /**
     25  * Unit tests for {@link com.android.contacts.common.util.DateUtils}.
     26  */
     27 @SmallTest
     28 public class DateUtilTests extends TestCase {
     29 
     30     /**
     31      * Test date differences which are in the same day.
     32      */
     33     public void testDayDiffNone() {
     34         Time time = new Time();
     35         long date1 = System.currentTimeMillis();
     36         long date2 = System.currentTimeMillis() + android.text.format.DateUtils.HOUR_IN_MILLIS;
     37         assertEquals(0, DateUtils.getDayDifference(time, date1, date2));
     38         assertEquals(0, DateUtils.getDayDifference(time, date2, date1));
     39     }
     40 
     41     /**
     42      * Test date differences which are a day apart.
     43      */
     44     public void testDayDiffOne() {
     45         Time time = new Time();
     46         long date1 = System.currentTimeMillis();
     47         long date2 = date1 + android.text.format.DateUtils.DAY_IN_MILLIS;
     48         assertEquals(1, DateUtils.getDayDifference(time, date1, date2));
     49         assertEquals(1, DateUtils.getDayDifference(time, date2, date1));
     50     }
     51 
     52     /**
     53      * Test date differences which are two days apart.
     54      */
     55     public void testDayDiffTwo() {
     56         Time time = new Time();
     57         long date1 = System.currentTimeMillis();
     58         long date2 = date1 + 2*android.text.format.DateUtils.DAY_IN_MILLIS;
     59         assertEquals(2, DateUtils.getDayDifference(time, date1, date2));
     60         assertEquals(2, DateUtils.getDayDifference(time, date2, date1));
     61     }
     62 }
     63