J4pTargetConfig { public JSONObject toJson() { JSONObject ret = new JSONObject(); ret.put("url",url); if (user != null) { ret.put("user",user); ret.put("password",password); } return ret; } J4pTargetConfig(String pUrl, String pUser, String pPassword); String getUrl(); String getUser(); String getPassword(); JSONObject toJson();  }
@Test public void json() { J4pTargetConfig cfg = new J4pTargetConfig(URL,"roland","s!cr!t"); JSONObject j = cfg.toJson(); assertEquals(j.get("url"),URL); assertEquals(j.get("user"),"roland"); assertEquals(j.get("password"),"s!cr!t"); }