### Question:
GpxParser { @Nullable List<Location> parseGpx(InputStream inputStream) throws ParserConfigurationException, SAXException, IOException, ParseException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(inputStream); Element elementRoot = document.getDocumentElement(); NodeList trackPointNodes = elementRoot.getElementsByTagName(TAG_TRACK_POINT); if (trackPointNodes == null || trackPointNodes.getLength() == 0) { return null; } return createGpxLocationList(trackPointNodes); }    }### Answer:
@Test public void invalidGpxTags_returnsNullList() throws ParserConfigurationException, SAXException, ParseException, IOException { GpxParser parser = new GpxParser(); InputStream inputStream = buildTestGpxInputStream(TEST_INVALID_GPX); List<Location> parsedLocations = parser.parseGpx(inputStream); assertNull(parsedLocations); }
@Test public void validGpxFile_returnsPopulatedLocationList() throws ParserConfigurationException, SAXException, ParseException, IOException { GpxParser parser = new GpxParser(); InputStream inputStream = buildTestGpxInputStream(TEST_GPX); List<Location> parsedLocations = parser.parseGpx(inputStream); assertTrue(!parsedLocations.isEmpty()); }
@Test public void validGpxFile_returnsCorrectAmountOfLocations() throws ParserConfigurationException, SAXException, ParseException, IOException { GpxParser parser = new GpxParser(); InputStream inputStream = buildTestGpxInputStream(TEST_GPX); List<Location> parsedLocations = parser.parseGpx(inputStream); assertEquals(3, parsedLocations.size()); }
@Test public void firstLocationUpdate_returnsCorrectLatitude() throws ParserConfigurationException, SAXException, ParseException, IOException { GpxParser parser = new GpxParser(); InputStream inputStream = buildTestGpxInputStream(TEST_GPX); List<Location> parsedLocations = parser.parseGpx(inputStream); double actualFirstLatitude = parsedLocations.get(FIRST_LOCATION).getLatitude(); assertEquals(FIRST_TEST_GPS_LATITUDE, actualFirstLatitude); }
@Test public void firstLocationUpdate_returnsCorrectLongitude() throws ParserConfigurationException, SAXException, ParseException, IOException { GpxParser parser = new GpxParser(); InputStream inputStream = buildTestGpxInputStream(TEST_GPX); List<Location> parsedLocations = parser.parseGpx(inputStream); double actualFirstLongitude = parsedLocations.get(FIRST_LOCATION).getLongitude(); assertEquals(FIRST_TEST_GPS_LONGITUDE, actualFirstLongitude); }
@Test public void firstLocationUpdate_returnsCorrectTimeInMillis() throws ParserConfigurationException, SAXException, ParseException, IOException { GpxParser parser = new GpxParser(); InputStream inputStream = buildTestGpxInputStream(TEST_GPX); List<Location> parsedLocations = parser.parseGpx(inputStream); long actualFirstTime = parsedLocations.get(FIRST_LOCATION).getTime(); assertEquals(FIRST_TEST_GPS_TIME, actualFirstTime, DELTA); }