Home | History | Annotate | Download | only in notification
      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.settings.notification;
     18 
     19 import static org.mockito.ArgumentMatchers.anyInt;
     20 import static org.mockito.Mockito.doCallRealMethod;
     21 import static org.mockito.Mockito.verify;
     22 import static org.mockito.Mockito.when;
     23 
     24 import android.content.Context;
     25 import android.media.AudioManager;
     26 
     27 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     28 
     29 import org.junit.Before;
     30 import org.junit.Test;
     31 import org.junit.runner.RunWith;
     32 import org.mockito.Mock;
     33 import org.mockito.MockitoAnnotations;
     34 
     35 @RunWith(SettingsRobolectricTestRunner.class)
     36 public class VolumeSeekBarPreferenceTest {
     37 
     38     @Mock
     39     private AudioManager mAudioManager;
     40     @Mock
     41     private VolumeSeekBarPreference mPreference;
     42     @Mock
     43     private Context mContext;
     44 
     45     @Before
     46     public void setUp() {
     47         MockitoAnnotations.initMocks(this);
     48         when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
     49         mPreference.mAudioManager = mAudioManager;
     50     }
     51 
     52     @Test
     53     public void setStream_shouldSetMinMaxAndProgress() {
     54         final int stream = 5;
     55         final int max = 17;
     56         final int min = 1;
     57         final int progress = 4;
     58         when(mAudioManager.getStreamMaxVolume(stream)).thenReturn(max);
     59         when(mAudioManager.getStreamMinVolumeInt(stream)).thenReturn(min);
     60         when(mAudioManager.getStreamVolume(stream)).thenReturn(progress);
     61         doCallRealMethod().when(mPreference).setStream(anyInt());
     62 
     63         mPreference.setStream(stream);
     64 
     65         verify(mPreference).setMax(max);
     66         verify(mPreference).setMin(min);
     67         verify(mPreference).setProgress(progress);
     68     }
     69 }
     70