ShowAll Questionssorted byDate Posted
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);
}

}
Abdul Khatri
Not sure what is this class all about. Man I see too many post from you like that. Can you please let us know what are you trying to accomplish with all these type of classes where is not a very healthy implementation. These are more look like you are trying to teach yourself. I don't see much to be included in the test class for this. Here it is.

You really need to understand the fundamentals

```@isTest
public class MapClassTest {

@isTest static void testcreateMap() {

MapClass mc = new MapClass();
mc.createMap();
}
}```

Abdul Khatri