Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes, cleanup dead code, static save option and flexible unitOfWork injection #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jdkgabri
Copy link

No description provided.

@@ -9,7 +9,7 @@
"default": true
},
{
"path": "sfdx-source/apex-domainbuilder-samplecode",
"path": "sfdx-source/apex-domainbuilder-sample",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ref was wrong

@@ -1,3 +1,4 @@
@IsTest
public class Random {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class did not have almost coverage and is only used within @istest classes, hence adding it too

@@ -3,7 +3,7 @@ public class Account_t extends DomainBuilder {

public Account_t() {
super(Account.SObjectType);

Copy link
Author

@jdkgabri jdkgabri Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invisible whitespace removal

@@ -1,10 +1,30 @@
@IsTest
public class DomainBuilder_Test {
@IsTest
private static void staticHappyPath() {
Copy link
Author

@jdkgabri jdkgabri Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test method to demostrate the possibility of calling the save() static method, similar to persist() but without requiring an instance, since it only actually operates on static variables it is logically meaningful.


@IsTest
private static void happyPath() {

Contact_t joe = new Contact_t().first('Ron').last('Harris');
Contact_t joe = new Contact_t().first('Joe').last('Harris');
Copy link
Author

@jdkgabri jdkgabri Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the variable name is joe, so firstName should not be "Ron"

System.assertEquals(6, Limits.getDmlRows());

// Verify
System.assertEquals(5, Limits.getDmlRows());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion was throwing an error because only 5 DML rows are consumed, not 6. SetSavePoint counts against DML Statements, but not against DML Rows. Added extra assert with comments for demostration

@@ -3,36 +3,31 @@ public abstract class DomainBuilder {
private static DirectedGraph graph = new DirectedGraph();
private static Set<DomainBuilder> objects = new Set<DomainBuilder>();

private Boolean isSetupObject;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused related dead code

// PUBLIC

public SObject persist() {
fflib_SObjectUnitOfWork uow = unitOfWork();
public static void save() {
Copy link
Author

@jdkgabri jdkgabri Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provide possible static save() call

}

public SObject persist(fflib_SObjectUnitOfWork.IDML dml) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow injection of custom implementation of UnitOfWork interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant