Esempio n. 1
0
func Test_Mock_Called_For_EmbeddedStruct_Expectation(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	exampleTestStruct := &ExampleTestStruct{
		TestVal1: 1,
		ExampleEmbeddedStruct: ExampleEmbeddedStruct{
			TestVal2: 2,
			TestVal3: 3,
		},
	}

	mockedService.On("TheExampleStructMethod", exampleTestStruct).Return(nil)

	assert.PanicsWithMessage(t, func() {
		exampleTestStructBad := &ExampleTestStruct{
			TestVal1: 4,
			ExampleEmbeddedStruct: ExampleEmbeddedStruct{
				TestVal2: 5,
				TestVal3: 6,
			},
		}
		mockedService.TheExampleStructMethod(exampleTestStructBad)
	}, fmt.Sprintf(unexpectedMethodCallClosest, "TheExampleStructMethod(*mock.ExampleTestStruct)\n\t\t0: {\"TestVal2\":5,\"TestVal3\":6,\"TestVal1\":4}", "TheExampleStructMethod(*mock.ExampleTestStruct)\n\t\t0: {\"TestVal2\":2,\"TestVal3\":3,\"TestVal1\":1}"))

}
Esempio n. 2
0
func Test_Mock_Called_For_SetTime_Expectation(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	mockedService.On("TheExampleMethod", 1, 2, 3).Return(5, "6", true).Times(4)

	mockedService.TheExampleMethod(1, 2, 3)
	mockedService.TheExampleMethod(1, 2, 3)
	mockedService.TheExampleMethod(1, 2, 3)
	mockedService.TheExampleMethod(1, 2, 3)
	assert.PanicsWithMessage(t, func() {
		mockedService.TheExampleMethod(1, 2, 3)
	}, fmt.Sprintf(unexpectedMethodCallClosest, "TheExampleMethod(int,int,int)\n\t\t0: 1\n\t\t1: 2\n\t\t2: 3", "TheExampleMethod(int,int,int)\n\t\t0: 1\n\t\t1: 2\n\t\t2: 3"))

}