You need to sign in to do that
Don't have an account?
sgss
Test Class for Map and its method...
//////Can anyone help me out for the Test Class of following Code, If any modification is needed to simplify Test Class you can provide in the code.
Cover all positive negative Bulk Testing if possible
////Description: Use of map and its methods
public class MapClass {
public void createMap(){
/**
1. Create Map and Enter Key value using : Map.put(key,value)
2. The map elements of mapString2 are copied from mapString
Account account1 = new Account(Name='marry',BillingCity='Las Vegas');
Account account2 = new Account(Name='John',BillingCity='Sydney');
Map<Integer, Account> mapAccount = new Map<Integer, Account> {};
mapAccount.put(1, account1);
mapAccount.put(2,account2);
System.debug('Map mapAccount contains: '+mapAccount);
/**
Create Map and get value using : Map.get(Key)
*/
Map<Integer, Account> mapAccount2 = mapAccount.clone();
mapAccount.get(1).BillingCity ='Las Vegas';
System.assertEquals('Las Vegas',mapAccount2.get(1).BillingCity);
/**
Map.containskey(key) : To check if map contains particular Key
*/
Boolean contains = mapAccount.containsKey(3);
System.debug('containskey result'+contains);
/**
keyset : Returns a set that contains all of the keys in the map.
*/
Set <Integer> keysetInt = new Set<Integer>();
keysetInt = mapAccount.keySet();
/**
Map.size() : Function to get Number of Element in Map
*/
Integer mapSize = mapAccount.size();
System.debug('Size of Map is'+mapSize);
/**
Map.value() : To get All value is Map
*/
List<Account> accountList = new List<Account>();
accountList = mapAccount.values();
System.debug('Value in Account List : '+accountList);
/**
Map.remove(key) : Remove Value at that key
*/
mapAccount.remove(1);
System.debug('Map mapAccount after remove: '+mapAccount);
}
}
Cover all positive negative Bulk Testing if possible
////Description: Use of map and its methods
public class MapClass {
public void createMap(){
/**
1. Create Map and Enter Key value using : Map.put(key,value)
2. The map elements of mapString2 are copied from mapString
Account account1 = new Account(Name='marry',BillingCity='Las Vegas');
Account account2 = new Account(Name='John',BillingCity='Sydney');
Map<Integer, Account> mapAccount = new Map<Integer, Account> {};
mapAccount.put(1, account1);
mapAccount.put(2,account2);
System.debug('Map mapAccount contains: '+mapAccount);
/**
Create Map and get value using : Map.get(Key)
*/
Map<Integer, Account> mapAccount2 = mapAccount.clone();
mapAccount.get(1).BillingCity ='Las Vegas';
System.assertEquals('Las Vegas',mapAccount2.get(1).BillingCity);
/**
Map.containskey(key) : To check if map contains particular Key
*/
Boolean contains = mapAccount.containsKey(3);
System.debug('containskey result'+contains);
/**
keyset : Returns a set that contains all of the keys in the map.
*/
Set <Integer> keysetInt = new Set<Integer>();
keysetInt = mapAccount.keySet();
/**
Map.size() : Function to get Number of Element in Map
*/
Integer mapSize = mapAccount.size();
System.debug('Size of Map is'+mapSize);
/**
Map.value() : To get All value is Map
*/
List<Account> accountList = new List<Account>();
accountList = mapAccount.values();
System.debug('Value in Account List : '+accountList);
/**
Map.remove(key) : Remove Value at that key
*/
mapAccount.remove(1);
System.debug('Map mapAccount after remove: '+mapAccount);
}
}
You really need to understand the fundamentals