1 /* 2 * Copyright (C) 2008 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 android.graphics.drawable.cts; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertFalse; 21 import static org.mockito.Mockito.reset; 22 import static org.mockito.Mockito.spy; 23 import static org.mockito.Mockito.times; 24 import static org.mockito.Mockito.verify; 25 26 import android.content.Context; 27 import android.content.res.Resources; 28 import android.graphics.drawable.Drawable; 29 import android.graphics.drawable.Drawable.ConstantState; 30 31 import androidx.test.InstrumentationRegistry; 32 import androidx.test.filters.SmallTest; 33 import androidx.test.runner.AndroidJUnit4; 34 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 38 @SmallTest 39 @RunWith(AndroidJUnit4.class) 40 public class Drawable_ConstantStateTest { 41 @Test 42 public void testNewDrawable() { 43 Context context = InstrumentationRegistry.getTargetContext(); 44 Resources resources = context.getResources(); 45 46 MockConstantState mock = spy(new MockConstantState()); 47 ConstantState cs = mock; 48 49 assertEquals(null, cs.newDrawable()); 50 verify(mock, times(1)).newDrawable(); 51 reset(mock); 52 53 assertEquals(null, cs.newDrawable(resources)); 54 verify(mock, times(1)).newDrawable(); 55 reset(mock); 56 57 assertEquals(null, cs.newDrawable(resources, context.getTheme())); 58 verify(mock, times(1)).newDrawable(); 59 reset(mock); 60 } 61 62 @Test 63 public void testCanApplyTheme() { 64 ConstantState cs = new MockConstantState(); 65 assertFalse(cs.canApplyTheme()); 66 } 67 68 public static class MockConstantState extends ConstantState { 69 @Override 70 public Drawable newDrawable() { 71 return null; 72 } 73 74 @Override 75 public int getChangingConfigurations() { 76 return 0; 77 } 78 } 79 } 80