在这里,我在演示者中获得了一些代码示例.如何在改装调用中为onSuccess和onFailure编写测试
public void getNotifications(final List<HashMap<String,Object>> notifications){
if (!"".equalsIgnoreCase(userDB.getValueFromSqlite("email",1))) {
UserNotifications userNotifications =
new UserNotifications(userDB.getValueFromSqlite("email",1),Integer.parseInt(userDB.getValueFromSqlite("userId",1).trim()));
Call call = apiInterface.getNotifications(userNotifications);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
UserNotifications userNotifications1 = (UserNotifications) response.body();
if(userNotifications1.getNotifications().isEmpty()){
view.setListToAdapter(notifications);
onFailure(call,new Throwable());
}
else {
for (UserNotifications.Datum datum:userNotifications1.getNotifications()) {
HashMap<String,Object> singleNotification= new HashMap<>();
singleNotification.put("notification",datum.getNotification());
singleNotification.put("date",datum.getDate());
notifications.add(singleNotification);
}
view.setListToAdapter(notifications);
}
}
@Override
public void onFailure(Call call, Throwable t) {
call.cancel();
}
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
我如何编写单元测试来涵盖这段代码的所有情况.
谢谢
如何每分钟轮询服务器以检查 Service Worker 更新?
我使用了 SWUpdate angular 的可用方法,但它不轮询服务器,而是在页面刷新时获取更新和缓存,这不是必需的。
我遇到了 checkForUpdate() 方法,它非常相似,但不确定它是如何工作的?
任何帮助将不胜感激。
ngOnInit(){
if(this.swUpdate.isEnabled){
this.swUpdate.available.subscribe( () => {
if(confirm("New Version available.. Load?")){
window.location.reload();
}
})
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码在第二次重新加载时从缓存中获取数据。
service-worker progressive-web-apps angular-cli angular angular-service-worker
android ×2
angular ×1
angular-cli ×1
bottom-sheet ×1
junit ×1
mockito ×1
retrofit2 ×1
unit-testing ×1