@org.junit.Test public void testParseMatch() { String matchJson = "{\"comp_level\": \"f\", \"match_number\": 1, \"videos\": [{\"type\": \"youtube\", \"key\": \"ci6LicTg5rk\"}], \"time_string\": \"3:36 PM\", \"set_number\": 1, \"key\": \"2014ctgro_f1m1\", \"time\": \"1394393760\", \"alliances\": {\"blue\": {\"score\": 113, \"teams\": [\"frc1991\", \"frc230\", \"frc1699\"]}, \"red\": {\"score\": 120, \"teams\": [\"frc236\", \"frc237\", \"frc2064\"]}}, \"event_key\": \"2014ctgro\"}"; Match match = JSONManager.getGson().fromJson(matchJson, Match.class); try { assertEquals(match.getKey(), "2014ctgro_f1m1"); assertEquals(match.getEventKey(), "2014ctgro"); assertEquals(match.getMatchNumber(), 1); assertEquals(match.getSetNumber(), 1); assertEquals(match.getType(), MatchHelper.TYPE.FINAL); assertEquals( match.getAlliances(), JSONManager.getasJsonObject( "{\"blue\": {\"score\": 113, \"teams\": [\"frc1991\", \"frc230\", \"frc1699\"]}, \"red\": {\"score\": 120, \"teams\": [\"frc236\", \"frc237\", \"frc2064\"]}}")); assertEquals(match.getTimeString(), "3:36 PM"); assertEquals(match.getTime(), new Date(1394393760)); assertEquals( match.getVideos(), JSONManager.getasJsonArray("[{\"type\": \"youtube\", \"key\": \"ci6LicTg5rk\"}]")); } catch (BasicModel.FieldNotDefinedException e) { Log.e(Constants.LOG_TAG, "Unable to get match fields"); e.printStackTrace(); } }
@org.junit.Test public void testParseMedia() { String mediaJson = "[" + " {" + " \"type\": \"cdphotothread\"," + " \"details\": {" + " \"image_partial\": \"fe3/fe38d320428adf4f51ac969efb3db32c_l.jpg\"" + " }," + " \"foreign_key\": \"39894\"" + " }," + " {" + " \"type\": \"youtube\"," + " \"details\": {}," + " \"foreign_key\": \"RpSgUrsghv4\"" + " }" + "]"; ArrayList<Media> medias = new ArrayList<>(); JsonArray mediaArray = JSONManager.getasJsonArray(mediaJson); for (JsonElement media : mediaArray) { medias.add(JSONManager.getGson().fromJson(media, Media.class)); } assertEquals(medias.size(), mediaArray.size()); assertEquals(medias.size(), 2); Media cd = medias.get(0); Media yt = medias.get(1); try { assertEquals(cd.getForeignKey(), "39894"); assertEquals(cd.getMediaType(), Media.TYPE.CD_PHOTO_THREAD); assertEquals( cd.getDetails(), JSONManager.getasJsonObject( "{\"image_partial\": \"fe3/fe38d320428adf4f51ac969efb3db32c_l.jpg\"}")); assertEquals(yt.getMediaType(), Media.TYPE.YOUTUBE); assertEquals(yt.getForeignKey(), "RpSgUrsghv4"); assertEquals(yt.getDetails(), new JsonObject()); } catch (BasicModel.FieldNotDefinedException e) { Log.e(Constants.LOG_TAG, "Unable to get media fields"); e.printStackTrace(); } }