我有一个使用以下方法的服务类:
data3 = data2.to_sql('main', con=engine, if_exists='replace',index=False)
cursor.execute("alter table main add status varchar(128)")
for i in ['tab1','tab2']:
cursor.execute("update main left join {} on main.email={}.email set status=if({}.email is not null,'match','nonmatch')".format(i,i,i))
conn.commit()
data_2=cursor.fetchall()
data3=data_2
print data_2
我模拟了此类,并且我想验证作为参数传递的列表只有一个元素。我是这样的:
update main left join (select * from tab1 union all select * from tab2) total on main.email=total.email
set status=if(total.email is not null,'match','nonmatch');
如您所见,我必须将参数强制转换为void doSomething(List<String> list)
,否则它将无法编译:
verify(myService).doSomething((List<String>) argThat(hasSize(1))))
问题:如何在不强制转换的情况下验证通话?我想让事情保持简单,可读和优雅。
答案 0 :(得分:3)
我更喜欢这种解决方案:
final ArgumentCaptor<List> argumentCaptor = ArgumentCaptor.forClass(List.class);
verify(myService).doSomething(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().size()).isEqualTo(1);