1 #pragma once 2 3 #include "interfaces/sensor.hpp" 4 #include "utils/generate_unique_mock_id.hpp" 5 6 #include <gmock/gmock.h> 7 8 class SensorMock : public interfaces::Sensor 9 { 10 public: 11 explicit SensorMock() 12 { 13 initialize(); 14 } 15 16 explicit SensorMock(Id sensorId) : mockSensorId(sensorId) 17 { 18 initialize(); 19 } 20 21 static Id makeId(std::string_view service, std::string_view path) 22 { 23 return Id("SensorMock", service, path); 24 } 25 26 MOCK_METHOD(Id, id, (), (const, override)); 27 MOCK_METHOD(std::string, metadata, (), (const, override)); 28 MOCK_METHOD(void, registerForUpdates, 29 (const std::weak_ptr<interfaces::SensorListener>&), (override)); 30 MOCK_METHOD(void, unregisterFromUpdates, 31 (const std::weak_ptr<interfaces::SensorListener>&), (override)); 32 33 const uint64_t mockId = generateUniqueMockId(); 34 35 Id mockSensorId = Id("SensorMock", "", ""); 36 37 private: 38 void initialize() 39 { 40 ON_CALL(*this, id()).WillByDefault(testing::Invoke([this] { 41 return this->mockSensorId; 42 })); 43 } 44 }; 45