Partial mock using groovy gmock v 0.8

324 Views Asked by At

I am not able to figure out partial mocking in groovy using gmock. I have the following code:

class Foo {
   Integer val
   Foo() {
      this.val = 4;
   }

   Integer printHello() {
      return getValue()
   }

   Integer getValue() {
      return val+1;
   }
}

and the testcase:

class FooTester {
   @Test
   void test() {
      def lol = new Foo(4)
      def mocker = mock(lol)
      mocker.getValue().returns(5)

      play {
         assertEquals(5, lol.printHello())
      }
   }
}

I am referring to the documentation here. Assertion is failing with java.lang.AssertionError: Expectation not matched on verify:

What may the problem?

1

There are 1 best solutions below

0
Todd W Crone On

After quick check of documentation, I think this should work:

class FooTester {
   @Test
   void test() {
      def lol = new Foo(4)
      mock(lol).value.returns(5)

      play {
         assertEquals(5, lol.printHello())
      }
   }
}