Skip to content

Commit 8599220

Browse files
committed
Fixing compilation issues introduced after refactoring
1 parent f527bde commit 8599220

File tree

12 files changed

+64
-28
lines changed

12 files changed

+64
-28
lines changed

.idea/illuminatedCloud.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/test-data-framework.iml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sfdx/sfdx-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"defaultusername": "test-data-framework"
2+
"defaultusername": "test-[email protected]"
33
}
Binary file not shown.

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ also allows you to create custom builders for different SObjectTypes.
125125

126126
To create a custom builder you will need to **both** extend `SObjectTestDataBuilder` and implement `ITestDataBuilder`.
127127
For the framework to automatically detect your custom builder it also **needs* to have a name that ends in `TestDataBuilder`
128-
(though there is a way to explicitly specify the builder to the framework, explained below):
128+
(though there is a way to explicitly specify the builder to the framework, explained below).
129+
130+
Any custom builder should start with some boilerplate code that looks as follows:
129131

130132
```apex
131133
@IsTest
@@ -146,6 +148,10 @@ public with sharing class OrderTestDataBuilder extends SObjectTestDataBuilder im
146148
return this.registerSObjectsForInsert(numberOfRecords);
147149
}
148150
151+
public OrderTestDataBuilder withChild(ITestDataBuilder childBuilder, SObjectField relationshipField) {
152+
return (OrderTestDataBuilder)this.withChildData(childBuilder, relationshipField);
153+
}
154+
149155
protected override Map<SObjectField, Object> getDefaultValueMap() {
150156
return new Map<SObjectField, Object> {
151157
Order__c.Customer__c => bindTo(SObjectTestDataBuilder.of(Account.SObjectType))

example/tests/AccountTestDataBuilder.cls

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@IsTest
2-
public with sharing class AccountTestDataBuilder extends SObjectTestDataBuilder {
2+
public with sharing class AccountTestDataBuilder extends SObjectTestDataBuilder implements ITestDataBuilder {
33
public ITestDataBuilder with(SObjectField field, Object value) {
44
this.withData(field, value);
55
return this;
@@ -37,6 +37,10 @@ public with sharing class AccountTestDataBuilder extends SObjectTestDataBuilder
3737
return this;
3838
}
3939

40+
public AccountTestDataBuilder withChild(ITestDataBuilder childBuilder, SObjectField relationshipField) {
41+
return (AccountTestDataBuilder)this.withChildData(childBuilder, relationshipField);
42+
}
43+
4044
protected override Map<SObjectField, Object> getDefaultValueMap() {
4145
return new Map<SObjectField, Object> {
4246
Account.Name => 'ACME'

example/tests/IntegrationTests.cls

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ private class IntegrationTests {
270270
return this.registerSObjectsForInsert(numberOfRecords);
271271
}
272272

273+
public PriceBookEntryBuilder withChild(ITestDataBuilder childBuilder, SObjectField relationshipField) {
274+
return (PriceBookEntryBuilder)this.withChildData(childBuilder, relationshipField);
275+
}
276+
273277
protected override Map<SObjectField, Object> getDefaultValueMap() {
274278
return new Map<SObjectField, Object> {
275279
PricebookEntry.Product2Id => bindTo(SObjectTestDataBuilder.of(Product2.SObjectType)),
@@ -296,6 +300,10 @@ private class IntegrationTests {
296300
return this.registerSObjectsForInsert(numberOfRecords);
297301
}
298302

303+
public OrderBuilder withChild(ITestDataBuilder childBuilder, SObjectField relationshipField) {
304+
return (OrderBuilder)this.withChildData(childBuilder, relationshipField);
305+
}
306+
299307
protected override Map<SObjectField, Object> getDefaultValueMap() {
300308
return new Map<SObjectField, Object> {
301309
Order.Status => 'Draft',
@@ -323,6 +331,10 @@ private class IntegrationTests {
323331
return this.registerSObjectsForInsert(numberOfRecords);
324332
}
325333

334+
public OrderItemBuilder withChild(ITestDataBuilder childBuilder, SObjectField relationshipField) {
335+
return (OrderItemBuilder)this.withChildData(childBuilder, relationshipField);
336+
}
337+
326338
protected override Map<SObjectField, Object> getDefaultValueMap() {
327339
return new Map<SObjectField, Object> {
328340
OrderItem.PricebookEntryId => bindTo(SObjectTestDataBuilder.of(PricebookEntry.SObjectType)),

example/tests/OrderItemTestDataBuilder.cls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public with sharing class OrderItemTestDataBuilder extends SObjectTestDataBuilde
1616
return this.registerSObjectsForInsert(numberOfRecords);
1717
}
1818

19+
public OrderItemTestDataBuilder withChild(ITestDataBuilder childBuilder, SObjectField relationshipField) {
20+
return (OrderItemTestDataBuilder)this.withChildData(childBuilder, relationshipField);
21+
}
22+
1923
protected override Map<SObjectField, Object> getDefaultValueMap() {
2024
return new Map<SObjectField, Object> {
2125
OrderItem__c.Order__c => bindTo(SObjectTestDataBuilder.of(Order__c.SObjectType)),

example/tests/OrderTestDataBuilder.cls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public with sharing class OrderTestDataBuilder extends SObjectTestDataBuilder im
1616
return this.registerSObjectsForInsert(numberOfRecords);
1717
}
1818

19+
public OrderTestDataBuilder withChild(ITestDataBuilder childBuilder, SObjectField relationshipField) {
20+
return (OrderTestDataBuilder)this.withChildData(childBuilder, relationshipField);
21+
}
22+
1923
protected override Map<SObjectField, Object> getDefaultValueMap() {
2024
return new Map<SObjectField, Object> {
2125
Order__c.Customer__c => bindTo(SObjectTestDataBuilder.of(Account.SObjectType))

force-app/main/default/classes/SObjectTestDataBuilder.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @description Provides base functionality for building SObject records for testing purposes. Any custom TestDataBuilder
33
* must extend this class as well as implement {@link ITestDataBuilder}.
44
*/
5-
public abstract class SObjectTestDataBuilder implements ITestDataCallback.ITestDataCallback {
5+
public abstract class SObjectTestDataBuilder implements ITestDataCallback {
66
private static TestDataBuilderCache builderCache = new TestDataBuilderCache();
77
private static History testDataHistory = new History();
88
private static List<LateBinding> allBindings = new List<LateBinding>();
@@ -397,7 +397,7 @@ public abstract class SObjectTestDataBuilder implements ITestDataCallback.ITestD
397397
}
398398

399399
public void log(List<SObject> insertedRecords, SObject parentRecord, SObjectField relationshipField,
400-
ITestDataCallback.ITestDataCallback callback) {
400+
ITestDataCallback callback) {
401401
for (SObject insertedRecord : insertedRecords) {
402402
HistoryItem item = new HistoryItem(insertedRecord, parentRecord, relationshipField, callback);
403403
log(item);
@@ -480,10 +480,10 @@ public abstract class SObjectTestDataBuilder implements ITestDataCallback.ITestD
480480
private SObject record;
481481
private SObject parentRecord;
482482
private SObjectField relationshipToParent;
483-
private ITestDataCallback.ITestDataCallback callback;
483+
private ITestDataCallback callback;
484484

485485
public HistoryItem(SObject record, SObject parentRecord, SObjectField relationshipField,
486-
ITestDataCallback.ITestDataCallback callback) {
486+
ITestDataCallback callback) {
487487
this.record = record;
488488
this.parentRecord = parentRecord;
489489
this.relationshipToParent = relationshipField;

0 commit comments

Comments
 (0)