Skip to content

ClassCastException with @Autowired Spring JpaRepositories #294

@beatjost

Description

@beatjost

We have several test which run until version 1.21 of JMockit. From version 1.22 we get a 'ClassCastException'. The problem there is that the spring JpaRepository retuns a repository instance itself instead of a generic domain class.

Repository

public interface StateRepository extends JpaRepository<State, Long> {
   ...

Runtime code

@Autowired
StateRepository stateRepo;
...
activity.setState(stateRepo.findOne(stateId));  //returns repo instead of domain pojo

JUnit test

@Tested
StateUpdater stateUpdater;
@Injectable
StateRepository stateRepo;

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions