Skip to content

Instantly share code, notes, and snippets.

@blogdarkspot
Last active July 18, 2017 02:49
Show Gist options
  • Save blogdarkspot/6d3bf61142f86d21d4079649774d3cf5 to your computer and use it in GitHub Desktop.
Save blogdarkspot/6d3bf61142f86d21d4079649774d3cf5 to your computer and use it in GitHub Desktop.
class ActiveMQManagerFake : public ActiveMQManagerInterface {
private:
ActiveMQManagerInterface* mock;
public:
void setMock(ActiveMQManagerInterface* mock) {
if (mock != NULL) {
this->mock = mock;
}
}
virtual void connectToServer() {
if (mock)
{
mock->sendMessageToServer();
mock->stop();
}
};
virtual void sendMessageToServer() {
};
virtual bool isConnected() {
return true;
};
virtual bool start() {
if (mock)
{
if (mock->isConnected())
{
mock->sendMessageToServer();
}
else
{
mock->connectToServer();
if (mock->isConnected())
{
mock->sendMessageToServer();
}
}
return true;
}
return false;
};
virtual bool stop() {
return true;
};
virtual void addQueue(const std::string&) {
};
};
class ActiveMQManagerMock : public ActiveMQManagerInterface {
private:
ActiveMQManagerFake fake;
public:
MOCK_METHOD0(getInstance, ActiveMQManagerInterface*());
MOCK_METHOD0(isConnected, bool());
MOCK_METHOD0(start, bool());
MOCK_METHOD0(stop, bool());
MOCK_METHOD1(addQueue, void(const string&));
MOCK_METHOD0(connectToServer, void());
MOCK_METHOD0(sendMessageToServer, void());
void delegateToFake()
{
fake.setMock(this);
ON_CALL(*this, start()).WillByDefault(Invoke(&fake, &ActiveMQManagerFake::start));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment