io.beanmapper.spring.web.mockmvc.MockEntityFinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of beanmapper-spring Show documentation
Show all versions of beanmapper-spring Show documentation
Spring support for the Bean Mapper
package io.beanmapper.spring.web.mockmvc;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityNotFoundException;
import io.beanmapper.spring.web.EntityFinder;
import org.springframework.data.domain.Persistable;
import org.springframework.data.repository.CrudRepository;
public class MockEntityFinder implements EntityFinder {
private Map, CrudRepository extends Persistable, Long>> repositories = new HashMap<>();
@Override
public Object find(Long id, Class> entityClass) throws EntityNotFoundException {
CrudRepository extends Persistable, Long> repository = repositories.get(entityClass);
if (repository == null) {
throw new RuntimeException("No constructor found for " + entityClass.getSimpleName() +
". Make sure to register the class in addConverters.registerExpectation");
}
return repository.findOne(id);
}
public void addRepository(CrudRepository extends Persistable, Long> repository, Class> entityClass) {
repositories.put(entityClass, repository);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy