ProvinceInfoParserTask extends AsyncTask<Void, Void, List<ProvinceModel>> { @Override protected List<ProvinceModel> doInBackground(Void... params) { if (null == mContext) return null; List<ProvinceModel> provinceList = new ArrayList<ProvinceModel>(); try { SAXParserFactory sax = SAXParserFactory.newInstance(); XMLReader reader = sax.newSAXParser().getXMLReader(); InputStream in = mContext.getAssets().open("city.xml"); reader.setContentHandler(new ProvinceInfoHandler(provinceList)); reader.parse(new InputSource(in)); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return provinceList; } ProvinceInfoParserTask(Context context, Handler handler);  static final int MSG_PARSE_RESULT_CALLBACK; }
@Test public void testDoInBackground() { List<ProvinceModel> actual = provinceInfoParserTask.doInBackground(); assertNotNull(actual); assertProvinceList(provinces, actual); }
@Test public void testDoInBackgroundWithNullContext() { Whitebox.setInternalState(provinceInfoParserTask, "mContext", null); List<ProvinceModel> actual = provinceInfoParserTask.doInBackground(); assertNull(actual); }