adds test for NiceMock with unknown return value

This commit is contained in:
Maurice Gilden 2017-08-18 11:21:28 +02:00
parent 1183503d11
commit 95f18d9938

View File

@ -79,6 +79,7 @@ class MockFoo : public Foo {
MOCK_METHOD0(DoThis, void());
MOCK_METHOD1(DoThat, int(bool flag));
MOCK_METHOD0(ReturnSomething, Mock());
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
@ -207,6 +208,20 @@ TEST(NiceMockTest, AllowsExpectedCall) {
nice_foo.DoThis();
}
// Tests that an unexpected call on a nice mock which returns a non-built in
// default value throws an exception and the exception contains the name of
// the method.
TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
NiceMock<MockFoo> nice_foo;
try {
nice_foo.ReturnSomething();
FAIL();
} catch (const std::runtime_error& ex) {
const std::string exception_msg(ex.what());
EXPECT_NE(exception_msg.find("ReturnSomething"), std::string::npos);
}
}
// Tests that an unexpected call on a nice mock fails.
TEST(NiceMockTest, UnexpectedCallFails) {
NiceMock<MockFoo> nice_foo;