AppSettingsReader { @Nullable public AbstractAppSettings read(@Nullable final String json) { if (TextUtils.isEmpty(json)) { return null; } try { return read(new StringReader(json)); } catch (IOException ioe) { Log.w(TAG, ioe.getMessage()); } return null; } AppSettingsReader(@NonNull final OnAppSettingsReaderListener onAppSettingsReaderListener); @Nullable AbstractAppSettings read(@Nullable final String json); @NonNull AbstractAppSettings read(@NonNull final Reader in);  }
@Test public void testReadAppSettingsWithDbFromJsonString() throws Exception { final String json = TestHelper.getFixture("app_settings_with_db.json"); final DummyAppSettings appSettings = (DummyAppSettings) appSettingsReader.read(json); verify(onAppSettingsReaderListener, never()).readAdditionalSettings(any(JsonReader.class), any(String.class), any(DummyAppSettings.class)); assertNotNull(appSettings); assertNotNull(appSettings.getDbSettings()); assertNotNull(appSettings.getSyncSettings()); assertEquals("local.db", appSettings.getDbSettings() .getName()); assertEquals(8, appSettings.getDbSettings() .getVersion()); Assert.assertEquals("http: appSettings.getSyncSettings() .getServerUrl()); Assert.assertEquals("my!token#", appSettings.getSyncSettings() .getToken()); Assert.assertEquals("status/", appSettings.getSyncSettings() .getStatusUrl()); Assert.assertEquals("import/", appSettings.getSyncSettings() .getImportUrl()); Assert.assertEquals(1, appSettings.getSyncSettings() .getExports() .size()); Assert.assertEquals("export/sqlite/", appSettings.getSyncSettings() .getExports() .get(0) .getUrl()); Assert.assertEquals("databases/data.db", appSettings.getSyncSettings() .getExports() .get(0) .getFile()); }
@Test public void testReadAppSettingsWithoutQualificationFromJsonString() throws Exception { final String json = TestHelper.getFixture("app_settings.json"); final DummyAppSettings appSettings = (DummyAppSettings) appSettingsReader.read(json); assertNotNull(appSettings); assertNull(appSettings.getQualificationSettings()); }
@Test public void testReadAppSettingsWithQualificationFromJsonString() throws Exception { final String json = TestHelper.getFixture("app_settings_with_qualification.json"); final DummyAppSettings appSettings = (DummyAppSettings) appSettingsReader.read(json); assertNotNull(appSettings); final QualificationSettings qualificationSettings = appSettings.getQualificationSettings(); assertNotNull(qualificationSettings); assertEquals(2, qualificationSettings.getOrganism()); assertEquals(140, qualificationSettings.getProtocol()); assertEquals(4, qualificationSettings.getLot()); }
@Test public void testReadAppSettingsFromJsonString() throws Exception { final String json = TestHelper.getFixture("app_settings.json"); final DummyAppSettings appSettings = (DummyAppSettings) appSettingsReader.read(json); verify(onAppSettingsReaderListener, never()).readAdditionalSettings(any(JsonReader.class), any(String.class), any(DummyAppSettings.class)); assertNotNull(appSettings); assertNotNull(appSettings.getDbSettings()); assertNotNull(appSettings.getSyncSettings()); assertEquals("data.db", appSettings.getDbSettings() .getName()); assertEquals(1, appSettings.getDbSettings() .getVersion()); Assert.assertEquals("http: appSettings.getSyncSettings() .getServerUrl()); Assert.assertEquals("my!token#", appSettings.getSyncSettings() .getToken()); Assert.assertEquals("status/", appSettings.getSyncSettings() .getStatusUrl()); Assert.assertEquals("import/", appSettings.getSyncSettings() .getImportUrl()); Assert.assertEquals(1, appSettings.getSyncSettings() .getExports() .size()); Assert.assertEquals("export/sqlite/", appSettings.getSyncSettings() .getExports() .get(0) .getUrl()); Assert.assertEquals("databases/data.db", appSettings.getSyncSettings() .getExports() .get(0) .getFile()); }
@Test public void testReadAppSettingsFromInvalidJsonString() throws Exception { final DummyAppSettings appSettings = (DummyAppSettings) appSettingsReader.read(""); assertNull(appSettings); }