Skip to content

Commit 76280a7

Browse files
author
Cristian N
committed
test: add tests to uncover the bug
1 parent 0e747fa commit 76280a7

File tree

1 file changed

+74
-6
lines changed

1 file changed

+74
-6
lines changed

sfdx-source/apex-common/test/classes/fflib_SObjectsTest.cls

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ private class fflib_SObjectsTest
102102

103103
System.assertEquals(3, domain.selectWithoutShippingCountry().size());
104104
}
105+
@IsTest
106+
static void itShouldReturnRecordsWithoutFieldValuesForNonStringFields()
107+
{
108+
DomainAccounts domain = generateDomain();
109+
110+
System.assertEquals(4, domain.selectWithoutNumberOfEmployees().size());
111+
}
105112

106113
@IsTest
107114
static void itShouldReturnRecordsWithoutAllFieldValues()
@@ -118,13 +125,20 @@ private class fflib_SObjectsTest
118125

119126
System.assert(domain.selectWithShippingCountry().size() == 4);
120127
}
128+
@IsTest
129+
static void itShouldReturnRecordsWithNumberOfEmployees()
130+
{
131+
DomainAccounts domain = generateDomain();
132+
133+
System.assert(domain.selectWithNumberOfEmployees().size() == 3);
134+
}
121135

122136
@IsTest
123137
static void itShouldReturnRecordsWithAllFieldValues()
124138
{
125139
DomainAccounts domain = generateDomain();
126140

127-
System.assert(domain.selectPopulatedRecords().size() == 4);
141+
System.assert(domain.selectPopulatedRecords().size() == 2);
128142
}
129143

130144
@IsTest
@@ -151,6 +165,44 @@ private class fflib_SObjectsTest
151165
);
152166
}
153167

168+
@IsTest
169+
static void itShouldReturnFieldValuesForNonStringFields()
170+
{
171+
DomainAccounts domain = generateDomain();
172+
173+
final Set<Integer> expectedOriginalType = new Set<Integer>
174+
{
175+
null,
176+
10,
177+
20,
178+
30
179+
};
180+
181+
System.assert(
182+
domain.getFieldValues(Schema.Account.NumberOfEmployees)
183+
.equals(expectedOriginalType)
184+
);
185+
}
186+
187+
@IsTest
188+
static void itShouldReturnStringFieldValuesForNonStringFields()
189+
{
190+
DomainAccounts domain = generateDomain();
191+
192+
final Set<String> expectedStrings = new Set<String>
193+
{
194+
null,
195+
'10',
196+
'20',
197+
'30'
198+
};
199+
200+
System.assert(
201+
domain.getStringFieldValues(Schema.Account.NumberOfEmployees)
202+
.equals(expectedStrings)
203+
);
204+
}
205+
154206
@IsTest
155207
static void itShouldSetFieldValue()
156208
{
@@ -212,11 +264,11 @@ private class fflib_SObjectsTest
212264
{
213265
new Account(Name = 'A', ShippingCountry = 'USA'),
214266
new Account(Name = 'B', ShippingCountry = 'Ireland'),
215-
new Account(Name = 'C', ShippingCountry = 'UK'),
267+
new Account(Name = 'C', ShippingCountry = 'UK', NumberOfEmployees = 10),
216268
new Account(Name = 'D', ShippingCountry = ''),
217-
new Account(Name = 'E'),
269+
new Account(Name = 'E', NumberOfEmployees = 20),
218270
new Account(),
219-
new Account(Name = 'G', ShippingCountry = 'Canada')
271+
new Account(Name = 'G', ShippingCountry = 'Canada', NumberOfEmployees = 30)
220272
}
221273
);
222274
return domain;
@@ -260,13 +312,28 @@ private class fflib_SObjectsTest
260312
);
261313
}
262314

315+
public List<Account> selectWithoutNumberOfEmployees()
316+
{
317+
return (List<Account>) getRecordsWithBlankFieldValues(
318+
Schema.Account.NumberOfEmployees
319+
);
320+
}
321+
322+
public List<Account> selectWithNumberOfEmployees()
323+
{
324+
return (List<Account>) getRecordsWithNotBlankFieldValues(
325+
Schema.Account.NumberOfEmployees
326+
);
327+
}
328+
263329
public List<Account> selectWithEmptyRecord()
264330
{
265331
return (List<Account>) getRecordsWithAllBlankFieldValues(
266332
new Set<Schema.SObjectField>
267333
{
268334
Schema.Account.Name,
269-
Schema.Account.ShippingCountry
335+
Schema.Account.ShippingCountry,
336+
Schema.Account.NumberOfEmployees
270337
}
271338
);
272339
}
@@ -277,7 +344,8 @@ private class fflib_SObjectsTest
277344
new Set<Schema.SObjectField>
278345
{
279346
Schema.Account.Name,
280-
Schema.Account.ShippingCountry
347+
Schema.Account.ShippingCountry,
348+
Schema.Account.NumberOfEmployees
281349
}
282350
);
283351
}

0 commit comments

Comments
 (0)