Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Testing
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Testing
Iterator in EasyMock
vivek dhiman
Ranch Hand
Posts: 157
I like...
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
I have the below function which i want to
test
.
public String createNode(Session session, String name) throws RepositoryException { Node root = session.getRootNode(); Node testNode = root.getNode("content"); NodeIterator nodeIterator = testNode.getNodes(); [b]while (nodeIterator.hasNext()) { Node temp = (Node) nodeIterator.next(); if (temp.getName().equals(name)) { break; } }[/b] testNode.addNode(name, "nt:unstructured"); return testNode.getPath()+"/"+name; }
TestCase so far i written is :
@Test public void createNode() throws RepositoryException { final Session SESSION_MOCK = EasyMock.createNiceMock((Session.class)); final Node ROOT_NODE_MOCK = EasyMock.createNiceMock(Node.class); EasyMock.expect(SESSION_MOCK.getRootNode()).andReturn(ROOT_NODE_MOCK); final Node CONTENT_NODE_MOCK = EasyMock.createNiceMock(Node.class); EasyMock.expect(ROOT_NODE_MOCK.getNode("content")).andReturn(CONTENT_NODE_MOCK); EasyMock.replay(SESSION_MOCK,ROOT_NODE_MOCK,CONTENT_NODE_MOCK); TestableClass tc = new TestableClass(); assertEquals("/content/viv", tc.createNode(SESSION_MOCK, "viv")); }
I am not sure how to proceed with iterator in testcase. Can someone provide the snippet how to use this.
Thanks
Tim Cooke
Sheriff
Posts: 5555
326
I like...
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The while loop serves no purpose in that method at all. What do you want to assert?
The use of EasyMock makes your test code look really unpleasant. It might be easier to construct a real Session object instead.
Tim Driven Development
| Test until the fear goes away
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
ClassCastException while reading ics file with ical4j in JackRabit
How to write Junit for only for get method
expectLastCall().atLeastOnce() what is the use.
addThrows : How to fail
More...