Matchers

Equal

The Equal matcher matches any value that is equal to the expected value. Equal uses reflect.DeepEqual to compare values.

This test will succeed, because reflect.DeepEqual compares values by their content:

mock.Foo(Equal(&Bar{}))

NotEqual

The NotEqual matcher matches any value that is not equal to the expected value.

  • Use it to exclude one concrete value from a stub:

    WhenSingle(mock.Foo(NotEqual(1))).ThenReturn(2)
    

Both matchers can be combined with Any in the same stubbing call.

WhenSingle(mock.Foo(Any[int]())).ThenReturn(3)