1 /* 2 * Copyright (C) 2023 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 android.media.AudioDeviceInfo.TYPE_BUS; 20 21 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 22 23 import static org.mockito.Mockito.when; 24 25 import android.media.AudioDeviceAttributes; 26 27 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 28 29 import org.mockito.Mockito; 30 31 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 32 public final class TestCarAudioDeviceInfoBuilder { 33 public static final int STEP_VALUE = 2; 34 public static final int MIN_GAIN = 3; 35 public static final int MAX_GAIN = 20; 36 public static final int DEFAULT_GAIN = 9; 37 38 private final String mAddress; 39 40 private int mStepValue = STEP_VALUE; 41 private int mDefaultGain = DEFAULT_GAIN; 42 private int mMinGain = MIN_GAIN; 43 private int mMaxGain = MAX_GAIN; 44 private boolean mIsActive = true; 45 46 private int mType = TYPE_BUS; 47 TestCarAudioDeviceInfoBuilder(String address)48 TestCarAudioDeviceInfoBuilder(String address) { 49 mAddress = address; 50 } 51 setStepValue(int stepValue)52 TestCarAudioDeviceInfoBuilder setStepValue(int stepValue) { 53 mStepValue = stepValue; 54 return this; 55 } 56 setDefaultGain(int defaultGain)57 TestCarAudioDeviceInfoBuilder setDefaultGain(int defaultGain) { 58 mDefaultGain = defaultGain; 59 return this; 60 } 61 setMinGain(int minGain)62 TestCarAudioDeviceInfoBuilder setMinGain(int minGain) { 63 mMinGain = minGain; 64 return this; 65 } 66 setMaxGain(int maxGain)67 TestCarAudioDeviceInfoBuilder setMaxGain(int maxGain) { 68 mMaxGain = maxGain; 69 return this; 70 } 71 setIsActive(boolean isActive)72 TestCarAudioDeviceInfoBuilder setIsActive(boolean isActive) { 73 mIsActive = isActive; 74 return this; 75 } 76 setType(int type)77 TestCarAudioDeviceInfoBuilder setType(int type) { 78 mType = type; 79 return this; 80 } 81 build()82 CarAudioDeviceInfo build() { 83 AudioDeviceAttributes attributeMock = Mockito.mock(AudioDeviceAttributes.class); 84 when(attributeMock.getAddress()).thenReturn(mAddress); 85 when(attributeMock.getType()).thenReturn(mType); 86 CarAudioDeviceInfo infoMock = Mockito.mock(CarAudioDeviceInfo.class); 87 when(infoMock.getStepValue()).thenReturn(mStepValue); 88 when(infoMock.getDefaultGain()).thenReturn(mDefaultGain); 89 when(infoMock.getMaxGain()).thenReturn(mMaxGain); 90 when(infoMock.getMinGain()).thenReturn(mMinGain); 91 when(infoMock.getAddress()).thenReturn(mAddress); 92 when(infoMock.getAudioDevice()).thenReturn(attributeMock); 93 when(infoMock.isActive()).thenReturn(mIsActive); 94 return infoMock; 95 } 96 } 97