### Question:
LQEvent extends LQModel { public JSONObject toJSON() { JSONObject json = new JSONObject(); try { if(mAttributes != null) { for(String key : mAttributes.keySet()){ if(mAttributes.get(key) instanceof Date) { json.put(key, LiquidTools.dateToString((Date) mAttributes.get(key))); } else { json.put(key, mAttributes.get(key)); } } } json.put("name", mName); json.put("date",LiquidTools.dateToString(mDate)); return json; } catch (JSONException e) { LQLog.error("LQEvent toJSON: " + e.getMessage()); } return null; } LQEvent(String name, HashMap<String,Object> attributes, Date date);  LQEvent(String name, HashMap<String,Object> attributes); void setName(String name); String getName(); JSONObject toJSON(); static boolean hasValidName(String name, boolean raiseException); static final String UNNAMED_EVENT; }### Answer:
@Test public void testJSONCreationWithoutAttributes() { event = FactoryGirl.createEvent(); json = event.toJSON(); assertTrue(json.has("name")); assertTrue(json.has("date")); }
@Test public void testJSONCreationWithAttributes() throws JSONException { HashMap<String, Object> attrs = new HashMap<String, Object>(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, 30); Date now = new Date(); attrs.put("attr1", true); attrs.put("attr2", "le_value"); attrs.put("attr3", now); attrs.put("name", "le_name"); attrs.put("date", LiquidTools.dateToString(cal.getTime())); event = FactoryGirl.createEvent(attrs); json = event.toJSON(); assertTrue(json.has("name")); assertTrue(json.has("date")); assertTrue(json.has("attr1")); assertTrue(json.has("attr2")); assertTrue(json.has("attr3")); assertEquals(true, json.getBoolean("attr1")); assertEquals("le_value", json.getString("attr2")); assertEquals(LiquidTools.dateToString(now), json.getString("attr3")); assertNotSame(LiquidTools.dateToString(cal.getTime()), json.getString("date")); assertNotSame("le_name", json.getString("name")); }