@Test void addStream() { Entity entity0 = mock(Entity.class); when(entity0.getIdValue()).thenReturn("id0"); when(entity0.get("id")).thenReturn("id0"); when(entity0.getString("id")).thenReturn("id0"); Entity entity1 = mock(Entity.class); when(entity1.getIdValue()).thenReturn("id1"); when(entity1.get("id")).thenReturn("id1"); when(entity1.getString("id")).thenReturn("id1"); Stream<Entity> entities = Stream.of(entity0, entity1); assertEquals(valueOf(2), inMemoryRepository.add(entities)); }
@Override public void add(Entity entity) { Object id = getId(entity); if (id == null) { throw new NullPointerException("Entity ID is null."); } if (entities.containsKey(id)) { throw new IllegalStateException("Entity with id " + id + " already exists"); } entities.put(id, entity); }
InMemoryRepository implements Repository<Entity> { @Override public void add(Entity entity) { Object id = getId(entity); if (id == null) { throw new NullPointerException("Entity ID is null."); } if (entities.containsKey(id)) { throw new IllegalStateException("Entity with id " + id + " already exists"); } entities.put(id, entity); } }
InMemoryRepository implements Repository<Entity> { @Override public void add(Entity entity) { Object id = getId(entity); if (id == null) { throw new NullPointerException("Entity ID is null."); } if (entities.containsKey(id)) { throw new IllegalStateException("Entity with id " + id + " already exists"); } entities.put(id, entity); } InMemoryRepository(EntityType entityType); }
InMemoryRepository implements Repository<Entity> { @Override public void add(Entity entity) { Object id = getId(entity); if (id == null) { throw new NullPointerException("Entity ID is null."); } if (entities.containsKey(id)) { throw new IllegalStateException("Entity with id " + id + " already exists"); } entities.put(id, entity); } 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 void add(Entity entity) { Object id = getId(entity); if (id == null) { throw new NullPointerException("Entity ID is null."); } if (entities.containsKey(id)) { throw new IllegalStateException("Entity with id " + id + " already exists"); } entities.put(id, entity); } 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);  }