Hi beauchai,
Following are examples for private and static methods:
-----PrivateMethod-----
TEST_METHOD(ReplacingPrivateMethodCallBasedOnParameters)
{
Person person;
Address* address = FAKE<Address>();
Zombieland land;
std::string city1("Unknown");
std::string cityYork("York");
// public methods can be set as private methods too
PRIVATE_WHEN_CALLED(address, GetCityByCountry,
IS<std::string>([](std::string& country) { return country.compare("US") == 0 || country.compare("UK") == 0; }
)).Return(&cityYork);
PRIVATE_WHEN_CALLED(address, GetCityByCountry(ANY_VAL(std::string))).Return(&city1);
string firstCity = person.GetCityFromAddress(address, "US");
string secondCity = person.GetCityFromAddress(address, "UK");
string thirdCity = person.GetCityFromAddress(address, "CA");
Assert::AreEqual(0, firstCity.compare("York"));
Assert::AreEqual(0, secondCity.compare("York"));
Assert::AreEqual(0, thirdCity.compare("Unknown"));
}
-----StaticMethod-----
TEST_METHOD(ReplacingStaticMethodCallBasedOnParameters)
{
Person person;
WHEN_CALLED(Address::GetCapitalCityByCountry(ANY_VAL(string))).
DoStaticOrGlobalInstead(Zombieland::GetZombielandCapitalCity, NULL);
string zombieCapital = person.GetCapitalCity("Zombieland");
string otherCapital = person.GetCapitalCity("US");
Assert::AreEqual(0, zombieCapital.compare("GhostTown"));
Assert::AreEqual(0, otherCapital.compare("Elsewhere"));
}
You can find more of these examples at the Typemock installation folder.