Skip to content

Commit

Permalink
issue-192 Refactoring UnitTests to replace System.assert with assert (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kryvyifedir authored Oct 3, 2024
1 parent 1807182 commit 1aa4f77
Show file tree
Hide file tree
Showing 25 changed files with 209 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ private class AchievementReachedEventsManagerTest {
Test.stopTest();

// Then
System.assertNotEquals(null, results, 'Results are expected to be returned by the method');
System.assertEquals(1, results.size(), 'Single event is expected to be sent per 1 stat');
Assert.isNotNull(results, 'Results are expected to be returned by the method');
Assert.areEqual(1, results.size(), 'Single event is expected to be sent per 1 stat');
for (Database.SaveResult result : results) {
System.assert(result.isSuccess(), 'Event is expected to be sent without any issues');
Assert.isTrue(result.isSuccess(), 'Event is expected to be sent without any issues');
}
}

Expand All @@ -41,7 +41,7 @@ private class AchievementReachedEventsManagerTest {
Test.stopTest();

// Then
System.assertEquals(null, results, 'Since achievement was already reached no Events are expected to be fired');
Assert.isNull(results, 'Since achievement was already reached no Events are expected to be fired');
}

@IsTest
Expand All @@ -61,7 +61,7 @@ private class AchievementReachedEventsManagerTest {
Test.stopTest();

// Then
System.assertEquals(null, results, 'Validation is expected to prevent any Events from being sent');
Assert.isNull(results, 'Validation is expected to prevent any Events from being sent');
}

@IsTest
Expand All @@ -76,6 +76,6 @@ private class AchievementReachedEventsManagerTest {
Test.stopTest();

// Then
System.assertEquals(null, results, 'Validation is expected to prevent any Events from being sent');
Assert.isNull(results, 'Validation is expected to prevent any Events from being sent');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ private class AchievementReachedTriggerHandlerTest {

// Then
List<ReachedAchievement__c> result = [SELECT Id, Key__c, User__c, Achievement__c FROM ReachedAchievement__c];
System.assertNotEquals(null, result, 'ReachedAchievement__c are expected to be created');
System.assertEquals(1, result.size(), 'Single ReachedAchievement__c is expected to be created');
System.assertEquals(userId, result[0].User__c, 'User__c filed value is expected to match userId');
System.assertEquals(achievement.Id, result[0].Achievement__c, 'User__c filed value is expected to match userId');
Assert.isNotNull(result, 'ReachedAchievement__c are expected to be created');
Assert.areEqual(1, result.size(), 'Single ReachedAchievement__c is expected to be created');
Assert.areEqual(userId, result[0].User__c, 'User__c filed value is expected to match userId');
Assert.areEqual(achievement.Id, result[0].Achievement__c, 'User__c filed value is expected to match userId');
}

@IsTest
Expand All @@ -43,7 +43,7 @@ private class AchievementReachedTriggerHandlerTest {

// Then
List<ReachedAchievement__c> result = [SELECT Id, Key__c, User__c, Achievement__c FROM ReachedAchievement__c];
System.assertEquals(1, result.size(), 'No new ReachedAchievement__c are expected to be created');
Assert.areEqual(1, result.size(), 'No new ReachedAchievement__c are expected to be created');
}

@IsTest
Expand All @@ -66,10 +66,10 @@ private class AchievementReachedTriggerHandlerTest {

// Then
List<ReachedAchievement__c> result = [SELECT Id, Key__c, User__c, Achievement__c FROM ReachedAchievement__c];
System.assertNotEquals(null, result, 'ReachedAchievement__c are expected to be created');
System.assertEquals(1, result.size(), 'Single ReachedAchievement__c is expected to be created');
System.assertEquals(userId, result[0].User__c, 'User__c filed value is expected to match userId');
System.assertEquals(achievement.Id, result[0].Achievement__c, 'User__c filed value is expected to match userId');
Assert.isNotNull(result, 'ReachedAchievement__c are expected to be created');
Assert.areEqual(1, result.size(), 'Single ReachedAchievement__c is expected to be created');
Assert.areEqual(userId, result[0].User__c, 'User__c filed value is expected to match userId');
Assert.areEqual(achievement.Id, result[0].Achievement__c, 'User__c filed value is expected to match userId');
}

@IsTest
Expand All @@ -91,7 +91,7 @@ private class AchievementReachedTriggerHandlerTest {
// Then
List<ReachedAchievement__c> result = [SELECT Id, Key__c, User__c, Achievement__c FROM ReachedAchievement__c];
List<Log__c> resultLogs = [SELECT Id FROM Log__c];
System.assertEquals(0, result.size(), 'No new ReachedAchievement__c are expected to be created');
Assert.isTrue(result.isEmpty(), 'No new ReachedAchievement__c are expected to be created');
}

@IsTest
Expand All @@ -113,7 +113,7 @@ private class AchievementReachedTriggerHandlerTest {
// Then
List<ReachedAchievement__c> result = [SELECT Id, Key__c, User__c, Achievement__c FROM ReachedAchievement__c];
List<Log__c> resultLogs = [SELECT Id FROM Log__c];
System.assertEquals(0, result.size(), 'No new ReachedAchievement__c are expected to be created');
Assert.isTrue(result.isEmpty(), 'No new ReachedAchievement__c are expected to be created');
}

@IsTest
Expand All @@ -139,7 +139,7 @@ private class AchievementReachedTriggerHandlerTest {

// Then
List<ReachedAchievement__c> result = [SELECT Id, Key__c, User__c, Achievement__c FROM ReachedAchievement__c];
System.assertNotEquals(null, result, 'ReachedAchievement__c are expected to be created');
System.assertEquals(202, result.size(), 'Single ReachedAchievement__c is expected to be created');
Assert.isNotNull(result, 'ReachedAchievement__c are expected to be created');
Assert.areEqual(202, result.size(), 'Single ReachedAchievement__c is expected to be created');
}
}
4 changes: 2 additions & 2 deletions force-app/main/default/classes/AchievementSelectorTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private class AchievementSelectorTest {
Test.stopTest();

// Then
system.assertEquals('Achievement__c', result, 'Achievement__c sObject ApiName is expected');
Assert.areEqual('Achievement__c', result, 'Achievement__c sObject ApiName is expected');
}

@IsTest
Expand All @@ -27,6 +27,6 @@ private class AchievementSelectorTest {

// Then
Set<String> expectedSet = new Set<String> {'Id', 'Name', 'Description__c', 'Goal__c', 'Score__c', 'UITitle__c', 'UIDescription__c', 'Measurement__c'};
system.assertEquals(expectedSet, result, 'A specific field set is expected');
Assert.areEqual(expectedSet, result, 'A specific field set is expected');
}
}
46 changes: 23 additions & 23 deletions force-app/main/default/classes/AchievementsDataHelperTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ private class AchievementsDataHelperTest {
Test.stopTest();

// Then
System.assert(result.containsKey(user1.Id), 'Map is expected to have keys for both users');
System.assert(result.containsKey(user2.Id), 'Map is expected to have keys for both users');
Assert.isTrue(result.containsKey(user1.Id), 'Map is expected to have keys for both users');
Assert.isTrue(result.containsKey(user2.Id), 'Map is expected to have keys for both users');

List<DataWrappers.AchievementCardData> resultUser1 = result.get(user1.Id);
System.assertEquals(2, resultUser1.size(), '2 Achievements are expected');
Assert.areEqual(2, resultUser1.size(), '2 Achievements are expected');
for (DataWrappers.AchievementCardData achievementData : resultUser1) {
if (achievementData.id == achievement1.Id) {
System.assertEquals(true, achievementData.isReached, 'First achievement for the first user is expected to be marked as reached');
Assert.isTrue(achievementData.isReached, 'First achievement for the first user is expected to be marked as reached');
} else {
System.assertEquals(false, achievementData.isReached, 'All other achievements are expected to be not reached');
Assert.isFalse(achievementData.isReached, 'All other achievements are expected to be not reached');
}
}

List<DataWrappers.AchievementCardData> resultUser2 = result.get(user2.Id);
System.assertEquals(2, resultUser2.size(), '2 Achievements are expected');
Assert.areEqual(2, resultUser2.size(), '2 Achievements are expected');
for (DataWrappers.AchievementCardData achievementData : resultUser2) {
System.assertEquals(false, achievementData.isReached, 'All achievements for second user are expected to be not reached');
Assert.isFalse(achievementData.isReached, 'All achievements for second user are expected to be not reached');
}
}

