From 95f18d99383c27bf645e8dc4f5dcaa188f6bafe3 Mon Sep 17 00:00:00 2001 From: Maurice Gilden Date: Fri, 18 Aug 2017 11:21:28 +0200 Subject: adds test for NiceMock with unknown return value --- googlemock/test/gmock-nice-strict_test.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 5d6ccc4f..5e6d53be 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -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 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 nice_foo; -- cgit v1.2.3