DSObject implements IObject { @Override public Object getValue(final IFieldName name) throws ReadValueException, InvalidArgumentException { if (null == name) { throw new InvalidArgumentException("Name parameter should not be null."); } return body.get(name); } DSObject(final Map<IFieldName, Object> objectEntries);  DSObject(final String body);  DSObject(); @Override Object getValue(final IFieldName name); @Override void setValue(final IFieldName name, final Object value); @Override void deleteField(final IFieldName name); @Override T serialize(); @Override Iterator<Map.Entry<IFieldName, Object>> iterator();  }
@Test public void checkCreationByString() throws Exception { IObject obj = new DSObject("{\n" + " \"value\": 1,\n" + " \"string\": \"foo\"\n" + "}"); assertNotNull(obj); assertEquals(1, obj.getValue(new FieldName("value"))); assertEquals("foo", obj.getValue(new FieldName("string"))); }
@Test public void checkCreationByMap() throws Exception { IFieldName fieldName = mock(IFieldName.class); Object obj = mock(Object.class); Map<IFieldName, Object> map = new HashMap<IFieldName, Object>(){{put(fieldName, obj);}}; IObject result = new DSObject(map); assertNotNull(obj); assertEquals(obj, result.getValue(fieldName)); }
@Test (expected = InvalidArgumentException.class) public void checkExceptionOnGetValue() throws Exception { (new DSObject()).getValue(null); fail(); }