Expand All @@ -56,7 +56,7 @@ private class AchievementsDataHelperTest {
DataWrappers.AchievementCardData result = AchievementsDataHelper.getClosestAchievementForUser(UserInfo.getUserId());
Test.stopTest();

System.assertEquals(achievement1.Id, result.id, 'Information about achievement 1 is expected to be returned');
Assert.areEqual(achievement1.Id, result.id, 'Information about achievement 1 is expected to be returned');
}

@IsTest
Expand All @@ -75,7 +75,7 @@ private class AchievementsDataHelperTest {
DataWrappers.AchievementCardData result = AchievementsDataHelper.getClosestAchievementForUser(UserInfo.getUserId());
Test.stopTest();

System.assertEquals(achievement2.Id, result.id, 'Information about achievement 2 is expected to be returned');
Assert.areEqual(achievement2.Id, result.id, 'Information about achievement 2 is expected to be returned');
}

@IsTest
Expand All @@ -94,7 +94,7 @@ private class AchievementsDataHelperTest {
DataWrappers.AchievementCardData result = AchievementsDataHelper.getClosestAchievementForUser(UserInfo.getUserId());
Test.stopTest();

System.assertEquals(null, result.id, 'Null is expected since all achievements were reached');
Assert.isNull(result.id, 'Null is expected since all achievements were reached');
}

