title: Testing and mocking a function which does not return any value
body: <p>I want to test a function, which does not return any value, but instead triggers other functions. While reading about testing, I found information that this is called a behavioral verification and that by mocking I can check what functions and in what order are triggered. However, I have a problem to implement the proper mocking technique for my code. </p>
  
  <p>Let's consider a simple example of the following interface and struct (the example is very basic just to make it easier to explain):</p>
  
  <pre><code>type ExampleInterface interface {
      DoSomething(arg int)
      DoEvenMore(arg int)
      AndEvenMore(arg int)
  } 
  
  type ExampleStruct struct {
       Id string 
       // Other fields
  }
  
  func (e *ExampleStruct) DoSomething(arg int) {
       arg2 := arg * 2
       e.DoEvenMore(arg2)
       arg3 := arg * 3
       e.AndEvenMore(arg3)  
  }
  
  func (e *ExampleStruct) DoEvenMore(arg int){
       fmt.Println("I did so many operations here using ", arg)
  }
  
  func (e *ExampleStruct) AndEvenMore(arg int) {
       // Performing other operations on arg
  }
  </code></pre>
  
  <p>Now, I want to test function <code>DoSomething</code>. Since it does not return any value what I want to do is to test whether after calling this function with argument 3 the following chain of events happens: function <code>DoEvenMore</code> is called once with argument <code>6</code>, and next function <code>AndEvenMore</code> is called once with argument <code>9</code></p>
  
  <p>I wrote the following mocking test:</p>
  
  <pre><code>func TestDoSomething(t *testing.T) {
  
      mockCtrl := gomock.NewController(t)
      defer mockCtrl.Finish()
  
      mockClient := mocks.NewMockExampleInterface(mockCtrl)
  
      example := ExampleStruct("ExampleId")
  
      gomock.InOrder(
          mockClient.EXPECT().DoSomething(3).Return().Times(1)
          mockClient.EXPECT().DoEvenMore(6).Return().Times(1)
          mockClient.EXPECT().AndEvenMore(9).Return().Times(1) 
      )
  
      example.DoSomething(3)
  }
  </code></pre>
  
  <p>However, when I run this test I get the error: <code>Unexpected call to *mocks.MockExampleInterface.DoSomething(..)</code>. </p>
  
  <p>How I should properly perform the mocking in such example?</p>