All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.beanmapper.spring.web.mockmvc.MockEntityFinder Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
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> repositories = new HashMap<>();

    @Override
    public Object find(Long id, Class entityClass) throws EntityNotFoundException {
        CrudRepository 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 repository, Class entityClass) {
        repositories.put(entityClass, repository);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy