0

I have the following code

//Unit to be tested (classname : PropertiesFile)
public static String getProperty(String name) {
        return propertiesMap.get(name).toString();
    }

where propertiesMap is a normal hashmap defined as Map propertiesMap;

Here is my TestNG test :

@Test()
public void testGetProperty1(@Mocked final Map<String, String> propertiesMap)

{
    new NonStrictExpectations()
    {{
            propertiesMap.get("region");
            result = anyString;
        }};

    PropertiesFile.getProperty("region");

}

I am getting NPE on return line.

Please let me know what I am doing wrong here? and how to get rid of this NPE and make the test work properly.

Saumya A
  • 11
  • 3

1 Answers1

0

I havent mocked collections till now so no idea whether they can be mocked. Moreover if u want to use this just set the property in your propertiesMap with the key as "region" and directly u will get the value corresponding to it. You dont need to use expectations in such case.