@SuppressWarnings("ResultOfMethodCallIgnored") @Test void findAllAsStreamQueryWithContent() throws IOException { EntityType entityType = mock(EntityType.class); try (InMemoryRepository inMemoryRepository = new InMemoryRepository(entityType)) { assertThrows( UnsupportedOperationException.class, () -> inMemoryRepository .findAll(new QueryImpl<>().eq("attr", "val").and().eq("attr2", "val")) .collect(Collectors.toList())); } }
@Override public Stream<Entity> findAll(Query<Entity> q) { if (new QueryImpl<>().equals(q)) { return entities.values().stream(); } else { if (q.getRules().size() == 1) { QueryRule r = q.getRules().iterator().next(); if (r.getOperator() == Operator.EQUALS) { return entities.entrySet().stream() .map( e -> { if (e.getValue().get(r.getField()).equals(r.getValue())) { return e.getValue(); } else { return null; } }) .filter(Objects::nonNull); } } throw new UnsupportedOperationException(); } }
InMemoryRepository implements Repository<Entity> { @Override public Stream<Entity> findAll(Query<Entity> q) { if (new QueryImpl<>().equals(q)) { return entities.values().stream(); } else { if (q.getRules().size() == 1) { QueryRule r = q.getRules().iterator().next(); if (r.getOperator() == Operator.EQUALS) { return entities.entrySet().stream() .map( e -> { if (e.getValue().get(r.getField()).equals(r.getValue())) { return e.getValue(); } else { return null; } }) .filter(Objects::nonNull); } } throw new UnsupportedOperationException(); } } }
InMemoryRepository implements Repository<Entity> { @Override public Stream<Entity> findAll(Query<Entity> q) { if (new QueryImpl<>().equals(q)) { return entities.values().stream(); } else { if (q.getRules().size() == 1) { QueryRule r = q.getRules().iterator().next(); if (r.getOperator() == Operator.EQUALS) { return entities.entrySet().stream() .map( e -> { if (e.getValue().get(r.getField()).equals(r.getValue())) { return e.getValue(); } else { return null; } }) .filter(Objects::nonNull); } } throw new UnsupportedOperationException(); } } InMemoryRepository(EntityType entityType); }
InMemoryRepository implements Repository<Entity> { @Override public Stream<Entity> findAll(Query<Entity> q) { if (new QueryImpl<>().equals(q)) { return entities.values().stream(); } else { if (q.getRules().size() == 1) { QueryRule r = q.getRules().iterator().next(); if (r.getOperator() == Operator.EQUALS) { return entities.entrySet().stream() .map( e -> { if (e.getValue().get(r.getField()).equals(r.getValue())) { return e.getValue(); } else { return null; } }) .filter(Objects::nonNull); } } throw new UnsupportedOperationException(); } } InMemoryRepository(EntityType entityType); @Override String getName(); EntityType getEntityType(); @Override Iterator<Entity> iterator(); @Override void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize); @Override void close(); @Override Query<Entity> query(); @Override long count(Query<Entity> q); @Override Stream<Entity> findAll(Query<Entity> q); @Override Entity findOne(Query<Entity> q); @Override Entity findOneById(Object id); @Override Entity findOneById(Object id, Fetch fetch); @Override Stream<Entity> findAll(Stream<Object> ids); @Override Stream<Entity> findAll(Stream<Object> ids, Fetch fetch); @Override long count(); @Override void update(Entity entity); @Override void update(Stream<Entity> entities); @Override void delete(Entity entity); @Override void delete(Stream<Entity> entities); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll(); @Override void add(Entity entity); @Override Integer add(Stream<Entity> entities); @Override Set<RepositoryCapability> getCapabilities(); @Override Set<Operator> getQueryOperators(); @Override AggregateResult aggregate(AggregateQuery aggregateQuery); }
InMemoryRepository implements Repository<Entity> { @Override public Stream<Entity> findAll(Query<Entity> q) { if (new QueryImpl<>().equals(q)) { return entities.values().stream(); } else { if (q.getRules().size() == 1) { QueryRule r = q.getRules().iterator().next(); if (r.getOperator() == Operator.EQUALS) { return entities.entrySet().stream() .map( e -> { if (e.getValue().get(r.getField()).equals(r.getValue())) { return e.getValue(); } else { return null; } }) .filter(Objects::nonNull); } } throw new UnsupportedOperationException(); } } InMemoryRepository(EntityType entityType); @Override String getName(); EntityType getEntityType(); @Override Iterator<Entity> iterator(); @Override void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize); @Override void close(); @Override Query<Entity> query(); @Override long count(Query<Entity> q); @Override Stream<Entity> findAll(Query<Entity> q); @Override Entity findOne(Query<Entity> q); @Override Entity findOneById(Object id); @Override Entity findOneById(Object id, Fetch fetch); @Override Stream<Entity> findAll(Stream<Object> ids); @Override Stream<Entity> findAll(Stream<Object> ids, Fetch fetch); @Override long count(); @Override void update(Entity entity); @Override void update(Stream<Entity> entities); @Override void delete(Entity entity); @Override void delete(Stream<Entity> entities); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll(); @Override void add(Entity entity); @Override Integer add(Stream<Entity> entities); @Override Set<RepositoryCapability> getCapabilities(); @Override Set<Operator> getQueryOperators(); @Override AggregateResult aggregate(AggregateQuery aggregateQuery);  }