@@ -820,6 +820,195 @@ func Test_Mock_Return_Nothing(t *testing.T) {
820820 assert .Equal (t , 0 , len (call .ReturnArguments ))
821821}
822822
823+ func Test_Mock_Return_NotBefore_In_Order (t * testing.T ) {
824+ var mockedService = new (TestExampleImplementation )
825+
826+ b := mockedService .
827+ On ("TheExampleMethod" , 1 , 2 , 3 ).
828+ Return (4 , nil )
829+ c := mockedService .
830+ On ("TheExampleMethod2" , true ).
831+ Return ().
832+ NotBefore (b )
833+
834+ require .Equal (t , []* Call {b , c }, mockedService .ExpectedCalls )
835+ require .NotPanics (t , func () {
836+ mockedService .TheExampleMethod (1 , 2 , 3 )
837+ })
838+ require .NotPanics (t , func () {
839+ mockedService .TheExampleMethod2 (true )
840+ })
841+ }
842+
843+ func Test_Mock_Return_NotBefore_Out_Of_Order (t * testing.T ) {
844+ var mockedService = new (TestExampleImplementation )
845+
846+ b := mockedService .
847+ On ("TheExampleMethod" , 1 , 2 , 3 ).
848+ Return (4 , nil ).Twice ()
849+ c := mockedService .
850+ On ("TheExampleMethod2" , true ).
851+ Return ().
852+ NotBefore (b )
853+
854+ require .Equal (t , []* Call {b , c }, mockedService .ExpectedCalls )
855+
856+ expectedPanicString := `mock: Unexpected Method Call
857+ -----------------------------
858+
859+ TheExampleMethod2(bool)
860+ 0: true
861+
862+ Must not be called before:
863+
864+ TheExampleMethod(int,int,int)
865+ 0: 1
866+ 1: 2
867+ 2: 3`
868+ require .PanicsWithValue (t , expectedPanicString , func () {
869+ mockedService .TheExampleMethod2 (true )
870+ })
871+ }
872+
873+ func Test_Mock_Return_NotBefore_Not_Enough_Times (t * testing.T ) {
874+ var mockedService = new (TestExampleImplementation )
875+
876+ b := mockedService .
877+ On ("TheExampleMethod" , 1 , 2 , 3 ).
878+ Return (4 , nil ).Twice ()
879+ c := mockedService .
880+ On ("TheExampleMethod2" , true ).
881+ Return ().
882+ NotBefore (b )
883+
884+ require .Equal (t , []* Call {b , c }, mockedService .ExpectedCalls )
885+
886+ require .NotPanics (t , func () {
887+ mockedService .TheExampleMethod (1 , 2 , 3 )
888+ })
889+ expectedPanicString := `mock: Unexpected Method Call
890+ -----------------------------
891+
892+ TheExampleMethod2(bool)
893+ 0: true
894+
895+ Must not be called before another call of:
896+
897+ TheExampleMethod(int,int,int)
898+ 0: 1
899+ 1: 2
900+ 2: 3`
901+ require .PanicsWithValue (t , expectedPanicString , func () {
902+ mockedService .TheExampleMethod2 (true )
903+ })
904+ }
905+
906+ func Test_Mock_Return_NotBefore_Different_Mock_In_Order (t * testing.T ) {
907+ var (
908+ mockedService1 = new (TestExampleImplementation )
909+ mockedService2 = new (TestExampleImplementation )
910+ )
911+
912+ b := mockedService1 .
913+ On ("TheExampleMethod" , 1 , 2 , 3 ).
914+ Return (4 , nil )
915+ c := mockedService2 .
916+ On ("TheExampleMethod2" , true ).
917+ Return ().
918+ NotBefore (b )
919+
920+ require .Equal (t , []* Call {c }, mockedService2 .ExpectedCalls )
921+ require .NotPanics (t , func () {
922+ mockedService1 .TheExampleMethod (1 , 2 , 3 )
923+ })
924+ require .NotPanics (t , func () {
925+ mockedService2 .TheExampleMethod2 (true )
926+ })
927+ }
928+ func Test_Mock_Return_NotBefore_Different_Mock_Out_Of_Order (t * testing.T ) {
929+ var (
930+ mockedService1 = new (TestExampleImplementation )
931+ mockedService2 = new (TestExampleImplementation )
932+ )
933+
934+ b := mockedService1 .
935+ On ("TheExampleMethod" , 1 , 2 , 3 ).
936+ Return (4 , nil )
937+ c := mockedService2 .
938+ On ("TheExampleMethod2" , true ).
939+ Return ().
940+ NotBefore (b )
941+
942+ require .Equal (t , []* Call {c }, mockedService2 .ExpectedCalls )
943+
944+ expectedPanicString := `mock: Unexpected Method Call
945+ -----------------------------
946+
947+ TheExampleMethod2(bool)
948+ 0: true
949+
950+ Must not be called before method from another mock instance:
951+
952+ TheExampleMethod(int,int,int)
953+ 0: 1
954+ 1: 2
955+ 2: 3`
956+ require .PanicsWithValue (t , expectedPanicString , func () {
957+ mockedService2 .TheExampleMethod2 (true )
958+ })
959+ }
960+
961+ func Test_Mock_Return_NotBefore_In_Order_With_Non_Dependant (t * testing.T ) {
962+ var mockedService = new (TestExampleImplementation )
963+
964+ a := mockedService .
965+ On ("TheExampleMethod" , 1 , 2 , 3 ).
966+ Return (4 , nil )
967+ b := mockedService .
968+ On ("TheExampleMethod" , 4 , 5 , 6 ).
969+ Return (4 , nil )
970+ c := mockedService .
971+ On ("TheExampleMethod2" , true ).
972+ Return ().
973+ NotBefore (a , b )
974+ d := mockedService .
975+ On ("TheExampleMethod7" , []bool {}).Return (nil )
976+
977+ require .Equal (t , []* Call {a , b , c , d }, mockedService .ExpectedCalls )
978+ require .NotPanics (t , func () {
979+ mockedService .TheExampleMethod7 ([]bool {})
980+ })
981+ require .NotPanics (t , func () {
982+ mockedService .TheExampleMethod (1 , 2 , 3 )
983+ })
984+ require .NotPanics (t , func () {
985+ mockedService .TheExampleMethod7 ([]bool {})
986+ })
987+ require .NotPanics (t , func () {
988+ mockedService .TheExampleMethod (4 , 5 , 6 )
989+ })
990+ require .NotPanics (t , func () {
991+ mockedService .TheExampleMethod7 ([]bool {})
992+ })
993+ require .NotPanics (t , func () {
994+ mockedService .TheExampleMethod2 (true )
995+ })
996+ require .NotPanics (t , func () {
997+ mockedService .TheExampleMethod7 ([]bool {})
998+ })
999+ }
1000+
1001+ func Test_Mock_Return_NotBefore_Orphan_Call (t * testing.T ) {
1002+ var mockedService = new (TestExampleImplementation )
1003+
1004+ require .PanicsWithValue (t , "not before calls must be created with Mock.On()" , func () {
1005+ mockedService .
1006+ On ("TheExampleMethod2" , true ).
1007+ Return ().
1008+ NotBefore (& Call {Method : "Not" , Arguments : Arguments {"how" , "it's" }, ReturnArguments : Arguments {"done" }})
1009+ })
1010+ }
1011+
8231012func Test_Mock_findExpectedCall (t * testing.T ) {
8241013
8251014 m := new (Mock )
0 commit comments