@IsTest
Expand All @@ -116,7 +116,7 @@ private class AchievementsDataHelperTest {
DataWrappers.AchievementCardData result = AchievementsDataHelper.getClosestAchievementForUser(UserInfo.getUserId());
Test.stopTest();

System.assertEquals(achievement3.Id, result.id, 'Information about achievement 3 is expected to be returned');
Assert.areEqual(achievement3.Id, result.id, 'Information about achievement 3 is expected to be returned');
}

@IsTest
Expand All @@ -133,12 +133,12 @@ private class AchievementsDataHelperTest {
Test.stopTest();

// Then
System.assertEquals(achievement1.Id, cardData.Id);
System.assertEquals(achievement1.UITitle__c, cardData.uiTitle);
System.assertEquals(achievement1.UIDescription__c, cardData.uiDescription);
System.assertEquals(achievement1.Score__c, cardData.score);
System.assertEquals(true, cardData.isReached);
System.assertEquals(reachedAchievement.CreatedDate.getTime(), cardData.ReachedDate);
Assert.areEqual(achievement1.Id, cardData.Id);
Assert.areEqual(achievement1.UITitle__c, cardData.uiTitle);
Assert.areEqual(achievement1.UIDescription__c, cardData.uiDescription);
Assert.areEqual(achievement1.Score__c, cardData.score);
Assert.isTrue(cardData.isReached);
Assert.areEqual(reachedAchievement.CreatedDate.getTime(), cardData.ReachedDate);
}

