### Question:
TraceThread extends Thread { @Override public void run() { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final XPath xPath = XPathFactory.newInstance().newXPath(); final String expression = " final String speedExpression = " NodeList nodeList = null; NodeList speedList = null; try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(traceFile); nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); speedList = (NodeList) xPath.compile(speedExpression).evaluate(document, XPathConstants.NODESET); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (XPathExpressionException e) { e.printStackTrace(); } parse(nodeList, speedList); } TraceThread(Context context, File traceFile, MockEngine engine, SleepFactory sleepFactory); void cancel(); boolean isCanceled(); @Override void run();  }### Answer:
@Test public void shouldReportEachLocation() throws Exception { traceThread.run(); assertThat(mockEngine.locations).hasSize(3); assertThat(mockEngine.locations.get(0).getLatitude()).isEqualTo(0.0); assertThat(mockEngine.locations.get(0).getLongitude()).isEqualTo(0.1); assertThat(mockEngine.locations.get(1).getLatitude()).isEqualTo(1.0); assertThat(mockEngine.locations.get(1).getLongitude()).isEqualTo(1.1); assertThat(mockEngine.locations.get(2).getLatitude()).isEqualTo(2.0); assertThat(mockEngine.locations.get(2).getLongitude()).isEqualTo(2.1); }
@Test public void shouldReportSpeed() throws Exception { traceThread.run(); assertThat(mockEngine.locations.get(0).getSpeed()).isEqualTo(10f); assertThat(mockEngine.locations.get(1).getSpeed()).isEqualTo(20f); assertThat(mockEngine.locations.get(2).getSpeed()).isEqualTo(30f); }
@Test public void shouldCalculateBearing() throws Exception { traceThread.run(); assertThat(mockEngine.locations.get(0).getBearing()).isEqualTo(0.0f); assertThat(mockEngine.locations.get(1).getBearing()) .isEqualTo(mockEngine.locations.get(0).bearingTo(mockEngine.locations.get(1))); assertThat(mockEngine.locations.get(2).getBearing()) .isEqualTo(mockEngine.locations.get(1).bearingTo(mockEngine.locations.get(2))); }
@Test public void shouldSetHasBearing() throws Exception { traceThread.run(); assertThat(mockEngine.locations.get(0).hasBearing()).isFalse(); assertThat(mockEngine.locations.get(1).hasBearing()).isTrue(); assertThat(mockEngine.locations.get(2).hasBearing()).isTrue(); }
@Test public void shouldRespectFastestInterval() throws Exception { mockEngine.setRequest(new TestLocationRequestUnbundled(100)); traceThread.run(); assertThat(sleepFactory.sleepTimeInMillis).isEqualTo(300); }
@Test public void shouldReportSpeedIfAvailable() throws Exception { traceThread = new TraceThread(application, getTestGpxTrace(), mockEngine, sleepFactory); traceThread.run(); assertThat(mockEngine.locations.get(0).hasSpeed()).isTrue(); }
@Test public void shouldNotReportSpeedIfNotAvailable() throws Exception { traceThread = new TraceThread(application, getNoSpeedGpxTrace(), mockEngine, sleepFactory); traceThread.run(); assertThat(mockEngine.locations.get(0).hasSpeed()).isFalse(); }