QuoteParser { public List<Quote> parseQuotesFromReddit(JSONObject response) throws JSONException { List<Quote> quoteArrayList = new ArrayList<>(); JSONObject data = response.getJSONObject("data"); JSONArray children = data.getJSONArray("children"); for (int i = 0; i < children.length(); i++) { JSONObject quoteChildren = children.getJSONObject(i); JSONObject quoteData = quoteChildren.getJSONObject("data"); String quoteString = quoteData.getString("title"); quoteString = removeQuotations(quoteString); quoteArrayList.add(getQuoteTextAndAuthorParsingDashes(quoteString)); } return quoteArrayList; }  List<Quote> parseQuotesFromReddit(JSONObject response);  }
@Test public void parseQuotesFromReddit() throws Exception { List<Quote> popularQuote = quoteParser.parseQuotesFromReddit(response); assertTrue("Could not parse 26 quotes from reddit", popularQuote.size() == 25); List<Quote> popularQuotesList = new ArrayList<>(); for (Quote quote : popularQuote) { if (quote.getQuoteAuthor().length() < 20 && quote.getQuoteAuthor().length() > 0) { popularQuotesList.add(quote); } } assertTrue("Did not get 13 valid quotes", popularQuotesList.size() == 11); Quote quote = popularQuotesList.get(0); assertTrue("Quote text Leonardo daVinci is not correct", quote.getQuoteText().equals("He who wishes to grow rich in a day will be hanged in a year. ")); assertTrue("Quote author Leonardo daVinci is not correct", quote.getQuoteAuthor().equals(" Leonardo daVinci")); quote = popularQuotesList.get(9); assertTrue("Quote text Helen Keller - is not correct", quote.getQuoteText().equals("Cut off as I am, it is inevitable that I should sometimes feel like a shadow walking in a shadowy world. When this happens I ask to be taken to New York City. Always I return home weary but I have the comforting certainty that mankind is real flesh and I myself am not a dream. ")); assertTrue("Quote author Helen Keller - is not correct", quote.getQuoteAuthor().equals(" Helen Keller -")); }