1 /* 2 * Copyright (C) 2022 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.car.telemetry.sessioncontroller; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.os.PersistableBundle; 22 23 import com.android.car.telemetry.publisher.Constants; 24 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 import org.mockito.junit.MockitoJUnitRunner; 28 29 @RunWith(MockitoJUnitRunner.class) 30 public class SessionAnnotationUnitTest { 31 private static final int SESSION_ID = 1; 32 private static final int SESSION_STATE = SessionController.STATE_ENTER_DRIVING_SESSION; 33 private static final long CREATED_AT_SINCE_BOOT_MILLIS = 123; 34 private static final long CREATED_AT_MILLIS = 123123; 35 private static final String BOOT_REASON = "reboot"; 36 private static final int BOOT_COUNT = 12; 37 38 private static final SessionAnnotation sAnnotation = new SessionAnnotation(SESSION_ID, 39 SESSION_STATE, 40 CREATED_AT_SINCE_BOOT_MILLIS, CREATED_AT_MILLIS, BOOT_REASON, BOOT_COUNT); 41 42 @Test testAddAnnotationsToBundle_addsPopulatedBundle()43 public void testAddAnnotationsToBundle_addsPopulatedBundle() { 44 PersistableBundle data = new PersistableBundle(); 45 46 sAnnotation.addAnnotationsToBundle(data); 47 48 assertThat(data.getInt(Constants.ANNOTATION_BUNDLE_KEY_SESSION_ID)).isEqualTo( 49 SESSION_ID); 50 assertThat(data.getInt(Constants.ANNOTATION_BUNDLE_KEY_SESSION_STATE)).isEqualTo( 51 SESSION_STATE); 52 assertThat(data.getLong( 53 Constants.ANNOTATION_BUNDLE_KEY_CREATED_AT_SINCE_BOOT_MILLIS)).isEqualTo( 54 CREATED_AT_SINCE_BOOT_MILLIS); 55 assertThat( 56 data.getLong(Constants.ANNOTATION_BUNDLE_KEY_CREATED_AT_MILLIS)).isEqualTo( 57 CREATED_AT_MILLIS); 58 assertThat(data.getString(Constants.ANNOTATION_BUNDLE_KEY_BOOT_REASON)).isEqualTo( 59 BOOT_REASON); 60 assertThat(data.getInt(Constants.ANNOTATION_BUNDLE_KEY_BOOT_COUNT)).isEqualTo( 61 BOOT_COUNT); 62 } 63 } 64