我正在尝试为Investigator存储库编写Junit
测试用例。我尝试过以下操作,但出现错误java.lang.ClassCastException
,有人可以告诉我为什么会出现此错误吗?
测试用例
@Test
public void testFindSinvestigatorName() throws JsonProcessingException {
Investigator invest = new Investigator();
invest.setsInvestigatorName("abc");
Set<Investigator> invest1 = new HashSet<>();
invest1.add(invest);
Investigator saveInDb = testEm.merge(invest);
Set<Investigator> getFromDb = investRepo.findSinvestigatorName();
assertEquals(saveInDb.getsInvestigatorName(),getFromDb.iterator().next().sInvestigatorName);
}
}
堆栈跟踪
java.lang.ClassCastException: java.util.HashMap cannot be cast to com.spacestudy.model.Investigator
at com.spacestudy.repository.TestInvestigatorRepository.testFindSinvestigatorName(TestInvestigatorRepository.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)