SmsDisplayer { public void twoStopResponse() { StopSearchResult stopSearchResult1 = (StopSearchResult) searchResults.get(0); StopSearchResult stopSearchResult2 = (StopSearchResult) searchResults.get(1); StringBuilder stopResponse1 = getInitialTwoStopResponse(stopSearchResult1); StringBuilder stopResponse2 = getInitialTwoStopResponse(stopSearchResult2); List<RouteItem> routesAvailable1 = stopSearchResult1.getRoutesAvailable(); List<RouteItem> routesAvailable2 = stopSearchResult2.getRoutesAvailable(); List<RouteDistanceAway> rdaList1 = getRouteDistanceAways(routesAvailable1); List<RouteDistanceAway> rdaList2 = getRouteDistanceAways(routesAvailable2); Iterator<RouteDistanceAway> it1 = rdaList1.iterator(); Iterator<RouteDistanceAway> it2 = rdaList2.iterator(); if (rdaList1.isEmpty()) stopResponse1.append(getNoUpcomingArrivalsString(routesAvailable1)); if (rdaList2.isEmpty()) stopResponse2.append(getNoUpcomingArrivalsString(routesAvailable2)); while (true) { if (!it1.hasNext() && !it2.hasNext()) break; String s1 = ""; String s2 = ""; if (it1.hasNext()) { RouteDistanceAway rda1 = it1.next(); s1 = rda1.toString(); } if (it2.hasNext()) { RouteDistanceAway rda2 = it2.next(); s2 = rda2.toString(); } if (s1.length() + s2.length() + stopResponse1.length() + stopResponse2.length() <= SmsDisplayer.MAX_CHARS) { stopResponse1.append(s1); stopResponse2.append(s2); } } addToResponse(stopResponse1); addToResponse(stopResponse2); } SmsDisplayer(List<SearchResult> searchResults); void singleStopResponse(); void noResultsResponse(); void twoStopResponse(); void manyStopResponse(); @Override String toString();  }
@Test public void testTwoStopResponse() { List<RouteItem> routes = new ArrayList<RouteItem>(); List<DistanceAway> distanceAways = new ArrayList<DistanceAway>(); distanceAways.add(new DistanceAway(1, 100, new Date(), Mode.SMS,300, FormattingContext.STOP, null)); distanceAways.add(new DistanceAway(2, 200, new Date(), Mode.SMS,300, FormattingContext.STOP, null)); RouteItem availableRoute = makeAvailableRoute(distanceAways); routes.add(availableRoute); StopSearchResult stopResult1 = makeStopSearchResult(routes, "N"); StopSearchResult stopResult2 = makeStopSearchResult(routes, "S"); List<SearchResult> searchResults = new ArrayList<SearchResult>(); searchResults.add(stopResult1); searchResults.add(stopResult2); SmsDisplayer sms = new SmsDisplayer(searchResults); sms.twoStopResponse(); String actual = sms.toString(); String exp = "N-bound (123456):\n" + "routeid: at stop\n" + "routeid: 2 stops away\n" + "S-bound (123456):\n" + "routeid: at stop\n" + "routeid: 2 stops away\n"; assertEquals(exp, actual); }