TypedProperty implements Model { @Override public void read(JSONObject object) throws JSONException { if (!object.getString(TYPE).equals(getType())) { throw new JSONException("Invalid type"); } setName(object.getString(NAME)); }  abstract String getType(); String getName(); void setName(String name); @Override void read(JSONObject object); @Override void write(JSONStringer writer); @Override boolean equals(Object o); @Override int hashCode();  }
@Test(expected = JSONException.class) public void readDifferentTypeTest() throws JSONException { JSONObject mockJsonObject = mock(JSONObject.class); when(mockJsonObject.getString(CommonProperties.TYPE)).thenReturn("type"); TypedProperty mockLog = new MockTypedProperty(); mockLog.read(mockJsonObject); }