I haven't understood your usecase well enough. So you would need to explain a bit more with some examples as to what exactly are you trying to do with your excelsheet and how it relates to a Map. Feel free to add more context.
Here I am assuming that the entire data set from a datasource such as xls will be one Map, wherein every row will correspond to a key in the Map, and the values represents the column values for each row.
public class HashmapsAsDataLazy {
private Collection<String> values;
private String testName;
@Test (dataProvider = "insideDp")
public void testMethod(String eachValue) {
Reporter.log(testName + " has its value was " + eachValue, true);
}
@DataProvider (name = "insideDp")
public Object[][] getMoreData() {
Object[][] testData = new Object[values.size()][1];
int i = 0;
for (String eachValue : values) {
testData[i++][0] = eachValue;
}
return testData;
}
@Factory (dataProvider = "dp")
public HashmapsAsDataLazy(String testName, Collection<String> values) {
this.values = values;
this.testName = testName;
}
@DataProvider (name = "dp")
public static Object[][] getData() {
Map<String, String> object1 = new HashMap<>();
object1.put("height", "5.5 ft");
object1.put("weight", "45 kgs");
Map<String, String> object2 = new HashMap<>();
object2.put("age", "2");
object2.put("weight", "45 kgs");
Map<String, String> object3 = new HashMap<>();
object3.put("color", "brown");
object3.put("orientation", "portrait");
return new Object[][] {
{"object1", object1.values()},
{"object2", object2.values()},
{"object3", object3.values()}
};
}
}-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running organized.chaos.testng.HashmapsAsDataLazy
Configuring TestNG with: TestNG652Configurator
object1 has its value was 45 kgs
object1 has its value was 5.5 ft
object3 has its value was portrait
object3 has its value was brown
object2 has its value was 45 kgs
object2 has its value was 2
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.48 sec - in organized.chaos.testng.HashmapsAsDataLazy
Results :
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.917 s
[INFO] Finished at: 2015-11-08T12:26:00+05:30
[INFO] Final Memory: 22M/174M
[INFO] ------------------------------------------------------------------------