OldStyleLoader { public static void parse(String text, Survey survey) throws Exception { Map<String, Station> nameToStation = new HashMap<>(); Station origin = survey.getOrigin(); nameToStation.put(origin.getName(), origin); String[] lines = text.split("\n"); for (String line : lines) { line = line.trim(); if (line.equals("") || line.startsWith("*")) { continue; } String comment = ""; if (line.contains("; ")) { comment = line.substring(line.indexOf("; ") + 2); comment = comment.replaceAll("\\\\n", "\n"); line = line.substring(0, line.indexOf("; ")); } String[] fields = line.trim().split("\t"); addLegToSurvey(survey, nameToStation, fields, comment); } }  static void parse(String text, Survey survey);  }
@Test public void testEmptySurveyResultsIn1Station() throws Exception { String text = ""; Survey survey = new Survey("TestSurvey"); OldStyleLoader.parse(text, survey); assert survey.getAllStations().size() == 1; }
@Test public void testSimpleSurveyIsParsed() throws Exception { String text = "1\t2\t9.11\t121\t-23\n"; Survey survey = new Survey("TestSurvey"); OldStyleLoader.parse(text, survey); assert survey.getAllStations().size() == 2; assert survey.getOrigin().getConnectedOnwardLegs().get(0) .getDestination().getName().equals("2"); }
@Test public void testStarredLinesAreIgnored() throws Exception { String text = "*data normal from to length compass clino\n" + "1\t2\t9.11\t121\t-23\n"; Survey survey = new Survey("TestSurvey"); OldStyleLoader.parse(text, survey); assert survey.getAllStations().size() == 2; }
@Test public void testReversedLegIsParsed() throws Exception { String text = "2\t1\t9.11\t121\t-23\n"; Survey survey = new Survey("TestSurvey"); OldStyleLoader.parse(text, survey); assert survey.getAllStations().size() == 2; assert survey.getOrigin().getConnectedOnwardLegs().get(0) .getDestination().getName().equals("2"); assert survey.getOrigin().getConnectedOnwardLegs().get(0) .wasShotBackwards(); }