本文整理汇总了Java中android.test.mock.MockResources类的典型用法代码示例。如果您正苦于以下问题:Java MockResources类的具体用法?Java MockResources怎么用?Java MockResources使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockResources类属于android.test.mock包,在下文中一共展示了MockResources类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResources
import android.test.mock.MockResources; //导入依赖的package包/类
@Override
public Resources getResources() {
Resources res = new MockResources() {
@Override
// The actual selects singular vs plural as well and in the given language
public String getQuantityString(int id, int quantity) {
if (id == R.plurals.Nmins) {
return quantity + " mins";
}
if (id == R.plurals.Nminutes) {
return quantity + " minutes";
}
if (id == R.plurals.Nhours) {
return quantity + " hours";
}
if (id == R.plurals.Ndays) {
return quantity + " days";
}
return id + " " + quantity;
}
};
return res;
}
示例2: getTestCalc
import android.test.mock.MockResources; //导入依赖的package包/类
/**
* Used to get a test calculator with a mocked resource file
*
* @return test calculator
*/
private Calculator getTestCalc() {
//TODO make this into something cleaner--use Mockito to completely fake the resource
MockResources mockResources = new MockResources() {
@Override
public String[] getStringArray(int id) {
if (id == R.array.unit_type_array_combined){
return new String[]{"key_currency|Currency|Currency", "key_temp|Temperature|Temp", "key_weight|Weight|Weight", "key_len|Length|Length", "key_area|Area|Area", "key_vol|Volume|Volume", "key_speed|Speed|Speed", "key_time|Time|Time", "key_fuel|FuelEconomy|FuelEco", "key_power|Power|Power", "key_energy|Energy|Energy", "key_force|Force|Force", "key_torque|Torque|Torque", "key_pressure|Pressure|Pressure", "key_digital|DigitalStorage|Digital"};
}
return null;
}
};
return Calculator.getTestCalculator(mockResources);
}
示例3: testGetStringResource
import android.test.mock.MockResources; //导入依赖的package包/类
public void testGetStringResource() {
MockResources mockResources = new MyMockResources();
String actual = mainActivity.getStringResource(mockResources);
assertEquals("string", actual);
}