Home | History | Annotate | Download | only in targetprep
      1 /*
      2  * Copyright (C) 2017 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.tradefed.targetprep;
     18 
     19 import com.android.tradefed.build.IBuildInfo;
     20 import com.android.tradefed.config.OptionSetter;
     21 import com.android.tradefed.device.ITestDevice;
     22 
     23 import org.easymock.EasyMock;
     24 import org.junit.Before;
     25 import org.junit.Test;
     26 import org.junit.runner.RunWith;
     27 import org.junit.runners.JUnit4;
     28 
     29 import java.util.Date;
     30 import java.util.concurrent.TimeUnit;
     31 
     32 /** Unit Tests for {@link TimeSetterTargetPreparer}. */
     33 @RunWith(JUnit4.class)
     34 public class TimeSetterTargetPreparerTest {
     35     private TimeSetterTargetPreparer mTimeSetterTargetPreparer;
     36     private ITestDevice mMockDevice;
     37     private IBuildInfo mMockBuildInfo;
     38     private long mMockNanoTime;
     39 
     40     @Before
     41     public void setUp() {
     42         mMockDevice = EasyMock.createMock(ITestDevice.class);
     43         mMockBuildInfo = EasyMock.createMock(IBuildInfo.class);
     44         mTimeSetterTargetPreparer =
     45                 new TimeSetterTargetPreparer() {
     46                     @Override
     47                     long getNanoTime() {
     48                         return mMockNanoTime;
     49                     }
     50                 };
     51     }
     52 
     53     @Test
     54     public void testSaveTime() throws Exception {
     55         OptionSetter optionSetter = new OptionSetter(mTimeSetterTargetPreparer);
     56         optionSetter.setOptionValue("time", "555");
     57 
     58         EasyMock.expect(mMockDevice.getDeviceDate()).andReturn(123L).once();
     59         mMockDevice.setDate(new Date(555L));
     60         EasyMock.expectLastCall().once();
     61         mMockDevice.setDate(new Date(128L));
     62         EasyMock.expectLastCall().once();
     63 
     64         EasyMock.replay(mMockDevice, mMockBuildInfo);
     65 
     66         mMockNanoTime = TimeUnit.MILLISECONDS.toNanos(2);
     67         mTimeSetterTargetPreparer.setUp(mMockDevice, mMockBuildInfo);
     68         mMockNanoTime = TimeUnit.MILLISECONDS.toNanos(7);
     69         mTimeSetterTargetPreparer.tearDown(mMockDevice, mMockBuildInfo, null);
     70         EasyMock.verify(mMockBuildInfo, mMockDevice);
     71     }
     72 }
     73