-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example 4 to show how to use the Mock object
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*------------------------------------------------------------------------ | ||
File : MockProcedureExample | ||
Purpose : Example showing how to use OEMock:MockProcedure. | ||
Notes : This example requires that OEMock and OEUnit are already | ||
on the ProPath. | ||
----------------------------------------------------------------------*/ | ||
|
||
USING Progress.Lang.*. | ||
USING OEMock.*. | ||
USING OEUnit.Assertion.*. | ||
|
||
ROUTINE-LEVEL ON ERROR UNDO, THROW. | ||
|
||
CLASS "Examples.Example 4.MockProcedureExample": | ||
|
||
DEFINE PROTECTED VARIABLE TestHandle AS HANDLE NO-UNDO. | ||
|
||
@Before. | ||
METHOD PUBLIC VOID CreateTestHandle(): | ||
RUN VALUE("Examples/Example 4/ProcedureToTest.p") PERSISTENT SET TestHandle. | ||
END METHOD. | ||
|
||
@After. | ||
METHOD PUBLIC VOID DeleteTestHandle(): | ||
IF VALID-HANDLE(TestHandle) THEN DELETE OBJECT TestHandle. | ||
END METHOD. | ||
|
||
@Test. | ||
METHOD PUBLIC VOID TestGetUserNameIsCalled(): | ||
|
||
DEFINE VARIABLE MessageText AS CHARACTER NO-UNDO. | ||
DEFINE VARIABLE mck AS OEMock.Mock NO-UNDO. | ||
|
||
/* Ask OEMock to generate a Mock object for the required procedure */ | ||
mck = OEMock:MockProcedure("Examples/Example 4/ProcedureToMock.p"). | ||
|
||
/* Set the output parameter value for parameter 'UserName' in the procedure "GetUserName". */ | ||
mck:SetProcedureOutputParameterValue("GetUserName", "UserName", "Mary Jones"). | ||
|
||
/* Set expectation that the "GetUserName" procedure will be run at least once */ | ||
mck:Expect("GetUserName"):CalledAtLeast(1). | ||
|
||
/* Generate the Mock procedure file */ | ||
mck:Generate(). | ||
|
||
/* Run procedure and verify the expected outcome */ | ||
RUN SayHello IN TestHandle(OUTPUT MessageText). | ||
Assert:AreEqual(MessageText, "Hello, Mary Jones"). | ||
|
||
/* Assert that any expectations were met */ | ||
mck:AssertIsSatisfied(). | ||
|
||
FINALLY: | ||
/* Mock object is no longer required so delete */ | ||
IF VALID-OBJECT(mck) THEN DELETE OBJECT mck. | ||
|
||
/* Test completed, tell OEMock to run the clean-up process */ | ||
OEMock:CleanUp(). | ||
END. | ||
END METHOD. | ||
|
||
END CLASS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*------------------------------------------------------------------------ | ||
File : ProcedureToMock.p | ||
Purpose : Procedure that will be mocked out in tests. | ||
----------------------------------------------------------------------*/ | ||
|
||
/* *************************** Definitions ************************** */ | ||
|
||
ROUTINE-LEVEL ON ERROR UNDO, THROW. | ||
|
||
/* ******************** Preprocessor Definitions ******************** */ | ||
|
||
|
||
/* *************************** Main Block *************************** */ | ||
|
||
PROCEDURE GetUserName: | ||
|
||
DEFINE OUTPUT PARAMETER UserName AS CHARACTER NO-UNDO. | ||
|
||
/* For the purposes of this example, this is set to a simple string */ | ||
ASSIGN UserName = "Joe Bloggs Jnr.". | ||
|
||
END PROCEDURE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/*------------------------------------------------------------------------ | ||
File : ProcedureToTest.p | ||
Purpose : This file represents a file that is to be tested | ||
----------------------------------------------------------------------*/ | ||
|
||
/* *************************** Definitions ************************** */ | ||
|
||
ROUTINE-LEVEL ON ERROR UNDO, THROW. | ||
|
||
/* ******************** Preprocessor Definitions ******************** */ | ||
|
||
|
||
/* *************************** Main Block *************************** */ | ||
|
||
PROCEDURE SayHello: | ||
|
||
DEFINE OUTPUT PARAMETER MessageText AS CHARACTER NO-UNDO. | ||
|
||
DEFINE VARIABLE ProcHandle AS HANDLE NO-UNDO. | ||
|
||
RUN VALUE("Examples/Example 4/ProcedureToMock.p") PERSISTENT SET ProcHandle. | ||
|
||
RUN GetUserName IN ProcHandle (OUTPUT MessageText). | ||
|
||
IF VALID-HANDLE(ProcHandle) THEN DELETE OBJECT ProcHandle. | ||
|
||
CASE MessageText: | ||
|
||
WHEN ? THEN | ||
DO: | ||
ASSIGN MessageText = "Hello World". | ||
END. | ||
|
||
WHEN "" THEN | ||
DO: | ||
ASSIGN MessageText = "Hello, person with no name". | ||
END. | ||
|
||
OTHERWISE | ||
DO: | ||
ASSIGN MessageText = "Hello, " + MessageText. | ||
END. | ||
END CASE. | ||
|
||
END PROCEDURE. |