如何验证链接的方法调用?

时间:2019-06-20 11:17:18

标签: mocking mockito

我正在为我的项目的DAO类编写测试。但是,当我使用Mockito的verify()方法时,它会抛出NullPointerException,因为createQuery()方法会返回null。我该如何解决?

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private EntityManager entityManagerMock;

@InjectMocks
private TaksitPlanSatiriDao taksitPlanSatiriDao = new TaksitPlanSatiriDaoJpa();

@Before
public void setUp() {
    taksitPlanSatiriEntity = new TaksitPlanSatiriEntity();
}
@Test
public void shouldUpdateWhenGuncelleCalledWithTaksitPlanSatiriEntity() {
    taksitPlanSatiriDao.guncelle(taksitPlanSatiriEntity);
    Mockito.verify(entityManagerMock).createQuery(ArgumentMatchers.anyString()).executeUpdate();
}

1 个答案:

答案 0 :(得分:0)

尝试:

    ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
    WITH SERDEPROPERTIES (
      'field.delim'=',',
      'line.delim'='\n',
      'serialization.format'=',',
      'serialization.encoding'='UTF-8')
    STORED AS INPUTFORMAT
      'org.apache.hadoop.mapred.TextInputFormat'
    OUTPUTFORMAT
      'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
    TBLPROPERTIES("skip.header.line.count"="1")

这是基于“深层存根”文档的:

https://static.javadoc.io/org.mockito/mockito-core/2.28.2/org/mockito/Mockito.html#RETURNS_DEEP_STUBS