Kata Step Three

 Next test: We want to verify that adding an item to the queue will notify the consumer that it can start grabbing items.

BoundedQueueTest.cpp

TEST(BoundedQueueTest, EnqueueResumesConsumer) {
        MockQueueControl producer, consumer;
        BoundedQueue<int> q(producer, consumer);
        EXPECT_CALL(consumer, Resume());
        q.enqueue(5);
}

See if you can make this compile, or read on:











Well, we need to add an enqueue() method:

BoundedQueue.h

public:
        ...
        void enqueue(const T& item) {}

Now we can compile and run tests, and see the failing test. Red bar!

See if you can make the test pass, or read on:











We have to remember the consumer, so that we can call Resume() on it any time we enqueue an item.

BoundedQueue.h

public:
        BoundedQueue(QueueControl& producer, QueueControl& consumer) : consumer(consumer) {
                producer.Resume();
                consumer.Pause();
        }
        void enqueue(const T& item) {
                consumer.Resume();
        }

private:
        QueueControl& consumer;
};

Green bar!


Go on to BoundedQueueKataStepFour.... or go back

BoundedQueueKataStepThree (last edited 2010-01-17 00:44:23 by KayJohansen)