Skip to content

Commit 72010c4

Browse files
Cleaner ConcurrentCacheTest.handleException test
1 parent 9d877c2 commit 72010c4

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

test/concurrentcache.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,21 @@
2020
#include "concurrent_cache.h"
2121
#include "gtest/gtest.h"
2222

23+
struct LazyValue
24+
{
25+
const int value;
26+
explicit LazyValue(int v) : value(v) {}
27+
int operator()() const { return value; }
28+
};
29+
30+
struct ExceptionSource
31+
{
32+
int operator()() const { throw std::runtime_error("oops"); return 0; }
33+
};
34+
2335
TEST(ConcurrentCacheTest, handleException) {
2436
zim::ConcurrentCache<int, int> cache(1);
25-
auto val = cache.getOrPut(7, []() { return 777; });
26-
EXPECT_EQ(val, 777);
27-
EXPECT_THROW(cache.getOrPut(8, []() { throw std::runtime_error("oups"); return 0; }), std::runtime_error);
28-
val = cache.getOrPut(8, []() { return 888; });
29-
EXPECT_EQ(val, 888);
37+
EXPECT_EQ(cache.getOrPut(7, LazyValue(777)), 777);
38+
EXPECT_THROW(cache.getOrPut(8, ExceptionSource()), std::runtime_error);
39+
EXPECT_EQ(cache.getOrPut(8, LazyValue(888)), 888);
3040
}

0 commit comments

Comments
 (0)