Kata Step Two
Our second test verifies that when a BoundedQueue is created, it tells the Consumer not to start grabbing items yet.
BoundedQueueTest.cpp
TEST(BoundedQueueTest, CreatePausesConsumer) {
MockQueueControl producer, consumer;
EXPECT_CALL(consumer, Pause());
BoundedQueue<int> q(producer, consumer);
}See if you can get this to compile, or read on:
We need to add void Pause() to our mock, and our interface:
BoundedQueueTest.cpp
class MockQueueControl : public QueueControl {
public:
...
MOCK_METHOD0(Pause, void());
};QueueControl.h
class QueueControl {
public:
...
virtual void Pause() = 0;
};And modify BoundedQueue's constructor, because we now know we also want a Consumer:
BoundedQueue.h
BoundedQueue(QueueControl& producer, QueueControl& consumer) {
producer.Resume();
}Finally, we need to modify our first test to call the new constructor:
BoundedQueueTest.cpp
TEST(BoundedQueueTest, CreateResumesProducer) {
MockQueueControl producer, consumer;
EXPECT_CALL(producer, Resume());
BoundedQueue<int> q(producer, consumer);
}
Now we should be able to compile and run tests, and see a new failing test.
See if you can make the test pass, or read on:
All we have to do to make the test pass is call Pause():
BoundedQueue.h
BoundedQueue(QueueControl& producer, QueueControl& consumer) {
producer.Resume();
consumer.Pause();
}Green bar!
Go on to BoundedQueueKataStepThree.... or go back
