|
| 1 | +/**************************************************************************** |
| 2 | + * Copyright 2017, Optimizely, Inc. and contributors * |
| 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.optimizely.ab.android.sdk; |
| 18 | + |
| 19 | +import android.app.UiModeManager; |
| 20 | +import android.content.Context; |
| 21 | +import android.content.res.Configuration; |
| 22 | +import android.os.Build; |
| 23 | +import android.support.annotation.RequiresApi; |
| 24 | +import android.support.test.runner.AndroidJUnit4; |
| 25 | + |
| 26 | +import com.optimizely.ab.event.internal.payload.Event; |
| 27 | + |
| 28 | +import org.junit.Test; |
| 29 | +import org.junit.runner.RunWith; |
| 30 | + |
| 31 | +import static junit.framework.Assert.assertEquals; |
| 32 | +import static org.mockito.Mockito.mock; |
| 33 | +import static org.mockito.Mockito.when; |
| 34 | + |
| 35 | +@RunWith(AndroidJUnit4.class) |
| 36 | +public class OptimizelyClientEngineTest { |
| 37 | + @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB_MR2) |
| 38 | + @Test |
| 39 | + public void testGetClientEngineFromContextAndroidTV() { |
| 40 | + Context context = mock(Context.class); |
| 41 | + UiModeManager uiModeManager = mock(UiModeManager.class); |
| 42 | + when(context.getSystemService(Context.UI_MODE_SERVICE)).thenReturn(uiModeManager); |
| 43 | + when(uiModeManager.getCurrentModeType()).thenReturn(Configuration.UI_MODE_TYPE_TELEVISION); |
| 44 | + assertEquals(Event.ClientEngine.ANDROID_TV_SDK, OptimizelyClientEngine.getClientEngineFromContext(context)); |
| 45 | + } |
| 46 | + |
| 47 | + @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB_MR2) |
| 48 | + @Test |
| 49 | + public void testGetClientEngineFromContextAndroid() { |
| 50 | + Context context = mock(Context.class); |
| 51 | + UiModeManager uiModeManager = mock(UiModeManager.class); |
| 52 | + when(context.getSystemService(Context.UI_MODE_SERVICE)).thenReturn(uiModeManager); |
| 53 | + when(uiModeManager.getCurrentModeType()).thenReturn(Configuration.UI_MODE_TYPE_NORMAL); |
| 54 | + assertEquals(Event.ClientEngine.ANDROID_SDK, OptimizelyClientEngine.getClientEngineFromContext(context)); |
| 55 | + } |
| 56 | +} |
0 commit comments