android.test.mock.MockResources Java Examples

The following examples show how to use android.test.mock.MockResources. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CalculatorJUnitTest.java    From Equate with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #2
Source File: MainActivityTest.java    From Inside_Android_Testing with Apache License 2.0 3 votes vote down vote up
public void testGetStringResource() {
	MockResources mockResources = new MyMockResources();

	String actual = mainActivity.getStringResource(mockResources);

	assertEquals("string", actual);
}