mardi 21 avril 2015

How to mock method calls of mock objects?

Consider this example

    resp.getWriter().write(Collections.singletonMap("path", file.getAbsolutePath()).toString());

where resp is HttpServletResponse and is mocked.

I am using JMock Mockery to mock these

My code looks like

   try {
          atLeast(1).of(resp).getWriter().write(String.valueOf(any(String.class)));
        } catch (IOException e) {
          e.printStackTrace();
        }
        will(returnValue("Hello"));

When I run this, I get

java.lang.NullPointerException

Which I believe is coming since getWriter() is not sending anything back

How do I handle this situation?

Aucun commentaire:

Enregistrer un commentaire