### Question:
StripeJsonUtils { @Nullable static String optString( @NonNull JSONObject jsonObject, @NonNull @Size(min = 1) String fieldName) { return nullIfNullOrEmpty(jsonObject.optString(fieldName)); }    }### Answer:
@Test public void optString_whenFieldPresent_findsAndReturnsField() { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("key", "value"); assertEquals("value", StripeJsonUtils.optString(jsonObject, "key")); } catch (JSONException jex) { fail("No exception expected"); } }
@Test public void optString_whenFieldContainsRawNull_returnsNull() { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("key", "null"); assertNull(StripeJsonUtils.optString(jsonObject, "key")); } catch (JSONException jex) { fail("No exception expected"); } }
@Test public void optString_whenFieldNotPresent_returnsNull() { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("key", "value"); Object ob = StripeJsonUtils.optString(jsonObject, "nokeyshere"); assertNull(ob); } catch (JSONException jex) { fail("No exception expected"); } }