Skip to content

Commit

Permalink
Revert "add mock.MethodCalled(methodName, args...)"
Browse files Browse the repository at this point in the history
This reverts commit 17a0bd5.

Should avoid simply exporting an internal method.
  • Loading branch information
ernesto-jimenez committed May 26, 2017
1 parent 34687eb commit f712be9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
7 changes: 2 additions & 5 deletions mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (m *Mock) On(methodName string, arguments ...interface{}) *Call {
// Recording and responding to activity
// */

func (m *Mock) FindExpectedCall(method string, arguments ...interface{}) (int, *Call) {
func (m *Mock) findExpectedCall(method string, arguments ...interface{}) (int, *Call) {
m.mutex.Lock()
defer m.mutex.Unlock()
for i, call := range m.ExpectedCalls {
Expand Down Expand Up @@ -287,11 +287,8 @@ func (m *Mock) Called(arguments ...interface{}) Arguments {
}
parts := strings.Split(functionPath, ".")
functionName := parts[len(parts)-1]
return m.MethodCalled(functionName, arguments...)
}

func (m *Mock) MethodCalled(functionName string, arguments ...interface{}) Arguments {
found, call := m.FindExpectedCall(functionName, arguments...)
found, call := m.findExpectedCall(functionName, arguments...)

if found < 0 {
// we have to fail here - because we don't know what to do
Expand Down
23 changes: 5 additions & 18 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package mock

import (
"errors"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
"time"
)

/*
Expand Down Expand Up @@ -562,7 +561,7 @@ func Test_Mock_findExpectedCall(t *testing.T) {
m.On("Two", 2).Return("two")
m.On("Two", 3).Return("three")

f, c := m.FindExpectedCall("Two", 3)
f, c := m.findExpectedCall("Two", 3)

if assert.Equal(t, 2, f) {
if assert.NotNil(t, c) {
Expand All @@ -581,7 +580,7 @@ func Test_Mock_findExpectedCall_For_Unknown_Method(t *testing.T) {
m.On("Two", 2).Return("two")
m.On("Two", 3).Return("three")

f, _ := m.FindExpectedCall("Two")
f, _ := m.findExpectedCall("Two")

assert.Equal(t, -1, f)

Expand All @@ -595,7 +594,7 @@ func Test_Mock_findExpectedCall_Respects_Repeatability(t *testing.T) {
m.On("Two", 3).Return("three").Twice()
m.On("Two", 3).Return("three").Times(8)

f, c := m.FindExpectedCall("Two", 3)
f, c := m.findExpectedCall("Two", 3)

if assert.Equal(t, 2, f) {
if assert.NotNil(t, c) {
Expand Down Expand Up @@ -1185,15 +1184,3 @@ func Test_WaitUntil_Parallel(t *testing.T) {
// Allow the first call to execute, so the second one executes afterwards
ch2 <- time.Now()
}

func Test_MethodCalled(t *testing.T) {
m := new(Mock)
m.On("foo", "hello").Return("world")

found, _ := m.FindExpectedCall("foo", "hello")
require.True(t, found >= 0)
retArgs := m.MethodCalled("foo", "hello")
require.True(t, len(retArgs) == 1)
require.Equal(t, "world", retArgs[0])
m.AssertExpectations(t)
}

0 comments on commit f712be9

Please sign in to comment.