blob: 239d413c12d23a7640e544c45cd6103c3ba9fa3f [file] [log] [blame]
Neil Fuller24836bf2018-06-08 18:44:49 +01001/*
2 * Copyright (C) 2018 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
17package com.android.server.timedetector;
18
19import static org.junit.Assert.assertEquals;
20
Neil Fuller24836bf2018-06-08 18:44:49 +010021import android.util.TimestampedValue;
22
Brett Chabota26eda92018-07-23 13:08:30 -070023import androidx.test.runner.AndroidJUnit4;
24
Neil Fuller24836bf2018-06-08 18:44:49 +010025import org.junit.Test;
26import org.junit.runner.RunWith;
27
28@RunWith(AndroidJUnit4.class)
29public class TimeDetectorStrategyTest {
30
31 @Test
32 public void testGetTimeAt() {
33 long timeMillis = 1000L;
34 int referenceTimeMillis = 100;
35 TimestampedValue<Long> timestampedValue =
36 new TimestampedValue<>(referenceTimeMillis, timeMillis);
37 // Reference time is after the timestamp.
38 assertEquals(
39 timeMillis + (125 - referenceTimeMillis),
40 TimeDetectorStrategy.getTimeAt(timestampedValue, 125));
41
42 // Reference time is before the timestamp.
43 assertEquals(
44 timeMillis + (75 - referenceTimeMillis),
45 TimeDetectorStrategy.getTimeAt(timestampedValue, 75));
46 }
47}