SettingsRepository implements MongoRepository<Setting, String>, Queryable<Setting> { @Override public Setting createOrUpdate(final Setting setting) { if (setting.getId() != null && !setting.getId().isEmpty()) { throw new IllegalArgumentException("This instance already has an id, can't create"); } setting.setId(this.idgen.generateId()); this.datastore.save(setting); if (LOGGER.isInfoEnabled()) { LOGGER.info(String.format("Saved setting with id %s", setting.getId())); } return setting; } @Inject  SettingsRepository(final Datastore datastore, final IdGenerator idgen); @Override List<Setting> findAll(); @Override Optional<Setting> find(final String id); @Override void delete(final String id); @Override Setting createOrUpdate(final Setting setting); void createOrOverride(final Setting setting); @Override QueryResult<Setting> query(final net.explorviz.shared.querying.Query<Setting> query);  }
@Test public void testExisting() { final FlagSetting s = new FlagSetting("id", "testname", "a test setting", "default", false); assertThrows(IllegalArgumentException.class, () -> this.sps.createOrUpdate(s)); }