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

Type casting bugfix #496

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sfdx-source/apex-common/main/classes/fflib_SObjects.cls
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public virtual class fflib_SObjects
{
for (SObjectField field : fields)
{
if (String.isNotBlank((String) record.get(field))) continue;
if (String.isNotBlank(String.valueOf(record.get(field)))) continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

@ImJohnMDaniel You're a stickler on using explicit blocks for if statements. I think that would be a good measure here too, especially since I had to look at it several time to see why this method wasn't doing the opposite of its name. 😇

Copy link
Author

Choose a reason for hiding this comment

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

Hi @stohn777,
First of all, thank you for taking the time to review the PR.
Second, I tend to agree with your comment related to the explicit blocks for if statements but since it's my first time contributing to this codebase, I wasn't sure what are the style conventions so I did not modify that at all.
I also like to enforce these kinds of things, especially the ones that improve the readability and consistency of the codebase and I would have to say that there are many things like this that could be improved in the entire library. If you all agree that this would be something wanted/needed, I would be happy to come up with other PRs to address them. But, since I'm a newbie, I don't want to overstep. I'll follow your lead! Thank you!


result.add(record);
break;
Expand All @@ -279,7 +279,7 @@ public virtual class fflib_SObjects
Boolean allBlank = true;
for (SObjectField field : fields)
{
if (String.isNotBlank((String) record.get(field)))
if (String.isNotBlank(String.valueOf(record.get(field))))
{
allBlank = false;
break;
Expand Down Expand Up @@ -314,7 +314,7 @@ public virtual class fflib_SObjects
{
for (SObjectField field : fields)
{
if (String.isNotBlank((String) record.get(field)))
if (String.isNotBlank(String.valueOf(record.get(field))))
{
result.add(record);
break;
Expand All @@ -337,7 +337,7 @@ public virtual class fflib_SObjects
Boolean allNonBlank = true;
for (SObjectField field : fields)
{
if (String.isBlank((String) record.get(field)))
if (String.isBlank(String.valueOf(record.get(field))))
{
allNonBlank = false;
break;
Expand Down
80 changes: 74 additions & 6 deletions sfdx-source/apex-common/test/classes/fflib_SObjectsTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ private class fflib_SObjectsTest

System.assertEquals(3, domain.selectWithoutShippingCountry().size());
}
@IsTest
static void itShouldReturnRecordsWithoutFieldValuesForNonStringFields()
{
DomainAccounts domain = generateDomain();

System.assertEquals(4, domain.selectWithoutNumberOfEmployees().size());
}

@IsTest
static void itShouldReturnRecordsWithoutAllFieldValues()
Expand All @@ -118,13 +125,20 @@ private class fflib_SObjectsTest

System.assert(domain.selectWithShippingCountry().size() == 4);
}
@IsTest
static void itShouldReturnRecordsWithNumberOfEmployees()
{
DomainAccounts domain = generateDomain();

System.assert(domain.selectWithNumberOfEmployees().size() == 3);
}

@IsTest
static void itShouldReturnRecordsWithAllFieldValues()
{
DomainAccounts domain = generateDomain();

System.assert(domain.selectPopulatedRecords().size() == 4);
System.assert(domain.selectPopulatedRecords().size() == 2);
}

@IsTest
Expand All @@ -151,6 +165,44 @@ private class fflib_SObjectsTest
);
}

@IsTest
static void itShouldReturnFieldValuesForNonStringFields()
{
DomainAccounts domain = generateDomain();

final Set<Integer> expectedOriginalType = new Set<Integer>
{
null,
10,
20,
30
};

System.assert(
domain.getFieldValues(Schema.Account.NumberOfEmployees)
.equals(expectedOriginalType)
);
}

@IsTest
static void itShouldReturnStringFieldValuesForNonStringFields()
{
DomainAccounts domain = generateDomain();

final Set<String> expectedStrings = new Set<String>
{
null,
'10',
'20',
'30'
};

System.assert(
domain.getStringFieldValues(Schema.Account.NumberOfEmployees)
.equals(expectedStrings)
);
}

@IsTest
static void itShouldSetFieldValue()
{
Expand Down Expand Up @@ -212,11 +264,11 @@ private class fflib_SObjectsTest
{
new Account(Name = 'A', ShippingCountry = 'USA'),
new Account(Name = 'B', ShippingCountry = 'Ireland'),
new Account(Name = 'C', ShippingCountry = 'UK'),
new Account(Name = 'C', ShippingCountry = 'UK', NumberOfEmployees = 10),
new Account(Name = 'D', ShippingCountry = ''),
new Account(Name = 'E'),
new Account(Name = 'E', NumberOfEmployees = 20),
new Account(),
new Account(Name = 'G', ShippingCountry = 'Canada')
new Account(Name = 'G', ShippingCountry = 'Canada', NumberOfEmployees = 30)
}
);
return domain;
Expand Down Expand Up @@ -260,13 +312,28 @@ private class fflib_SObjectsTest
);
}

public List<Account> selectWithoutNumberOfEmployees()
{
return (List<Account>) getRecordsWithBlankFieldValues(
Schema.Account.NumberOfEmployees
);
}

public List<Account> selectWithNumberOfEmployees()
{
return (List<Account>) getRecordsWithNotBlankFieldValues(
Schema.Account.NumberOfEmployees
);
}

public List<Account> selectWithEmptyRecord()
{
return (List<Account>) getRecordsWithAllBlankFieldValues(
new Set<Schema.SObjectField>
{
Schema.Account.Name,
Schema.Account.ShippingCountry
Schema.Account.ShippingCountry,
Schema.Account.NumberOfEmployees
}
);
}
Expand All @@ -277,7 +344,8 @@ private class fflib_SObjectsTest
new Set<Schema.SObjectField>
{
Schema.Account.Name,
Schema.Account.ShippingCountry
Schema.Account.ShippingCountry,
Schema.Account.NumberOfEmployees
}
);
}
Expand Down
Loading