From 308ed0b4d9882f3e640fdc075038f476ab7c79bc Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Fri, 18 Feb 2022 17:01:11 +0800 Subject: [PATCH] UT modify Signed-off-by: fangJinliang1 Change-Id: I76d1b161ba948fd681f6f9dcffacf83ddad7b7b3 Signed-off-by: fangJinliang1 --- .../ans/native/src/notification_request.cpp | 15 +++++++-------- .../advanced_notification_service_test.cpp | 4 ++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index f48ccfb59..beba5fa04 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -1545,15 +1545,14 @@ bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const } jsonObject["distributedOptions"] = optObj; - if (!notificationFlags_) { - return false; - } - nlohmann::json flagsObj; - if (!NotificationJsonConverter::ConvertToJosn(notificationFlags_.get(), flagsObj)) { - ANS_LOGE("Cannot convert notificationFlags to JSON"); - return false; + if (notificationFlags_) { + nlohmann::json flagsObj; + if (!NotificationJsonConverter::ConvertToJosn(notificationFlags_.get(), flagsObj)) { + ANS_LOGE("Cannot convert notificationFlags to JSON"); + return false; + } + jsonObject["notificationFlags"] = flagsObj; } - jsonObject["notificationFlags"] = flagsObj; return true; } diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index fc1d0c27c..f58b8f4e7 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1229,6 +1229,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09600, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09700, Function | SmallTest | Level1) { + EXPECT_EQ( + (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK); TestAddSlot(NotificationConstant::SlotType::OTHER); bool allowed = true; EXPECT_EQ((int)advancedNotificationService_->IsSpecialBundleAllowedNotify( @@ -1243,6 +1245,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09700, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09800, Function | SmallTest | Level1) { + EXPECT_EQ( + (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK); std::vector> notifications; bool allowed = true; EXPECT_EQ((int)advancedNotificationService_->IsSpecialBundleAllowedNotify( -- Gitee