[Testing] To migration DefaultSubscriptionControllerTest

1. Use AndroidJunit4 instead of RobolectricTestRunner
2. Use ApplicationProvider instead of RuntimeEnvironment to get context
3. Change Copy Right
4. Create new class and add a function which loads the Settings Resource.
5. remove getOnPreferenceChangeListener. Becasue the error:
java.lang.NoSuchMethodError: No virtual method getOnPreferenceChangeListener()

Bug: 173004787
Test: atest -c DefaultSubscriptionControllerTest
Change-Id: Iac9834f2a47bd8b50234646197a31058ffacaa4b
This commit is contained in:
SongFerngWang
2020-11-12 10:28:09 +08:00
parent d682b2cc57
commit aa941c91b7
2 changed files with 84 additions and 38 deletions

View File

@@ -0,0 +1,28 @@
/*
* 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.settings.testutils;
import android.content.Context;
public final class Utils {
public static int getResourceId(Context context, String type, String name) {
return context.getResources().getIdentifier(name, type, context.getPackageName());
}
public static String getResourceString(Context context, String name) {
return context.getResources().getString(getResourceId(context, "string", name));
}
}