I have below method which i want to test using EasyMock.
public String createNode(Session session, String name) throws RepositoryException {
Node root = session.getRootNode();
Node testNode = root.getNode( "content" );
if( !testNode.hasNode(name) ) {
testNode.addNode( name, "nt:unstructured" );
}
return testNode.getPath()+"/"+name;
}
And test method is :
@Test
public void createNodeTest() throws RepositoryException {
final Session SESSION_MOCK = EasyMock.createNiceMock((Session.class));
final Node ROOT_NODE_MOCK = EasyMock.createNiceMock(Node.class);
final Node CONTENT_NODE_MOCK = EasyMock.createNiceMock(Node.class);
final Node CHILD_NODE_MOCK = EasyMock.createNiceMock(Node.class);
EasyMock.expect(SESSION_MOCK.getRootNode()).andReturn(ROOT_NODE_MOCK);
EasyMock.expect(ROOT_NODE_MOCK.getNode("content")).andReturn(CONTENT_NODE_MOCK);
EasyMock.expect(CONTENT_NODE_MOCK.hasNode("viv")).andReturn(false);
EasyMock.expect(CONTENT_NODE_MOCK.addNode("viv","nt:unstructured")).andReturn(CHILD_NODE_MOCK);
EasyMock.expect(CHILD_NODE_MOCK.getPath()).andReturn("/content/viv");
EasyMock.replay(SESSION_MOCK,ROOT_NODE_MOCK,CONTENT_NODE_MOCK);
TestableClass tc = new TestableClass();
assertEquals("/content/viv", tc.createNode(SESSION_MOCK,"viv"));
EasyMock.verify(SESSION_MOCK,CONTENT_NODE_MOCK,ROOT_NODE_MOCK);
}
Getting failure :
org.junit.ComparisonFailure: expected:<[/content]/viv> but was:<[null]/viv>
Anyone can tell where i am wrong, i want to get the test pass. Thanks