@IsTest
Expand All @@ -153,12 +153,12 @@ private class AchievementsDataHelperTest {
Test.stopTest();

// Then
System.assertEquals(achievement1.Id, cardData.Id);
System.assertEquals(achievement1.UITitle__c, cardData.uiTitle);
System.assertEquals(achievement1.UIDescription__c, cardData.uiDescription);
System.assertEquals(achievement1.Score__c, cardData.score);
System.assertEquals(false, cardData.isReached);
System.assertEquals(0, cardData.ReachedDate);
Assert.areEqual(achievement1.Id, cardData.Id);
Assert.areEqual(achievement1.UITitle__c, cardData.uiTitle);
Assert.areEqual(achievement1.UIDescription__c, cardData.uiDescription);
Assert.areEqual(achievement1.Score__c, cardData.score);
Assert.isFalse(cardData.isReached);
Assert.areEqual(0, cardData.ReachedDate);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ private class AchievementsInfoControllerTest {
Test.stopTest();

// Then
System.assert(result.containsKey('Success'), 'Resulting map is expected to have "Success" key');
System.assert(!result.containsKey('Warning'), 'Resulting map is not expected to have "Warning" key');
System.assert(!result.containsKey('Error'), 'Resulting map is not expected to have "Error" key');
Assert.isTrue(result.containsKey('Success'), 'Resulting map is expected to have "Success" key');
Assert.isTrue(!result.containsKey('Warning'), 'Resulting map is not expected to have "Warning" key');
Assert.isTrue(!result.containsKey('Error'), 'Resulting map is not expected to have "Error" key');

Map<Id, List<DataWrappers.AchievementCardData>> achievementsByUserIdMap = (Map<Id, List<DataWrappers.AchievementCardData>>) result.get('Success');
List<DataWrappers.AchievementCardData> userAchievementCardDataList = achievementsByUserIdMap.get(UserInfo.getUserId());

System.assertNotEquals(null, userAchievementCardDataList, 'Achievements are expected to be found for current user');
System.assertEquals(2, userAchievementCardDataList.size(), '2 Achievements are expected');
Assert.isNotNull(userAchievementCardDataList, 'Achievements are expected to be found for current user');
Assert.areEqual(2, userAchievementCardDataList.size(), '2 Achievements are expected');
for (DataWrappers.AchievementCardData achievementData : userAchievementCardDataList) {
if (achievementData.id == achievement1.Id) {
System.assertEquals(true, achievementData.isReached, 'First achievement for the user is expected to be marked as reached');
Assert.isTrue(achievementData.isReached, 'First achievement for the user is expected to be marked as reached');
} else {
System.assertEquals(false, achievementData.isReached, 'All other achievements are expected to be not reached');
Assert.isFalse(achievementData.isReached, 'All other achievements are expected to be not reached');
}
}
}
Expand All @@ -46,9 +46,8 @@ private class AchievementsInfoControllerTest {
Test.stopTest();

// Then
System.assert(true, 'Exception is expected to be handled safely');
} catch (Exception e) {
System.assert(false, 'Exception is expected to be handled safely');
Assert.fail('Exception is expected to be handled safely');
}

}
Expand Down
9 changes: 4 additions & 5 deletions force-app/main/default/classes/CaseTriggerHandlerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public with sharing class CaseTriggerHandlerTest {

// Then
List<UserMeasurement__c> result = [SELECT Id, User__c, Measurement__c, Value__c FROM UserMeasurement__c];
System.assertEquals(1, result.size(), 'Single UserMeasurement__c is expected for all 201 Case records');
System.assertEquals(202, result[0].Value__c, 'Single UserMeasurement__c Value is expected to a total number of Cases');
Assert.areEqual(1, result.size(), 'Single UserMeasurement__c is expected for all 201 Case records');
Assert.areEqual(202, result[0].Value__c, 'Single UserMeasurement__c Value is expected to a total number of Cases');
}

@IsTest
Expand All @@ -45,7 +45,7 @@ public with sharing class CaseTriggerHandlerTest {

// Then
List<UserMeasurement__c> result = [SELECT Id, User__c, Measurement__c, Value__c FROM UserMeasurement__c];
System.assertEquals(0, result.size(), 'Zero UserMeasurement__c is expected to be created');
Assert.areEqual(0, result.size(), 'Zero UserMeasurement__c is expected to be created');
}

@IsTest
Expand All @@ -58,9 +58,8 @@ public with sharing class CaseTriggerHandlerTest {
Test.stopTest();

// Then
System.assert(true, 'Exception is expected to be handled safely');
} catch (Exception e) {
System.assert(false, 'Exception is expected to be handled safely');
Assert.fail('Exception is expected to be handled safely');
}
}
}
24 changes: 12 additions & 12 deletions force-app/main/default/classes/ControllerResponseTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ private class ControllerResponseTest {
Test.stopTest();

// Then
system.assert(result.containsKey('Success'), 'Map is expected to include Success key');
system.assert(!result.containsKey('Error'), 'Map is not expected to include Error key');
system.assert(!result.containsKey('Warning'), 'Map is not expected to include Warning key');
system.assertEquals('Test', (String) result.get('Success'), 'Value is expected to be stored in Map under Success key');
Assert.isTrue(result.containsKey('Success'), 'Map is expected to include Success key');
Assert.isFalse(result.containsKey('Error'), 'Map is not expected to include Error key');
Assert.isFalse(result.containsKey('Warning'), 'Map is not expected to include Warning key');
Assert.areEqual('Test', (String) result.get('Success'), 'Value is expected to be stored in Map under Success key');
}

