SettingsRepository implements MongoRepository<Setting, String>, Queryable<Setting> { @Override public Optional<Setting> find(final String id) { if (id == null || id.isEmpty()) { return Optional.empty(); } final Class<?>[] types = {RangeSetting.class, FlagSetting.class}; for (final Class<?> t : types) { final Setting setting = (Setting) this.datastore.get(t, id); final Optional<Setting> res = Optional.ofNullable(setting); if (res.isPresent()) { return res; } } return Optional.empty(); } @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 testFindById() { when(this.ds.get(FlagSetting.class, "b")).thenReturn(this.flagSettings.get(0)); when(this.ds.get(FlagSetting.class, CoreMatchers.not(CoreMatchers.equalTo("b")))) .thenReturn(null); when(this.ds.get(RangeSetting.class, "r")).thenReturn(this.rangeSettings.get(0)); when(this.ds.get(RangeSetting.class, CoreMatchers.not(CoreMatchers.equalTo("r")))) .thenReturn(null); final Setting retrieved = this.sps.find("b").get(); assertEquals(this.flagSettings.get(0), retrieved); }