1 #pragma once 2 3 #include "interfaces/report_factory.hpp" 4 #include "mocks/report_mock.hpp" 5 #include "params/report_params.hpp" 6 7 #include <gmock/gmock.h> 8 9 class ReportFactoryMock : public interfaces::ReportFactory 10 { 11 public: 12 ReportFactoryMock() 13 { 14 using namespace testing; 15 16 ON_CALL(*this, 17 make(A<boost::asio::yield_context&>(), _, _, _, _, _, _, _, _)) 18 .WillByDefault(WithArgs<1>(Invoke([](const std::string& name) { 19 return std::make_unique<NiceMock<ReportMock>>(name); 20 }))); 21 ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _, _)) 22 .WillByDefault(WithArgs<0>(Invoke([](const std::string& name) { 23 return std::make_unique<NiceMock<ReportMock>>(name); 24 }))); 25 } 26 27 MOCK_METHOD(std::unique_ptr<interfaces::Report>, make, 28 (boost::asio::yield_context&, const std::string&, 29 const std::string&, bool, bool, std::chrono::milliseconds, 30 const ReadingParameters&, interfaces::ReportManager&, 31 interfaces::JsonStorage&), 32 (const, override)); 33 MOCK_METHOD(std::unique_ptr<interfaces::Report>, make, 34 (const std::string&, const std::string&, bool, bool, 35 std::chrono::milliseconds, const ReadingParameters&, 36 interfaces::ReportManager&, interfaces::JsonStorage&, 37 std::vector<LabeledMetricParameters>), 38 (const, override)); 39 40 auto& expectMake( 41 const testing::Matcher<boost::asio::yield_context&>& yield, 42 std::optional<std::reference_wrapper<const ReportParams>> paramsRef, 43 const testing::Matcher<interfaces::ReportManager&>& rm, 44 const testing::Matcher<interfaces::JsonStorage&>& js) 45 { 46 if (paramsRef) 47 { 48 const ReportParams& params = *paramsRef; 49 return EXPECT_CALL(*this, make(yield, params.reportName(), 50 params.reportingType(), 51 params.emitReadingUpdate(), 52 params.logToMetricReportCollection(), 53 params.interval(), 54 params.readingParameters(), rm, js)); 55 } 56 else 57 { 58 using testing::_; 59 return EXPECT_CALL(*this, make(yield, _, _, _, _, _, _, rm, js)); 60 } 61 } 62 63 auto& expectMake( 64 std::optional<std::reference_wrapper<const ReportParams>> paramsRef, 65 const testing::Matcher<interfaces::ReportManager&>& rm, 66 const testing::Matcher<interfaces::JsonStorage&>& js, 67 const testing::Matcher<std::vector<LabeledMetricParameters>>& lrp) 68 { 69 if (paramsRef) 70 { 71 const ReportParams& params = *paramsRef; 72 return EXPECT_CALL(*this, 73 make(params.reportName(), params.reportingType(), 74 params.emitReadingUpdate(), 75 params.logToMetricReportCollection(), 76 params.interval(), 77 params.readingParameters(), rm, js, lrp)); 78 } 79 else 80 { 81 using testing::_; 82 return EXPECT_CALL(*this, make(_, _, _, _, _, _, rm, js, lrp)); 83 } 84 } 85 }; 86