InMemoryDatabase implements IDatabase { @Override public void upsert(final IObject document, final String collectionName) throws IDatabaseException { try { DataBaseItem item = IOC.resolve(Keys.getOrAdd(DataBaseItem.class.getCanonicalName()), document, collectionName); if (null == item.getId()) { insert(item); } else { update(item); } } catch (ResolutionException e) { throw new IDatabaseException("Failed to create DataBaseItem", e); } } InMemoryDatabase(); @Override void upsert(final IObject document, final String collectionName); @Override void createCollection(final String collectionName); @Override void insert(final IObject document, final String collectionName); @Override void update(final IObject document, final String collectionName); @Override IObject getById(final Object id, final String collectionName); @Override List<IObject> select(final IObject condition, final String collectionName); @Override void delete(final IObject document, final String collectionName); @Override Long count(final IObject condition, final String collectionName);  }
@Test(expected = IDatabaseException.class) public void testUpsertToNotExistingCollection() throws InvalidArgumentException, IDatabaseException, SerializeException, ReadValueException { InMemoryDatabase database = new InMemoryDatabase(); IObject document = new DSObject("{}"); database.upsert(document, "collection_name"); }