1 /*
2  * Copyright (C) 2024 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.audio;
18 
19 import static org.junit.Assert.assertThrows;
20 
21 import android.car.test.AbstractExpectableTestCase;
22 
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.junit.MockitoJUnitRunner;
26 
27 @RunWith(MockitoJUnitRunner.class)
28 public final class CarActivationVolumeConfigTest extends AbstractExpectableTestCase {
29 
30     private static final int MIN_ACTIVATION_GAIN_INDEX_PERCENTAGE = 10;
31     private static final int MAX_ACTIVATION_GAIN_INDEX_PERCENTAGE = 90;
32     private static final int ACTIVATION_VOLUME_INVOCATION_TYPE =
33             CarActivationVolumeConfig.ACTIVATION_VOLUME_ON_BOOT;
34 
35     private static final CarActivationVolumeConfig CAR_ACTIVATION_VOLUME_CONFIG =
36             new CarActivationVolumeConfig(ACTIVATION_VOLUME_INVOCATION_TYPE,
37                     MIN_ACTIVATION_GAIN_INDEX_PERCENTAGE, MAX_ACTIVATION_GAIN_INDEX_PERCENTAGE);
38 
39     @Test
construct_withMinActivationVolumePercentageHigherThanMax()40     public void construct_withMinActivationVolumePercentageHigherThanMax() {
41         IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class,
42                 () -> new CarActivationVolumeConfig(ACTIVATION_VOLUME_INVOCATION_TYPE,
43                         MAX_ACTIVATION_GAIN_INDEX_PERCENTAGE,
44                         MIN_ACTIVATION_GAIN_INDEX_PERCENTAGE));
45 
46         expectWithMessage("Exception for min activation volume percentage higher than max")
47                 .that(thrown).hasMessageThat().contains("can not be higher than");
48     }
49 
50     @Test
getInvocationType()51     public void getInvocationType() {
52         expectWithMessage("Activation volume invocation type")
53                 .that(CAR_ACTIVATION_VOLUME_CONFIG.getInvocationType())
54                 .isEqualTo(ACTIVATION_VOLUME_INVOCATION_TYPE);
55     }
56 
57     @Test
getMinActivationVolumePercentage()58     public void getMinActivationVolumePercentage() {
59         expectWithMessage("Min activation volume percentage")
60                 .that(CAR_ACTIVATION_VOLUME_CONFIG.getMinActivationVolumePercentage())
61                 .isEqualTo(MIN_ACTIVATION_GAIN_INDEX_PERCENTAGE);
62     }
63 
64     @Test
getMaxActivationVolumePercentage()65     public void getMaxActivationVolumePercentage() {
66         expectWithMessage("Max activation volume percentage")
67                 .that(CAR_ACTIVATION_VOLUME_CONFIG.getMaxActivationVolumePercentage())
68                 .isEqualTo(MAX_ACTIVATION_GAIN_INDEX_PERCENTAGE);
69     }
70 }
71