From 3751be0f1cf608ce8384ef1efcd1bf6cb554ef15 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 13 Nov 2020 13:48:51 -0800 Subject: [PATCH] Removing obsolete shadows Change-Id: I9dcaa69e4e86130642be15e3585f5898dd866839 --- .../config/robolectric.properties | 5 -- .../launcher3/model/BackupRestoreTest.java | 4 +- .../LShadowApplicationPackageManager.java | 36 ------------ .../launcher3/shadows/LShadowBitmap.java | 36 ------------ .../launcher3/shadows/LShadowTypeface.java | 38 ------------- .../launcher3/shadows/LShadowUserManager.java | 53 ------------------ .../shadows/LShadowWallpaperManager.java | 56 ------------------- .../util/LauncherTestApplication.java | 4 -- 8 files changed, 2 insertions(+), 230 deletions(-) delete mode 100644 robolectric_tests/src/com/android/launcher3/shadows/LShadowApplicationPackageManager.java delete mode 100644 robolectric_tests/src/com/android/launcher3/shadows/LShadowBitmap.java delete mode 100644 robolectric_tests/src/com/android/launcher3/shadows/LShadowTypeface.java delete mode 100644 robolectric_tests/src/com/android/launcher3/shadows/LShadowUserManager.java delete mode 100644 robolectric_tests/src/com/android/launcher3/shadows/LShadowWallpaperManager.java diff --git a/robolectric_tests/config/robolectric.properties b/robolectric_tests/config/robolectric.properties index a8e0cb3acd..4e811f36ff 100644 --- a/robolectric_tests/config/robolectric.properties +++ b/robolectric_tests/config/robolectric.properties @@ -1,15 +1,10 @@ sdk=29 shadows= \ - com.android.launcher3.shadows.LShadowApplicationPackageManager \ com.android.launcher3.shadows.LShadowAppPredictionManager \ com.android.launcher3.shadows.LShadowAppWidgetManager \ com.android.launcher3.shadows.LShadowBackupManager \ - com.android.launcher3.shadows.LShadowBitmap \ com.android.launcher3.shadows.LShadowDisplay \ com.android.launcher3.shadows.LShadowLauncherApps \ - com.android.launcher3.shadows.LShadowTypeface \ - com.android.launcher3.shadows.LShadowUserManager \ - com.android.launcher3.shadows.LShadowWallpaperManager \ com.android.launcher3.shadows.ShadowDeviceFlag \ com.android.launcher3.shadows.ShadowLooperExecutor \ com.android.launcher3.shadows.ShadowMainThreadInitializedObject \ diff --git a/robolectric_tests/src/com/android/launcher3/model/BackupRestoreTest.java b/robolectric_tests/src/com/android/launcher3/model/BackupRestoreTest.java index 90313abe1d..8baf5a3f27 100644 --- a/robolectric_tests/src/com/android/launcher3/model/BackupRestoreTest.java +++ b/robolectric_tests/src/com/android/launcher3/model/BackupRestoreTest.java @@ -41,7 +41,6 @@ import android.os.UserManager; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.provider.RestoreDbTask; import com.android.launcher3.shadows.LShadowBackupManager; -import com.android.launcher3.shadows.LShadowUserManager; import com.android.launcher3.util.LauncherModelHelper; import org.junit.Before; @@ -51,6 +50,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.LooperMode; import org.robolectric.shadow.api.Shadow; +import org.robolectric.shadows.ShadowUserManager; /** * Tests to verify backup and restore flow. @@ -68,7 +68,7 @@ public class BackupRestoreTest { private static final int FLAG_SYSTEM = 0x00000800; private static final int FLAG_PROFILE = 0x00001000; - private LShadowUserManager mUserManager; + private ShadowUserManager mUserManager; private BackupManager mBackupManager; private LauncherModelHelper mModelHelper; private SQLiteDatabase mDb; diff --git a/robolectric_tests/src/com/android/launcher3/shadows/LShadowApplicationPackageManager.java b/robolectric_tests/src/com/android/launcher3/shadows/LShadowApplicationPackageManager.java deleted file mode 100644 index da8b91986f..0000000000 --- a/robolectric_tests/src/com/android/launcher3/shadows/LShadowApplicationPackageManager.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3.shadows; - -import android.os.Process; -import android.os.UserHandle; - -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.shadows.ShadowApplicationPackageManager; - -/** - * Shadow for {@link ShadowApplicationPackageManager} which create mock predictors - */ -@Implements(className = "android.app.ApplicationPackageManager") -public class LShadowApplicationPackageManager extends ShadowApplicationPackageManager { - - @Implementation - public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { - return Process.myUserHandle().equals(user) ? label : "Work " + label; - } -} diff --git a/robolectric_tests/src/com/android/launcher3/shadows/LShadowBitmap.java b/robolectric_tests/src/com/android/launcher3/shadows/LShadowBitmap.java deleted file mode 100644 index abd90bb8f6..0000000000 --- a/robolectric_tests/src/com/android/launcher3/shadows/LShadowBitmap.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3.shadows; - -import android.graphics.Bitmap; -import android.graphics.Paint; - -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.shadows.ShadowBitmap; - -/** - * Extension of {@link ShadowBitmap} with missing shadow methods - */ -@Implements(value = Bitmap.class) -public class LShadowBitmap extends ShadowBitmap { - - @Implementation - protected Bitmap extractAlpha(Paint paint, int[] offsetXY) { - return extractAlpha(); - } -} diff --git a/robolectric_tests/src/com/android/launcher3/shadows/LShadowTypeface.java b/robolectric_tests/src/com/android/launcher3/shadows/LShadowTypeface.java deleted file mode 100644 index 0e7c1deba0..0000000000 --- a/robolectric_tests/src/com/android/launcher3/shadows/LShadowTypeface.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.launcher3.shadows; - -import android.graphics.Typeface; - -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.shadows.ShadowTypeface; - -/** - * Extension of {@link ShadowTypeface} with missing shadow methods - */ -@Implements(Typeface.class) -public class LShadowTypeface extends ShadowTypeface { - - @Implementation - public static Typeface create(Typeface family, int weight, boolean italic) { - int style = italic ? Typeface.ITALIC : Typeface.NORMAL; - if (weight >= 400) { - style |= Typeface.BOLD; - } - return create(family, style); - } -} diff --git a/robolectric_tests/src/com/android/launcher3/shadows/LShadowUserManager.java b/robolectric_tests/src/com/android/launcher3/shadows/LShadowUserManager.java deleted file mode 100644 index edf8edbb43..0000000000 --- a/robolectric_tests/src/com/android/launcher3/shadows/LShadowUserManager.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3.shadows; - -import android.os.UserHandle; -import android.os.UserManager; -import android.util.SparseBooleanArray; - -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.shadows.ShadowUserManager; - -/** - * Extension of {@link ShadowUserManager} with missing shadow methods - */ -@Implements(value = UserManager.class) -public class LShadowUserManager extends ShadowUserManager { - - private final SparseBooleanArray mQuietUsers = new SparseBooleanArray(); - private final SparseBooleanArray mLockedUsers = new SparseBooleanArray(); - - @Implementation - protected boolean isQuietModeEnabled(UserHandle userHandle) { - return mQuietUsers.get(userHandle.hashCode()); - } - - public void setQuietModeEnabled(UserHandle userHandle, boolean enabled) { - mQuietUsers.put(userHandle.hashCode(), enabled); - } - - @Implementation - protected boolean isUserUnlocked(UserHandle userHandle) { - return !mLockedUsers.get(userHandle.hashCode()); - } - - public void setUserLocked(UserHandle userHandle, boolean enabled) { - mLockedUsers.put(userHandle.hashCode(), enabled); - } -} diff --git a/robolectric_tests/src/com/android/launcher3/shadows/LShadowWallpaperManager.java b/robolectric_tests/src/com/android/launcher3/shadows/LShadowWallpaperManager.java deleted file mode 100644 index d60251c901..0000000000 --- a/robolectric_tests/src/com/android/launcher3/shadows/LShadowWallpaperManager.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3.shadows; - -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; - -import android.app.WallpaperManager; -import android.content.Context; - -import org.robolectric.RuntimeEnvironment; -import org.robolectric.Shadows; -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.shadows.ShadowApplication; -import org.robolectric.shadows.ShadowUserManager; -import org.robolectric.shadows.ShadowWallpaperManager; - -/** - * Extension of {@link ShadowUserManager} with missing shadow methods - */ -@Implements(WallpaperManager.class) -public class LShadowWallpaperManager extends ShadowWallpaperManager { - - @Implementation - protected static WallpaperManager getInstance(Context context) { - return context.getSystemService(WallpaperManager.class); - } - - /** - * Remove this once the fix for - * https://github.com/robolectric/robolectric/issues/5285 - * is available - */ - public static void initializeMock() { - WallpaperManager wm = mock(WallpaperManager.class); - ShadowApplication shadowApplication = Shadows.shadowOf(RuntimeEnvironment.application); - shadowApplication.setSystemService(Context.WALLPAPER_SERVICE, wm); - doReturn(0).when(wm).getDesiredMinimumWidth(); - doReturn(0).when(wm).getDesiredMinimumHeight(); - } -} diff --git a/robolectric_tests/src/com/android/launcher3/util/LauncherTestApplication.java b/robolectric_tests/src/com/android/launcher3/util/LauncherTestApplication.java index 6dd4df8377..efac15098c 100644 --- a/robolectric_tests/src/com/android/launcher3/util/LauncherTestApplication.java +++ b/robolectric_tests/src/com/android/launcher3/util/LauncherTestApplication.java @@ -19,7 +19,6 @@ import static org.mockito.Mockito.mock; import android.app.Application; -import com.android.launcher3.shadows.LShadowWallpaperManager; import com.android.launcher3.shadows.ShadowMainThreadInitializedObject; import com.android.launcher3.shadows.ShadowOverrides; import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; @@ -37,9 +36,6 @@ public class LauncherTestApplication extends Application implements TestLifecycl // Disable plugins PluginManagerWrapper.INSTANCE.initializeForTesting(mock(PluginManagerWrapper.class)); - - // Initialize mock wallpaper manager - LShadowWallpaperManager.initializeMock(); } @Override