Java 类android.test.mock.MockResources 实例源码

项目:Calendar_lunar    文件:EditEventHelperTest.java   
@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;
}
项目:Equate    文件:CalculatorJUnitTest.java   
/**
 * 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);
}
项目:Inside_Android_Testing    文件:MainActivityTest.java   
public void testGetStringResource() {
    MockResources mockResources = new MyMockResources();

    String actual = mainActivity.getStringResource(mockResources);

    assertEquals("string", actual);
}