java.lang.ClassCastException:无法将java.util.HashMap强制转换为[model]

时间:2018-09-04 14:40:04

标签: spring-data-jpa junit4

我正在尝试为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)

0 个答案:

没有答案