### Question:
StripeJsonUtils { @Nullable static String getString( @NonNull JSONObject jsonObject, @NonNull @Size(min = 1) String fieldName) throws JSONException { return nullIfNullOrEmpty(jsonObject.getString(fieldName)); }    }### Answer:
@Test public void getString_whenFieldContainsRawNull_returnsNull() { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("key", "null"); assertNull(StripeJsonUtils.getString(jsonObject, "key")); } catch (JSONException jex) { fail("No exception expected"); } }
@Test(expected = JSONException.class) public void getString_whenFieldNotPresent_throwsJsonException() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "value"); StripeJsonUtils.getString(jsonObject, "differentKey"); fail("Expected an exception."); }
@Test public void getString_whenFieldPresent_findsAndReturnsField() { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("key", "value"); assertEquals("value", StripeJsonUtils.getString(jsonObject, "key")); } catch (JSONException jex) { fail("No exception expected"); } }