diff --git a/fastpair/ui/fast_pair/fast_pair_notification_controller_test.cc b/fastpair/ui/fast_pair/fast_pair_notification_controller_test.cc index 86a40579..997b8aa6 100644 --- a/fastpair/ui/fast_pair/fast_pair_notification_controller_test.cc +++ b/fastpair/ui/fast_pair/fast_pair_notification_controller_test.cc @@ -14,16 +14,16 @@ #include "fastpair/ui/fast_pair/fast_pair_notification_controller.h" -#include -#include #include +#include #include +#include #include "gmock/gmock.h" #include "protobuf-matchers/protocol-buffer-matchers.h" #include "gtest/gtest.h" #include "fastpair/repository/device_metadata.h" -#include "internal/platform/medium_environment.h" +#include "fastpair/ui/fast_pair/fake_fast_pair_notification_controller_observer.h" namespace nearby { namespace fastpair { @@ -33,64 +33,29 @@ const int64_t kDeviceId = 10148625; const char kModelId[] = "9adb11"; const char kDeviceName[] = "Pixel Buds Pro"; -class FastPairNotificationControllerObserver - : public FastPairNotificationController::Observer { - public: - void OnUpdateDevice(const DeviceMetadata& device) override { - device_metadata_name_list_.push_back(device.GetDetails().name()); - on_update_device_count_++; - } - - bool CheckDeviceMetadataListContainTestDevice( - const std::string& device_name) { - auto it = std::find(device_metadata_name_list_.begin(), - device_metadata_name_list_.end(), device_name); - return it != device_metadata_name_list_.end(); - } - - int on_update_device_count() { return on_update_device_count_; } - - private: - std::vector device_metadata_name_list_; - int on_update_device_count_ = 0; -}; - class FastPairNotificationControllerTest : public ::testing::Test { protected: - FastPairNotificationControllerTest() {} - ~FastPairNotificationControllerTest() override = default; - void SetUp() override { - notification_controller_ = - std::make_shared(); - notification_controller_obsesrver_ = - std::make_unique(); - notification_controller_->AddObserver( - notification_controller_obsesrver_.get()); + FastPairNotificationControllerTest() { + notification_controller_.AddObserver(¬ification_controller_obsesrver_); } - void TearDown() override { env_.Stop(); } - void TriggerOnUpdateDevice(DeviceMetadata& device) { - notification_controller_->ShowGuestDiscoveryNotification(device); + notification_controller_.ShowGuestDiscoveryNotification(device); } - MediumEnvironment& env_{MediumEnvironment::Instance()}; - std::shared_ptr notification_controller_; - std::unique_ptr - notification_controller_obsesrver_; + FastPairNotificationController notification_controller_; + FakeFastPairNotificationControllerObserver notification_controller_obsesrver_; }; TEST_F(FastPairNotificationControllerTest, ShowGuestDiscoveryNotification) { - env_.Start(); proto::GetObservedDeviceResponse response; response.mutable_device()->set_id(kDeviceId); response.mutable_device()->set_name(kDeviceName); DeviceMetadata device_metadata(response); TriggerOnUpdateDevice(device_metadata); EXPECT_TRUE(notification_controller_obsesrver_ - ->CheckDeviceMetadataListContainTestDevice(kDeviceName)); - EXPECT_EQ(1, notification_controller_obsesrver_->on_update_device_count()); - env_.Stop(); + .CheckDeviceMetadataListContainTestDevice(kDeviceName)); + EXPECT_EQ(1, notification_controller_obsesrver_.on_update_device_count()); } } // namespace