小编Jay*_*Jay的帖子

回调改造中的单元测试

在这里,我在演示者中获得了一些代码示例.如何在改装调用中为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)

我如何编写单元测试来涵盖这段代码的所有情况.

谢谢

junit android unit-testing mockito retrofit2

8
推荐指数
1
解决办法
6204
查看次数

定期检查 Service Worker 更新

如何每分钟轮询服务器以检查 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

5
推荐指数
1
解决办法
1713
查看次数

在滑动bottomSheet时动画箭头按钮

我有一张底片,在滑动时我需要设置动画箭头按钮,指示天气用户向上或向下滑动?在此输入图像描述

这是我的样品测试,当你在图片中看到的同时滑动底部纸张时,底部的箭头按钮应该向上旋转,同时向上滑动,向下滑动按钮应该向上旋转.

谢谢,杰伊

android android-animation android-layout bottom-sheet

2
推荐指数
1
解决办法
1564
查看次数