This is the code I want to check
public static Map<String, String> JSON2Map(String urlParams) {
String [] params = urlParams.split("&");
Map<String, String> map = new HashMap<String, String>();
for (String param : params) {
String[] kvs= param.split("=");
if ( kvs.length>1)
map.put(kvs[0], kvs[1]);
}
return map;
}
This is my unit test:
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void JSON2MapTest() throws Exception {
exception.expect(NullPointerException.class);
exception.expectMessage("send null will occur NullPointerException");
JSONUtils.JSON2Map(null);
}
When I run the test, it throws:
java.lang.AssertionError:
Expected: (exception with message a string containing "send null will occur NullPointerException" and an instance of java.lang.NullPointerException)
got: java.lang.NullPointerException
if I comment //exception.expectMessage?(....), it will pass.
What is going on with exception.expectMessage?
source
share