Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlic committed Jul 5, 2024
1 parent 8d72b3f commit c82efc8
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class DecimalCollectionTest {
@IsTest
private static void sumShouldReturnSumIfItExists() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class DoubleCollectionTest {
@IsTest
private static void sumShouldReturnSumIfItExists() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class SObjectCollectionTest {

static Id firstUserId = TestUtility.getFakeId(User.SObjectType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class MapToObjectTest {

private class MappingTarget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,69 @@
public with sharing class MapToSObjectTest {

@IsTest
private static void testFieldSetting() {
Id oppId = TestUtility.getFakeId(Opportunity.SObjectType);
Opportunity opp = new Opportunity(Id = oppId);
private static void testSetFieldWithFieldValue() {
Opportunity opp = new Opportunity();
Task task = (Task) new MapToSObject(Task.SObjectType).setField(Task.Subject, 'Test').call(opp);
System.Assert.areEqual('Test', task.Subject);
}

@IsTest
private static void testFieldNameSetting() {
Id oppId = TestUtility.getFakeId(Opportunity.SObjectType);
Opportunity opp = new Opportunity(Id = oppId);
private static void testSetFieldWithRelationValue() {
Opportunity opp = new Opportunity();
Task task = (Task) new MapToSObject(Task.SObjectType).setField('Subject', 'Test').call(opp);
System.Assert.areEqual('Test', task.Subject);
}

@IsTest
private static void testSimpleFieldMapping() {
Id oppId = TestUtility.getFakeId(Opportunity.SObjectType);
Opportunity opp = new Opportunity(Id = oppId);
Task task = (Task) new MapToSObject(Task.SObjectType).mapField(Task.WhatId, Opportunity.Id).call(opp);
System.Assert.areEqual(oppId, task.WhatId);
private static void testSetFieldsWithFieldValues() {
Opportunity opp = new Opportunity();
Task task = (Task) new MapToSObject(Task.SObjectType).setFields(new Map<Schema.SObjectField, Object>{
Task.Subject => 'Test'
}).call(opp);
System.Assert.areEqual('Test', task.Subject);
}

@IsTest
private static void testSimpleFieldNameMapping() {
private static void testSetFieldsWithPrototype() {
Opportunity opp = new Opportunity();
Task task = (Task) new MapToSObject(Task.SObjectType).setFields(new Task(Subject = 'Test')).call(opp);
System.Assert.areEqual('Test', task.Subject);
}

@IsTest
private static void testMapFieldWithField() {
Id oppId = TestUtility.getFakeId(Opportunity.SObjectType);
Opportunity opp = new Opportunity(Id = oppId);
Task task = (Task) new MapToSObject(Task.SObjectType).mapField(Task.WhatId, 'Id').call(opp);
Task task = (Task) new MapToSObject(Task.SObjectType).mapField(Task.WhatId, Opportunity.Id).call(opp);
System.Assert.areEqual(oppId, task.WhatId);
}

@IsTest
private static void testRelationMapping() {
private static void testMapFieldWithRelation() {
Id accountId = TestUtility.getFakeId(Account.SObjectType);
Opportunity opp = new Opportunity(Account = new Account(Id = accountId));
Task task = (Task) new MapToSObject(Task.SObjectType).mapField(Task.WhatId, 'Account.Id').call(opp);
System.Assert.areEqual(accountId, task.WhatId);
}

@IsTest
private static void testMapFieldsWithFields() {
Opportunity opp = new Opportunity(Description = 'Test', Amount = 500);
Account account = (Account) new MapToSObject(Account.SObjectType).mapFields(new Map<Schema.SObjectfield, Schema.SObjectField>{
Account.Description => Opportunity.Description,
Account.AnnualRevenue => Opportunity.Amount
}).call(opp);
System.Assert.areEqual(account.Description, opp.Description);
System.Assert.areEqual(account.AnnualRevenue, opp.Amount);
}

@IsTest
private static void testMapFieldsWithRelations() {
Opportunity opp = new Opportunity(Description = 'Test', Amount = 500);
Account account = (Account) new MapToSObject(Account.SObjectType).mapFields(new Map<Schema.SObjectfield, String>{
Account.Description => 'Description',
Account.AnnualRevenue => 'Amount'
}).call(opp);
System.Assert.areEqual(account.Description, opp.Description);
System.Assert.areEqual(account.AnnualRevenue, opp.Amount);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class ModifySObjectTest {

@IsTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class SObjectStreamTest {
@IsTest
private static void testFilter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class OptionalDecimalTest {
@IsTest
private static void optionalCanBeNull() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class OptionalDoubleTest {
@IsTest
private static void optionalCanBeNull() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class OptionalSObjectTest {
@IsTest
private static void optionalCanBeNull() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class PrimitiveComparerTest {
@IsTest
private static void nullComparison() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@IsTest(IsParallel=true)
@IsTest(isParallel=true)
private class SObjectFieldReaderTest {
@IsTest
private static void testResolving() {
Expand Down

0 comments on commit c82efc8

Please sign in to comment.