@@ -85,7 +85,8 @@ public class fflib_ApexMocksUtilsTest
85
85
}
86
86
87
87
@isTest
88
- private static void makeRelationship_GenericOverload_ReturnsObjectsWithRelationFieldSet () {
88
+ private static void makeRelationship_GenericOverload_ReturnsObjectsWithRelationFieldSet ()
89
+ {
89
90
// Given
90
91
SObject acc = Schema .getGlobalDescribe ().get (' Account' ).newSObject ();
91
92
acc .put (' Id' , fflib_IDGenerator .generate (acc .getSObjectType ()));
@@ -128,8 +129,8 @@ public class fflib_ApexMocksUtilsTest
128
129
}
129
130
130
131
@isTest
131
- private static void makeRelationship_GenericOverload_ThrowsErrorOnInvalidParentType () {
132
-
132
+ private static void makeRelationship_GenericOverload_ThrowsErrorOnInvalidParentType ()
133
+ {
133
134
// Setup parent object
134
135
SObject acc = Schema .getGlobalDescribe ().get (' Account' ).newSObject ();
135
136
acc .put (' Id' , fflib_IDGenerator .generate (acc .getSObjectType ()));
@@ -155,8 +156,8 @@ public class fflib_ApexMocksUtilsTest
155
156
}
156
157
157
158
@isTest
158
- private static void makeRelationship_GenericOverload_ThrowsErrorOnInvalidChildType () {
159
-
159
+ private static void makeRelationship_GenericOverload_ThrowsErrorOnInvalidChildType ()
160
+ {
160
161
// Setup parent object
161
162
SObject acc = Schema .getGlobalDescribe ().get (' Account' ).newSObject ();
162
163
acc .put (' Id' , fflib_IDGenerator .generate (acc .getSObjectType ()));
@@ -182,8 +183,8 @@ public class fflib_ApexMocksUtilsTest
182
183
}
183
184
184
185
@isTest
185
- private static void makeRelationship_GenericOverload_ThrowsErrorOnInvalidFieldName () {
186
-
186
+ private static void makeRelationship_GenericOverload_ThrowsErrorOnInvalidFieldName ()
187
+ {
187
188
// Setup parent object
188
189
SObject acc = Schema .getGlobalDescribe ().get (' Account' ).newSObject ();
189
190
acc .put (' Id' , fflib_IDGenerator .generate (acc .getSObjectType ()));
@@ -208,6 +209,67 @@ public class fflib_ApexMocksUtilsTest
208
209
System .Assert .areEqual (' SObject field not found: MyInvalidField' , errorMessage );
209
210
}
210
211
212
+ @IsTest
213
+ private static void makeRelationship_ObjectWithNull_DoesNotThrowErrorOnJSONExceptionCanNotWriteAFieldNameExpectingAValue ()
214
+ {
215
+ // Given
216
+ Product2 prod1 = new Product2 (
217
+ Id = fflib_IDGenerator .generate (Product2 .SObjectType ),
218
+ Name = ' Product1' ,
219
+ ProductCode = ' P1' ,
220
+ Description = null ,
221
+ StockKeepingUnit = ' P1'
222
+ );
223
+
224
+ Product2 prod2 = new Product2 (
225
+ Id = fflib_IDGenerator .generate (Product2 .SObjectType ),
226
+ Name = ' Product2' ,
227
+ ProductCode = ' P2' ,
228
+ Description = ' this is another product' ,
229
+ StockKeepingUnit = ' P2'
230
+ );
231
+
232
+ OrderItem oi1 = new OrderItem (
233
+ Id = fflib_IDGenerator .generate (OrderItem .SObjectType ),
234
+ Product2Id = prod1 .Id ,
235
+ Product2 = prod1 ,
236
+ UnitPrice = 10 ,
237
+ Quantity = 1
238
+ );
239
+
240
+ OrderItem oi2 = new OrderItem (
241
+ Id = fflib_IDGenerator .generate (OrderItem .SObjectType ),
242
+ Product2Id = prod2 .Id ,
243
+ Product2 = prod2 ,
244
+ UnitPrice = 10 ,
245
+ Quantity = 1
246
+ );
247
+
248
+ Order order = new Order ();
249
+
250
+ Exception exceptionThatWasCalled = null ;
251
+
252
+ // When
253
+ Test .startTest ();
254
+
255
+ try {
256
+ fflib_ApexMocksUtils .makeRelationship (
257
+ List <Order >.class ,
258
+ new List <Order >{ order },
259
+ OrderItem .OrderId ,
260
+ new List <List <OrderItem >>{ new List <OrderItem >{oi1 , oi2 } }
261
+ );
262
+ } catch (JSONException e ) {
263
+ exceptionThatWasCalled = e ;
264
+ }
265
+
266
+ Test .stopTest ();
267
+
268
+ // Then
269
+ System .debug (exceptionThatWasCalled );
270
+ Assert .isNull (exceptionThatWasCalled , ' Exception should not have been called' );
271
+ }
272
+
211
273
@isTest
212
274
static void setReadOnlyFields_CreatedByIdSetToCurrentUserId_IdFieldSetSuccessfully () {
213
275
0 commit comments