ServerHandle { public JSONObject toJSONObject(MBeanServerExecutor pServerManager) { JSONObject ret = new JSONObject(); addNullSafe(ret, "vendor", vendor); addNullSafe(ret, "product", product); addNullSafe(ret, "version", version); Map<String,String> extra = getExtraInfo(pServerManager); if (extra != null) { JSONObject jsonExtra = new JSONObject(); for (Map.Entry<String,String> entry : extra.entrySet()) { jsonExtra.put(entry.getKey(),entry.getValue()); } ret.put("extraInfo", jsonExtra); } return ret; } ServerHandle(String vendor, String product, String version, Map<String, String> extraInfo); String getVendor(); String getProduct(); String getVersion(); Map<String,String> getExtraInfo(MBeanServerExecutor pServerManager); void preDispatch(MBeanServerExecutor pMBeanServerExecutor, JmxRequest pJmxReq); void postDetect(MBeanServerExecutor pServerManager, Configuration pConfig, LogHandler pLoghandler); ObjectName registerMBeanAtServer(MBeanServer pServer, Object pMBean, String pName); JSONObject toJSONObject(MBeanServerExecutor pServerManager);  }
@Test public void toJson() { JSONObject json = serverHandle.toJSONObject(null); assertEquals(json.get("vendor"),vendor); assertEquals(json.get("product"),product); assertEquals(json.get("version"),version); assertEquals(((JSONObject) json.get("extraInfo")).get("extra1"),"value1"); }