@IsTest
Expand All @@ -28,10 +28,10 @@ private class ControllerResponseTest {
Test.stopTest();

// Then
system.assert(!result.containsKey('Success'), 'Map is not expected to include Success key');
system.assert(result.containsKey('Error'), 'Map is expected to include Error key');
system.assert(!result.containsKey('Warning'), 'Map is not expected to include Warning key');
system.assertEquals('Test', (String) result.get('Error'), 'Value is expected to be stored in Map under Success key');
Assert.isFalse(result.containsKey('Success'), 'Map is not expected to include Success key');
Assert.isTrue(result.containsKey('Error'), 'Map is expected to include Error key');
Assert.isFalse(result.containsKey('Warning'), 'Map is not expected to include Warning key');
Assert.areEqual('Test', (String) result.get('Error'), 'Value is expected to be stored in Map under Success key');
}

@IsTest
Expand All @@ -45,9 +45,9 @@ private class ControllerResponseTest {
Test.stopTest();

// Then
system.assert(!result.containsKey('Success'), 'Map is not expected to include Success key');
system.assert(!result.containsKey('Error'), 'Map is not expected to include Error key');
system.assert(result.containsKey('Warning'), 'Map is expected to include Warning key');
system.assertEquals('Test', (String) result.get('Warning'), 'Value is expected to be stored in Map under Success key');
Assert.isFalse(result.containsKey('Success'), 'Map is not expected to include Success key');
Assert.isFalse(result.containsKey('Error'), 'Map is not expected to include Error key');
Assert.isTrue(result.containsKey('Warning'), 'Map is expected to include Warning key');
Assert.areEqual('Test', (String) result.get('Warning'), 'Value is expected to be stored in Map under Success key');
}
}
13 changes: 6 additions & 7 deletions force-app/main/default/classes/FeedItemTriggerHandlerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ private class FeedItemTriggerHandlerTest {

// Then
List<UserMeasurement__c> result = [SELECT Id, User__c, Measurement__c, Value__c FROM UserMeasurement__c];
System.assertEquals(1, result.size(), 'Single UserMeasurement__c is expected for all 201 FeedItem records');
System.assertEquals(202, result[0].Value__c, 'Single UserMeasurement__c Value is expected to a total number of FeedItems');
Assert.areEqual(1, result.size(), 'Single UserMeasurement__c is expected for all 201 FeedItem records');
Assert.areEqual(202, result[0].Value__c, 'Single UserMeasurement__c Value is expected to a total number of FeedItems');
}

@IsTest
Expand All @@ -42,8 +42,8 @@ private class FeedItemTriggerHandlerTest {

// Then
List<UserMeasurement__c> result = [SELECT Id, User__c, Measurement__c, Value__c FROM UserMeasurement__c];
System.assertEquals(1, result.size(), 'Single UserMeasurement__c is expected for all 201 FeedItem records');
System.assertEquals(202, result[0].Value__c, 'Single UserMeasurement__c Value is expected to a total number of FeedItems');
Assert.areEqual(1, result.size(), 'Single UserMeasurement__c is expected for all 201 FeedItem records');
Assert.areEqual(202, result[0].Value__c, 'Single UserMeasurement__c Value is expected to a total number of FeedItems');
}

@IsTest
Expand All @@ -62,7 +62,7 @@ private class FeedItemTriggerHandlerTest {

// Then
List<UserMeasurement__c> result = [SELECT Id, User__c, Measurement__c, Value__c FROM UserMeasurement__c];
System.assertEquals(0, result.size(), 'Zero UserMeasurement__c is expected to be created');
Assert.areEqual(0, result.size(), 'Zero UserMeasurement__c is expected to be created');
}

@IsTest
Expand All @@ -75,9 +75,8 @@ private class FeedItemTriggerHandlerTest {
Test.stopTest();

// Then
System.assert(true, 'Exception is expected to be handled safely');
} catch (Exception e) {
System.assert(false, 'Exception is expected to be handled safely');
Assert.fail('Exception is expected to be handled safely');
}
}
}
Loading

0 comments on commit 1aa4f77

Please sign in to comment.