BaseEntityMemoryStore implements Store<T, UUID> { public T create(@Valid T entity) throws EntityAlreadyExistsException, InvalidEntityException { if (entity.getId() == null) { entity.setId(UUID.randomUUID()); } if (exists(entity)) { throw new EntityAlreadyExistsException(); } entities.put(entity.getId(), entity); return entity; }  T create(@Valid T entity); void update(@Valid T entity); void delete(@Valid T entity); Integer countAll(); List<T> findAll(Integer number, Integer offset); List<T> findByIds(final List<UUID> ids); T findById(UUID id);  }
@Test(expected = EntityAlreadyExistsException.class) public void testCreateSeveralTimesWithSameIdThrowsException() throws Exception { MyEntity entity = store.create(new MyEntity()); store.create(entity); }