Skip to content

Commit

Permalink
Updated to use new Apex Mocks matcher feature
Browse files Browse the repository at this point in the history
  • Loading branch information
afawcettffdc committed Jun 27, 2016
1 parent a442c38 commit d44a3fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 2 additions & 3 deletions fflib-sample-code/src/classes/OpportunitiesServiceTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,18 @@ private class OpportunitiesServiceTest
mocks.when(selectorMock.sObjectType()).thenReturn(Opportunity.SObjectType);
mocks.when(selectorMock.selectByIdWithProducts(testOppsSet)).thenReturn(testOppsList);
mocks.stopStubbing();
Decimal discountPercent = 10;
Application.UnitOfWork.setMock(uowMock);
Application.Domain.setMock(domainMock);
Application.Selector.setMock(selectorMock);

// When
OpportunitiesService.applyDiscounts(testOppsSet, discountPercent);
OpportunitiesService.applyDiscounts(testOppsSet, 10);

// Then
((IOpportunitiesSelector)
mocks.verify(selectorMock)).selectByIdWithProducts(testOppsSet);
((IOpportunities)
mocks.verify(domainMock)).applyDiscount(discountPercent, uowMock);
mocks.verify(domainMock)).applyDiscount(10, uowMock);
((fflib_ISObjectUnitOfWork)
mocks.verify(uowMock, 1)).commitWork();
}
Expand Down
7 changes: 5 additions & 2 deletions fflib-sample-code/src/classes/OpportunitiesTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ private class OpportunitiesTest

// Then
((fflib_ISObjectUnitOfWork)
mocks.verify(uowMock, 1)).registerDirty(opp);
System.assertEquals(900, opp.Amount);
mocks.verify(uowMock, 1)).registerDirty(
fflib_Match.sObjectWith(
new Map<SObjectField, Object>{
Opportunity.Id => opp.Id,
Opportunity.Amount => 900} ));
}

@IsTest
Expand Down

0 comments on commit d44a3fb

Please sign in to comment.