cleanup: let the handler own the file system implementation
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ic7c31237bd5440b2cfa171df93545a63708e404c
diff --git a/cleanup/test/cleanup_handler_unittest.cpp b/cleanup/test/cleanup_handler_unittest.cpp
index 5191234..33216a9 100644
--- a/cleanup/test/cleanup_handler_unittest.cpp
+++ b/cleanup/test/cleanup_handler_unittest.cpp
@@ -2,6 +2,7 @@
#include "filesystem_mock.hpp"
#include "util.hpp"
+#include <memory>
#include <string>
#include <vector>
@@ -18,24 +19,32 @@
class CleanupHandlerTest : public ::testing::Test
{
protected:
+ CleanupHandlerTest() : mock(std::make_unique<FileSystemMock>())
+ {
+ mock_ptr = mock.get();
+ handler = std::make_unique<FileCleanupHandler>(cleanupBlobId, blobs,
+ std::move(mock));
+ }
+
std::vector<std::string> blobs = {"abcd", "efgh"};
- FileSystemMock mock;
- FileCleanupHandler handler{cleanupBlobId, blobs, &mock};
+ std::unique_ptr<FileSystemMock> mock;
+ FileSystemMock* mock_ptr;
+ std::unique_ptr<FileCleanupHandler> handler;
};
TEST_F(CleanupHandlerTest, GetBlobListReturnsExpectedList)
{
- EXPECT_TRUE(handler.canHandleBlob(cleanupBlobId));
- EXPECT_THAT(handler.getBlobIds(),
+ EXPECT_TRUE(handler->canHandleBlob(cleanupBlobId));
+ EXPECT_THAT(handler->getBlobIds(),
UnorderedElementsAreArray({cleanupBlobId}));
}
TEST_F(CleanupHandlerTest, CommitShouldDeleteFiles)
{
- EXPECT_CALL(mock, remove("abcd")).WillOnce(Return());
- EXPECT_CALL(mock, remove("efgh")).WillOnce(Return());
+ EXPECT_CALL(*mock_ptr, remove("abcd")).WillOnce(Return());
+ EXPECT_CALL(*mock_ptr, remove("efgh")).WillOnce(Return());
- EXPECT_TRUE(handler.commit(1, {}));
+ EXPECT_TRUE(handler->commit(1, {}));
}
} // namespace