diff --git a/Delphi.Mocks.MethodData.pas b/Delphi.Mocks.MethodData.pas index 8d21d77..0762613 100644 --- a/Delphi.Mocks.MethodData.pas +++ b/Delphi.Mocks.MethodData.pas @@ -534,17 +534,21 @@ procedure TMethodData.RecordHit(const Args: TArray; const returnType : T procedure TMethodData.StubNoBehaviourRecordHit(const Args: TArray; const AExpectationHitCtr : Integer; const returnType: TRttiType; out Result: TValue); begin - //If we have no return type defined, and the default return type is empty - if (returnType <> nil) and (FReturnDefault.IsEmpty) then - begin - //Return the default value for the passed in return type - Result := GetDefaultValue(returnType); - end - else if FSetupParameters.BehaviorMustBeDefined and (AExpectationHitCtr = 0) and (FReturnDefault.IsEmpty) then - begin - //If we must have default behaviour defined, and there was nothing defined raise a mock exception. - raise EMockException.Create(Format('[%s] has no behaviour or expectation defined for method [%s]', [FTypeName, FMethodName])); - end; + MockNoBehaviourRecordHit(Args, AExpectationHitCtr, returnType, Result); + +// +// //If we have no return type defined, and the default return type is empty +// if (returnType <> nil) and (FReturnDefault.IsEmpty) then +// begin +// //Return the default value for the passed in return type +// Result := GetDefaultValue(returnType); +// end +// else if FSetupParameters.BehaviorMustBeDefined and (AExpectationHitCtr = 0) and (FReturnDefault.IsEmpty) then +// begin +// //If we must have default behaviour defined, and there was nothing defined raise a mock exception. +// raise EMockException.Create(Format('[%s] has no behaviour or expectation defined for method [%s]', [FTypeName, FMethodName])); +// end; +// result := FReturnDefault; end; function TMethodData.Verify(var report : string) : boolean; diff --git a/Tests/Delphi.Mocks.Tests.Stubs.pas b/Tests/Delphi.Mocks.Tests.Stubs.pas new file mode 100644 index 0000000..93a8ec6 --- /dev/null +++ b/Tests/Delphi.Mocks.Tests.Stubs.pas @@ -0,0 +1,47 @@ +unit Delphi.Mocks.Tests.Stubs; + +interface + +uses + DUnitX.TestFramework; +type + {$M+} + [TestFixture] + TStubTests = class + published + procedure Test_WillReturnDefault; + end; + {$M-} + + {$M+} + ITestable = interface + function DoSomething(const value : string) : string; + end; + {$M-} + + +implementation + +uses + Delphi.Mocks; +{ TUtilsTests } +{ TStubTests } + +procedure TStubTests.Test_WillReturnDefault; +var + stub : TStub; + intf : ITestable; + actual : string; +begin + stub := TStub.Create; + stub.Setup.WillReturnDefault('DoSomething','hello'); + intf := stub.Instance; + actual := intf.DoSomething('world'); + Assert.AreEqual('hello', actual); +end; + +initialization + TDUnitX.RegisterTestFixture(TStubTests); + + +end. diff --git a/Tests/Delphi.Mocks.Tests.dpr b/Tests/Delphi.Mocks.Tests.dpr index 5b4546c..0c9f134 100644 --- a/Tests/Delphi.Mocks.Tests.dpr +++ b/Tests/Delphi.Mocks.Tests.dpr @@ -26,9 +26,6 @@ uses DUnitX.Windows.Console, DUnitX.Loggers.XML.NUnit, SysUtils, - {$IFDEF TESTINSIGHT} - TestInsight.DUnitX, - {$ENDIF } Delphi.Mocks.AutoMock in '..\Delphi.Mocks.AutoMock.pas', Delphi.Mocks.Behavior in '..\Delphi.Mocks.Behavior.pas', Delphi.Mocks.Expectation in '..\Delphi.Mocks.Expectation.pas', @@ -63,7 +60,8 @@ uses Delphi.Mocks.Tests.TValue in 'Delphi.Mocks.Tests.TValue.pas', Delphi.Mocks.Tests.Utils in 'Delphi.Mocks.Tests.Utils.pas', Delphi.Mocks.Utils.Tests in 'Delphi.Mocks.Utils.Tests.pas', - Delphi.Mocks.Examples.Matchers in 'Delphi.Mocks.Examples.Matchers.pas'; + Delphi.Mocks.Examples.Matchers in 'Delphi.Mocks.Examples.Matchers.pas', + Delphi.Mocks.Tests.Stubs in 'Delphi.Mocks.Tests.Stubs.pas'; {$R *.RES}