DI: allow to trigger the lazy instantiation of a mock service instance directly

Basically the mocking mechanism just switches the configuration
and then waits for the service to be accessed in order to cause acutual
instantiation of the mock service implementation. But sometimes we want
to prepare and rig the mock instance prior to the first invocation;
in such cases it can be handy just to trigger the lazy creating process
This commit is contained in:
Fischlurch 2018-04-08 18:40:40 +02:00
parent e99ad7a3e6
commit 20ecc3f0d0
2 changed files with 12 additions and 2 deletions

View file

@ -324,17 +324,26 @@ namespace lib {
return bool(mock_);
}
/** trigger lazy service object instantiation */
MOC&
triggerCreate()
{
Depend<SRV>{}.operator()();
ENSURE (mock_);
return *mock_;
}
MOC&
operator* () const
{
ENSURE (mock_);
REQUIRE (mock_);
return *mock_;
}
MOC*
operator-> () const
{
ENSURE (mock_);
REQUIRE (mock_);
return mock_.get();
}
};

View file

@ -116,6 +116,7 @@ namespace test {
auto location = UICoord{"win-1","persp-A","thePanel","someView","tab#5"};
DummyTab dummyTab;
fakeDirectory.triggerCreate();
fakeDirectory->expectedQuery = location;
fakeDirectory->expectedAnswer = &dummyTab;