@Nullable public static SourceCodeVerification fromJson(@Nullable JSONObject jsonObject) { if (jsonObject == null) { return null; } return new SourceCodeVerification( jsonObject.optInt(FIELD_ATTEMPTS_REMAINING, INVALID_ATTEMPTS_REMAINING), asStatus(optString(jsonObject, FIELD_STATUS))); }
@Nullable public static SourceCodeVerification fromString(@Nullable String jsonString) { try { return fromJson(new JSONObject(jsonString)); } catch (JSONException ignored) { return null; } }
@Test public void fromJsonString_toMap_createsExpectedMap() { assertMapEquals(EXAMPLE_MAP_CODE_VERIFICATION, mCodeVerification.toMap()); } }
@Before public void setup() { mCodeVerification = SourceCodeVerification.fromString(EXAMPLE_JSON_CODE_VERIFICATION); assertNotNull(mCodeVerification); }
@Test public void fromJsonString_backToJson_createsIdenticalElement() { try { JSONObject rawConversion = new JSONObject(EXAMPLE_JSON_CODE_VERIFICATION); assertJsonEquals(rawConversion, mCodeVerification.toJson()); } catch (JSONException jsonException) { fail("Test Data failure: " + jsonException.getLocalizedMessage()); } }
case FIELD_CODE_VERIFICATION: return type.cast( SourceCodeVerification.fromJson( jsonObject.optJSONObject(FIELD_CODE_VERIFICATION))); case FIELD_OWNER: