JsonHelper { public static String createTweetsWithHashtagRanking(String tweetsArray) throws RuntimeException { JSONObject returnJsonObj = new JSONObject(); try { JSONArray tweetsJsonArray = new JSONArray(tweetsArray); returnJsonObj.put(KEY_TWEETS, tweetsJsonArray); returnJsonObj.put(KEY_TOPTEN, extractTopTenHashtags(tweetsArray)); } catch (JSONException e) { throw new RuntimeException("Failure during create json object with hashtag search."); } return returnJsonObj.toString(); }  static String generateCoordinates(String json); static String createTweetsWithHashtagRanking(String tweetsArray); static String createTweetsWithoutHashtagRanking(String tweetsArray); static final String KEY_COORDINATES; static final String KEY_PLACE; static final String KEY_TWEETS; static final String KEY_TOPTEN; }
@Test public void createTweetsWithHashtagRankingTest() throws Exception { String result = JsonHelper.createTweetsWithHashtagRanking(tweetsArray); JSONObject resultJsonObj = new JSONObject(result); assertTrue(resultJsonObj.has(JsonHelper.KEY_TWEETS)); assertTrue(resultJsonObj.has(JsonHelper.KEY_TOPTEN)); assertTrue(resultJsonObj.getJSONArray(JsonHelper.KEY_TOPTEN).length() == 10); assertTrue(Objects.equals(resultJsonObj.getJSONArray(JsonHelper.KEY_TOPTEN).getString(0), "#yolo")); assertTrue(Objects.equals(resultJsonObj.getJSONArray(JsonHelper.KEY_TOPTEN).getString(1), "#dirili")); assertTrue(resultJsonObj.getJSONArray(JsonHelper.KEY_TWEETS).length() == 34); JSONObject firstTweet = (JSONObject) resultJsonObj.getJSONArray(JsonHelper.KEY_TWEETS).get(0); assertTrue(firstTweet.has("text")); assertTrue(Objects.equals(firstTweet.getString("id_str"), "715193777833582592")); }