#pragma once #include "interfaces/report_factory.hpp" #include "mocks/report_mock.hpp" #include "params/report_params.hpp" #include "utils/transform.hpp" #include class ReportFactoryMock : public interfaces::ReportFactory { static std::vector convertToLabeled(const ReadingParameters& readingParams) { return utils::transform(readingParams, [](const auto& params) { return LabeledMetricParameters( utils::transform(std::get<0>(params), [](const auto& sensorPath) { return LabeledSensorParameters("Service", sensorPath); }), utils::stringToOperationType(std::get<1>(params)), std::get<2>(params), std::get<3>(params), utils::stringToCollectionTimeScope(std::get<4>(params)), CollectionDuration(Milliseconds(std::get<5>(params)))); }); } public: ReportFactoryMock() { using namespace testing; ON_CALL(*this, convertMetricParams(_, _)) .WillByDefault( WithArgs<1>(Invoke(&ReportFactoryMock::convertToLabeled))); ON_CALL(*this, make(A(), _, _, _, _, _, _, _, _)) .WillByDefault(WithArgs<0>(Invoke([](const std::string& name) { return std::make_unique>(name); }))); } MOCK_METHOD(std::vector, convertMetricParams, (boost::asio::yield_context&, const ReadingParameters&), (const, override)); MOCK_METHOD(std::unique_ptr, make, (const std::string&, const std::string&, bool, bool, Milliseconds, interfaces::ReportManager&, interfaces::JsonStorage&, std::vector, bool), (const, override)); auto& expectMake( std::optional> paramsRef, const testing::Matcher& rm, const testing::Matcher& js) { if (paramsRef) { const ReportParams& params = *paramsRef; return EXPECT_CALL( *this, make(params.reportName(), params.reportingType(), params.emitReadingUpdate(), params.logToMetricReportCollection(), params.interval(), rm, js, params.metricParameters(), params.enabled())); } else { using testing::_; return EXPECT_CALL(*this, make(_, _, _, _, _, rm, js, _, _)); } } };