title: gmock, Expected: to be called once Actual: never called
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  #include &lt;string&gt;
  #include "gtest/gtest.h"
  #include "gmock/gmock.h"
  using ::testing::AtLeast;
  using ::testing::Return;
  using ::testing::_;
  
  class User{
  public:
      string Name;
      virtual void SetName(string tmpName){Name=tmpName;}
      virtual string GetName(){return Name;}
      virtual bool IsAdmin(){ 
          string admin="alley";
          if(admin.compare(Name)==0)//the contents of both strings are equal
              return true;
          return false;
      }
  };
  
  class MockUser:public User
  {
      public:
      MOCK_METHOD1(SetName, void(string tmpName));
      MOCK_METHOD0(GetName, string());
      MOCK_METHOD0(IsAdmin, bool());
  };
  
  class Reservation{
  public:
      User &amp;BookName;
      Reservation(User user):BookName(user){}
      bool CanBeCancelBy(User cuser){
          cuser.IsAdmin();
          if(cuser.IsAdmin()==true)
              return true;
          if(cuser.GetName().compare(BookName.GetName())==0)//the contents of both strings are equal
              return true;
          return false;
      }
  };
  TEST(CanBeCancelBy, MockUserIsAdmin_ReturnTrue)
  {
      //Arrange   
      MockUser admin;
      User a1;
      a1.SetName("a1");
      Reservation r1(a1);
      EXPECT_CALL(admin, IsAdmin()).Times(1).WillOnce(Return(true));
      //Act
      //bool result =admin.IsAdmin();
      bool result=r1.CanBeCancelBy(admin);
      //Assert
      EXPECT_EQ(result, 1);
  }
  
  int main()
  {   
      testing::InitGoogleTest();
      return RUN_ALL_TESTS();
  }
  </code></pre>
  
  <p>I think IsAdmin() will be called, but it doesn't. </p>
  
  <p>The execute result as bellow:</p>
  
  <p>[ RUN      ] [mCanBeCancelBy.MockUserIsAdmin_ReturnTrue
  Reservation.cpp:56: Failure
  Expected equality of these values:
     result
      Which is: false
    1
  Reservation.cpp:51: Failure
  Actual function call count doesn't match EXPECT_CALL(admin, IsAdmin())...
           Expected: to be called once
             Actual: never called - unsatisfied and active
  [  FAILED  ] [mCanBeCancelBy.MockUserIsAdmin_ReturnTrue (3 ms)</p>
  
  <p>Can someone help me to understand what's going wrong?</p>