@Test public void checkToObject_noType() { Document document = PowerMockito.mock(Document.class); final HashMap<String, Object> properties = new HashMap<>(); when(document.getProperties()).thenReturn(properties); when(document.getId()).thenReturn("foo"); CouchbaseLiteOrm orm = new CouchbaseLiteOrmInternal(); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("The document foo doesn't have set the \"type\" property."); orm.toObject(document); }
public <T> T toObject(Document document) { final Map<String, Object> properties = document.getProperties(); final String sDocumentType = (String) properties.get("type"); if (sDocumentType == null) { throw new IllegalArgumentException("The document " + document.getId() + " doesn't have set the \"type\" property."); } @SuppressWarnings("unchecked") final Mapper<T> mapper = (Mapper<T>) stringToMapper.get(sDocumentType); if (mapper == null) { throw new IllegalArgumentException("Unknown type " + sDocumentType + " at document " + document.getId() + "."); } return mapper.toObject(properties); }
CouchbaseLiteOrm { public <T> T toObject(Document document) { final Map<String, Object> properties = document.getProperties(); final String sDocumentType = (String) properties.get("type"); if (sDocumentType == null) { throw new IllegalArgumentException("The document " + document.getId() + " doesn't have set the \"type\" property."); } @SuppressWarnings("unchecked") final Mapper<T> mapper = (Mapper<T>) stringToMapper.get(sDocumentType); if (mapper == null) { throw new IllegalArgumentException("Unknown type " + sDocumentType + " at document " + document.getId() + "."); } return mapper.toObject(properties); } }
CouchbaseLiteOrm { public <T> T toObject(Document document) { final Map<String, Object> properties = document.getProperties(); final String sDocumentType = (String) properties.get("type"); if (sDocumentType == null) { throw new IllegalArgumentException("The document " + document.getId() + " doesn't have set the \"type\" property."); } @SuppressWarnings("unchecked") final Mapper<T> mapper = (Mapper<T>) stringToMapper.get(sDocumentType); if (mapper == null) { throw new IllegalArgumentException("Unknown type " + sDocumentType + " at document " + document.getId() + "."); } return mapper.toObject(properties); } CouchbaseLiteOrm(); }
CouchbaseLiteOrm { public <T> T toObject(Document document) { final Map<String, Object> properties = document.getProperties(); final String sDocumentType = (String) properties.get("type"); if (sDocumentType == null) { throw new IllegalArgumentException("The document " + document.getId() + " doesn't have set the \"type\" property."); } @SuppressWarnings("unchecked") final Mapper<T> mapper = (Mapper<T>) stringToMapper.get(sDocumentType); if (mapper == null) { throw new IllegalArgumentException("Unknown type " + sDocumentType + " at document " + document.getId() + "."); } return mapper.toObject(properties); } CouchbaseLiteOrm(); static CouchbaseLiteOrm newInstance(); T toObject(Document document); Document toDocument(T object, Document document); Map<String, Object> toProperties(T object); }
CouchbaseLiteOrm { public <T> T toObject(Document document) { final Map<String, Object> properties = document.getProperties(); final String sDocumentType = (String) properties.get("type"); if (sDocumentType == null) { throw new IllegalArgumentException("The document " + document.getId() + " doesn't have set the \"type\" property."); } @SuppressWarnings("unchecked") final Mapper<T> mapper = (Mapper<T>) stringToMapper.get(sDocumentType); if (mapper == null) { throw new IllegalArgumentException("Unknown type " + sDocumentType + " at document " + document.getId() + "."); } return mapper.toObject(properties); } CouchbaseLiteOrm(); static CouchbaseLiteOrm newInstance(); T toObject(Document document); Document toDocument(T object, Document document); Map<String, Object> toProperties(T object);  }