public void execute(File file) throws Exception {
DeviceRepositoryFactory factory =
DeviceRepositoryFactory.getDefaultInstance();
URL deviceRepositoryUrl = file.toURL();
DeviceRepository repository = factory.getDeviceRepository(
deviceRepositoryUrl, null);
// Test retrieval of an IMEI that exists as an eight-digit TAC
String devName = repository.getDeviceNameByIMEI("350612190161323");
assertEquals("Device 3506121901613238 should be Nokia 6210 Special",
"Nokia-6210-Special", devName);
// Test retrieval of an IMEI that falls back to a six-digit TAC
devName = repository.getDeviceNameByIMEI("350612350161323");
assertEquals("Device 3506123501613238 should be Nokia 6210",
"Nokia-6210", devName);
// Test retrieval of a IMEI that does not map to a TAC of eight or six
// digits
devName = repository.getDeviceNameByIMEI("123456789012345");
assertNull("Device 123456789012345 should not exist", devName);
// Test retrieval of an invalid IMEI
try {
repository.getDeviceNameByIMEI("cheddarsmonkeys");
fail("Attempt to find non-numeric IMEI should " +
"throw IllegalArgumentException");
} catch (IllegalArgumentException iae) {
// We expect an IllegalArgumentException - 'cheddarsmonkeys'
// is not a valid IMEI combination.
}
try {
repository.getDeviceNameByIMEI("0123456789abcde");
fail("Attempt to find non-numeric IMEI should " +
"throw IllegalArgumentException");
} catch (IllegalArgumentException iae) {
// We expect an IllegalArgumentException - '0123456789abcde'
// is not a valid IMEI combination.
}
// Test invalid length
try {
repository.getDeviceNameByIMEI("0123456789");
fail("Attempt to find too short IMEI should " +
"throw IllegalArgumentException");
} catch (IllegalArgumentException iae) {
// We expect an IllegalArgumentException - '0123456789' is
// not a valid IMEI combination.
}
try {
repository.getDeviceNameByIMEI("01234567890123456789");
fail("Attempt to find too long IMEI should " +
"throw IllegalArgumentException");
} catch (IllegalArgumentException iae) {
// We expect an IllegalArgumentException
// '01234567890123456789' is not a valid IMEI combination.