diff --git a/fastpair/analytics/BUILD b/fastpair/analytics/BUILD index 797b9d7f..dfb41b67 100644 --- a/fastpair/analytics/BUILD +++ b/fastpair/analytics/BUILD @@ -38,7 +38,7 @@ cc_test( srcs = ["analytics_recorder_test.cc"], deps = [ ":analytics", - "//internal/analytics:event_logger", + "//internal/analytics:mock_event_logger", "//internal/proto/analytics:fast_pair_log_cc_proto", "//proto:fast_pair_enums_cc_proto", "@com_github_protobuf_matchers//protobuf-matchers", diff --git a/fastpair/analytics/analytics_recorder_test.cc b/fastpair/analytics/analytics_recorder_test.cc index baa6eb24..c0a30db2 100644 --- a/fastpair/analytics/analytics_recorder_test.cc +++ b/fastpair/analytics/analytics_recorder_test.cc @@ -19,7 +19,7 @@ #include "gmock/gmock.h" #include "protobuf-matchers/protocol-buffer-matchers.h" #include "gtest/gtest.h" -#include "internal/analytics/event_logger.h" +#include "internal/analytics/mock_event_logger.h" #include "internal/proto/analytics/fast_pair_log.proto.h" #include "proto/fast_pair_enums.proto.h" #include "google/protobuf/message_lite.h" @@ -29,17 +29,10 @@ namespace fastpair { namespace analytics { namespace { +using ::nearby::analytics::MockEventLogger; using ::nearby::proto::fastpair::FastPairEvent; using ::nearby::proto::fastpair::FastPairLog; -class MockEventLogger : public ::nearby::analytics::EventLogger { - public: - MockEventLogger() = default; - ~MockEventLogger() override = default; - - MOCK_METHOD(void, Log, (const ::google::protobuf::MessageLite& message), (override)); -}; - class AnalyticsRecorderTest : public ::testing::Test { public: AnalyticsRecorderTest() = default; diff --git a/internal/analytics/BUILD b/internal/analytics/BUILD index 6e831f13..543f3e63 100644 --- a/internal/analytics/BUILD +++ b/internal/analytics/BUILD @@ -28,3 +28,16 @@ cc_library( ], deps = ["@com_google_protobuf//:protobuf_lite"], ) + +cc_library( + name = "mock_event_logger", + testonly = True, + hdrs = ["mock_event_logger.h"], + compatible_with = ["//buildenv/target:non_prod"], + visibility = ["//visibility:public"], + deps = [ + ":event_logger", + "@com_google_googletest//:gtest_for_library_testonly", + "@com_google_protobuf//:protobuf_lite", + ], +) diff --git a/internal/analytics/mock_event_logger.h b/internal/analytics/mock_event_logger.h new file mode 100644 index 00000000..167a6827 --- /dev/null +++ b/internal/analytics/mock_event_logger.h @@ -0,0 +1,34 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_MOCK_EVENT_LOGGER_H_ +#define THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_MOCK_EVENT_LOGGER_H_ + +#include "gmock/gmock.h" +#include "internal/analytics/event_logger.h" +#include "google/protobuf/message_lite.h" + +namespace nearby::analytics { + +class MockEventLogger : public ::nearby::analytics::EventLogger { + public: + MockEventLogger() = default; + ~MockEventLogger() override = default; + + MOCK_METHOD(void, Log, (const ::google::protobuf::MessageLite& message), (override)); +}; + +} // namespace nearby::analytics + +#endif // THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_MOCK_EVENT_LOGGER_H_ diff --git a/sharing/BUILD b/sharing/BUILD index 82cb4f51..29841c35 100644 --- a/sharing/BUILD +++ b/sharing/BUILD @@ -320,7 +320,7 @@ cc_test( "//base:casts", "//connections:core_types", "//internal/account", - "//internal/analytics:event_logger", + "//internal/analytics:mock_event_logger", "//internal/base:files", "//internal/flags:nearby_flags", "//internal/network:types", diff --git a/sharing/analytics/BUILD b/sharing/analytics/BUILD index cb0c8844..66c52a03 100644 --- a/sharing/analytics/BUILD +++ b/sharing/analytics/BUILD @@ -45,7 +45,7 @@ cc_test( srcs = ["analytics_recorder_test.cc"], deps = [ ":analytics", - "//internal/analytics:event_logger", + "//internal/analytics:mock_event_logger", "//internal/platform/implementation/g3", # fixdeps: keep "//proto:sharing_enums_cc_proto", "//sharing:types", diff --git a/sharing/analytics/analytics_recorder_test.cc b/sharing/analytics/analytics_recorder_test.cc index ca7e53ca..cb66eefa 100644 --- a/sharing/analytics/analytics_recorder_test.cc +++ b/sharing/analytics/analytics_recorder_test.cc @@ -26,7 +26,7 @@ #include "protobuf-matchers/protocol-buffer-matchers.h" #include "gtest/gtest.h" #include "absl/strings/string_view.h" -#include "internal/analytics/event_logger.h" +#include "internal/analytics/mock_event_logger.h" #include "proto/sharing_enums.pb.h" #include "sharing/analytics/analytics_device_settings.h" #include "sharing/analytics/analytics_information.h" @@ -48,6 +48,7 @@ namespace { using ::location::nearby::proto::sharing::EventCategory; using ::location::nearby::proto::sharing::EventType; using ::location::nearby::proto::sharing::OSType; +using ::nearby::analytics::MockEventLogger; using ::nearby::sharing::analytics::proto::SharingLog; using ::nearby::sharing::proto::DataUsage; using ::nearby::sharing::proto::DeviceVisibility; @@ -59,14 +60,6 @@ constexpr absl::string_view kFileMimeType = "application/pdf"; constexpr absl::string_view kTextMimeType = "text/plain"; constexpr absl::string_view kAppPackageName = "com.google.android.youtube"; -class MockEventLogger : public ::nearby::analytics::EventLogger { - public: - MockEventLogger() = default; - ~MockEventLogger() override = default; - - MOCK_METHOD(void, Log, (const ::google::protobuf::MessageLite& message), (override)); -}; - class AnalyticsRecorderTest : public ::testing::Test { public: AnalyticsRecorderTest() = default; diff --git a/sharing/nearby_sharing_event_logger_test.cc b/sharing/nearby_sharing_event_logger_test.cc index c6a4a0ed..cb4d2e7c 100644 --- a/sharing/nearby_sharing_event_logger_test.cc +++ b/sharing/nearby_sharing_event_logger_test.cc @@ -20,7 +20,7 @@ #include "gmock/gmock.h" #include "protobuf-matchers/protocol-buffer-matchers.h" #include "gtest/gtest.h" -#include "internal/analytics/event_logger.h" +#include "internal/analytics/mock_event_logger.h" #include "proto/sharing_enums.pb.h" #include "sharing/common/nearby_share_prefs.h" #include "sharing/internal/test/fake_preference_manager.h" @@ -32,16 +32,9 @@ namespace sharing { namespace { using ::location::nearby::proto::sharing::EventCategory; using ::location::nearby::proto::sharing::EventType; -using ::nearby::analytics::EventLogger; +using ::nearby::analytics::MockEventLogger; using ::nearby::sharing::analytics::proto::SharingLog; -class MockEventLogger : public EventLogger { - public: - ~MockEventLogger() override = default; - - MOCK_METHOD(void, Log, (const proto2::MessageLite& message), (override)); -}; - class NearbySharingEventLoggerTest : public ::testing::Test { public: NearbySharingEventLoggerTest() = default;