1 /* 2 * Copyright (C) 2020 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.systemui.accessibility; 18 19 import static org.junit.Assert.assertNotEquals; 20 import static org.junit.Assert.assertNotNull; 21 22 import android.hardware.display.DisplayManager; 23 import android.testing.AndroidTestingRunner; 24 import android.view.Display; 25 26 import androidx.annotation.NonNull; 27 import androidx.test.filters.SmallTest; 28 29 import com.android.systemui.SysuiTestCase; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 35 @SmallTest 36 @RunWith(AndroidTestingRunner.class) 37 public class DisplayIdIndexSupplierTest extends SysuiTestCase { 38 39 private DisplayIdIndexSupplier<Object> mDisplayIdIndexSupplier; 40 41 @Before setUp()42 public void setUp() throws Exception { 43 mDisplayIdIndexSupplier = new DisplayIdIndexSupplier( 44 mContext.getSystemService(DisplayManager.class)) { 45 46 @NonNull 47 @Override 48 protected Object createInstance(Display display) { 49 return new Object(); 50 } 51 }; 52 } 53 54 @Test get_instanceIsNotNull()55 public void get_instanceIsNotNull() { 56 Object object = mDisplayIdIndexSupplier.get(Display.DEFAULT_DISPLAY); 57 assertNotNull(object); 58 } 59 60 @Test get_removeExistedObject_newObject()61 public void get_removeExistedObject_newObject() { 62 Object object = mDisplayIdIndexSupplier.get(Display.DEFAULT_DISPLAY); 63 mDisplayIdIndexSupplier.remove(Display.DEFAULT_DISPLAY); 64 65 Object newObject = mDisplayIdIndexSupplier.get(Display.DEFAULT_DISPLAY); 66 67 assertNotEquals(object, newObject); 68 } 69 70 @Test get_clearAllObjects_newObject()71 public void get_clearAllObjects_newObject() { 72 Object object = mDisplayIdIndexSupplier.get(Display.DEFAULT_DISPLAY); 73 mDisplayIdIndexSupplier.clear(); 74 75 Object newObject = mDisplayIdIndexSupplier.get(Display.DEFAULT_DISPLAY); 76 77 assertNotEquals(object, newObject); 78 } 79 } 80