MetadataTranslater { public static void translateAndUpdate(Context context, Survey survey, String string) throws Exception { Set<String> surveyNamesNotToLoad = new HashSet<>(); translateAndUpdate(context, survey, string, surveyNamesNotToLoad); }  static String translate(Survey survey); static void translateAndUpdate(Context context, Survey survey, String string); static void translateAndUpdate(
            Context context,
            Survey survey,
            String string,
            Set<String> surveyNamesNotToLoad); static JSONObject toJson(Survey survey); static List<JSONArray> toListOfArrays(JSONArray array); static final String CONNECTIONS_TAG; static final String ACTIVE_STATION_TAG; }
@Test public void testActiveStationIsTParsed() throws Exception { Survey survey = new Survey("test"); String text = "{\"active-station\":\"1\",\"connections\":{}}"; MetadataTranslater.translateAndUpdate(null, survey, text); Assert.assertEquals(survey.getActiveStation().getName(), "1"); }
@Test public void testJsonIsTranslatedToSurveyWithActiveStation() throws Exception { String json = "{\"active-station\":\"1\",\"connections\":{}}"; Survey testSurvey = BasicTestSurveyCreator.createStraightNorth(); testSurvey.setActiveStation(testSurvey.getStationByName("2")); MetadataTranslater.translateAndUpdate(null, testSurvey, json); Assert.assertEquals("1", testSurvey.getActiveStation().getName()); Assert.assertEquals(0, testSurvey.getConnectedSurveys().size()); }
@Test public void testConnectedSurveyJsonIsTranslatedToConnectedSurvey() throws Exception { String json = "{\"active-station\":\"1\",\"connections\":{\"1\":[[\"connected\",\"1\"]]}}"; Survey survey = new Survey("test"); Survey connected = new Survey("connected"); PowerMockito.mockStatic(Loader.class); Mockito.when( Loader.loadSurvey((Context)anyObject(), anyString(), anySet(), anyBoolean())) .thenReturn(connected); MetadataTranslater.translateAndUpdate(null, survey, json); Assert.assertEquals(1, survey.getConnectedSurveys().size()); }