Create Fake Presenter and Factory of presenter for further testing in UI broker

PiperOrigin-RevId: 522111553
This commit is contained in:
hai007
2023-04-05 11:42:32 -07:00
committed by Copybara-Service
parent c41fd2ed2a
commit 0705059e94
3 changed files with 91 additions and 1 deletions
@@ -0,0 +1,57 @@
// Copyright 2023 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_FASTPAIR_UI_FAST_PAIR_FAKE_FAST_PAIR_PRESENTER_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_UI_FAST_PAIR_FAKE_FAST_PAIR_PRESENTER_H_
#include <memory>
#include "fastpair/ui/fast_pair/fast_pair_presenter_impl.h"
namespace nearby {
namespace fastpair {
class FakeFastPairPresenter : public FastPairPresenter {
public:
void ShowDiscovery(
const FastPairDevice& device,
FastPairNotificationController& notification_controller) override {
show_discovery_ = true;
}
bool show_deiscovery() { return show_discovery_; }
private:
bool show_discovery_ = false;
};
class FakeFastPairPresenterFactory : public FastPairPresenterImpl::Factory {
public:
std::unique_ptr<FastPairPresenter> CreateInstance() override {
auto fake_fast_pair_presenter = std::make_unique<FakeFastPairPresenter>();
fake_fast_pair_presenter_ = fake_fast_pair_presenter.get();
return fake_fast_pair_presenter;
}
FakeFastPairPresenter* fake_fast_pair_presenter() {
return fake_fast_pair_presenter_;
}
protected:
FakeFastPairPresenter* fake_fast_pair_presenter_ = nullptr;
};
} // namespace fastpair
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_FASTPAIR_UI_FAST_PAIR_FAKE_FAST_PAIR_PRESENTER_H_
@@ -25,6 +25,26 @@
namespace nearby {
namespace fastpair {
// static
FastPairPresenterImpl::Factory*
FastPairPresenterImpl::Factory::g_test_factory_ = nullptr;
// static
std::unique_ptr<FastPairPresenter> FastPairPresenterImpl::Factory::Create() {
if (g_test_factory_) {
return g_test_factory_->CreateInstance();
}
return std::make_unique<FastPairPresenterImpl>();
}
// static
void FastPairPresenterImpl::Factory::SetFactoryForTesting(
Factory* g_test_factory) {
g_test_factory_ = g_test_factory;
}
FastPairPresenterImpl::Factory::~Factory() = default;
void FastPairPresenterImpl::ShowDiscovery(
const FastPairDevice& device,
FastPairNotificationController& notification_controller) {
@@ -27,10 +27,23 @@ namespace fastpair {
class FastPairPresenterImpl : public FastPairPresenter {
public:
class Factory {
public:
static std::unique_ptr<FastPairPresenter> Create();
static void SetFactoryForTesting(Factory* g_test_factory);
protected:
virtual ~Factory();
virtual std::unique_ptr<FastPairPresenter> CreateInstance() = 0;
private:
static Factory* g_test_factory_;
};
FastPairPresenterImpl() = default;
FastPairPresenterImpl(const FastPairPresenterImpl&) = delete;
FastPairPresenterImpl& operator=(const FastPairPresenterImpl&) = delete;
~FastPairPresenterImpl() override = default;
void ShowDiscovery(
const FastPairDevice& device,