Hi ,
i am using jmockit for creating a test case
I am trying to mock a servlet and
1>I noticing that even though i have mocked Node class it is passing null value so how to set up node class with a particular path
In the code below i am using
@Mocked
private Node ne;
2>In servlet I have to ad a test case for finding value of a particular tag values in a set ,how to do that as servlet does not return vertical tag at the end of servlet it just return response and the method i am looking is a private method in the servlet . So just for this test case should I need to change the method to public is the right way
@RunWith(JMockit.class)
public class MyServletTest {
@tested
private MyServlet servlet;
@Injectable
SlingHttpServletRequest request;
@Injectable
SlingHttpServletResponse response;
private Set<String> verticalTagsSet;
@Mocked
private Node ne;
@Before
public void init() throws Exception {
servlet = new MyServlet();
//initMocks(null);
}
@test
public void testVerticalTagPath() throws Exception {
new Expectations() {
{
// ne.getPath();
// result= "/content/abc";
}};
verticalTagsSet=new HashSet<String>();
verticalTagsSet.add("content-tag:aa/bb/cc");
verticalTagsSet.add("content-tag:aa/bb/cc/dd");
Set<String> test= new HashSet<String>();
test.addAll(verticalTagsSet);
//servlet.doGet(request, response);
servlet.mapVerticalTags(ne,verticalTagsSet);
Assert.assertEquals(test,servlet.getVerticalTagsSet());
new Verifications() {
{
}};
}
Thanks