How Unit test an inner class's public method

M

mike

Hi,

I have the following inner class that I need to test since it is an
essential part of the functionality.
Any suggestions on how I can test the public visit method?

cheers,

//mike

private final class UpdateOperation implements IIterativeOperation {

public IStatus visit(IResource resource, int depth,
IProgressMonitor monitor) {
try {
monitor.beginTask("Updating " + resource.getFullPath(), 100);

// Sanity check - can't update something that is not part of
// clearcase
if (!hasRemote(resource)) {
return new Status(
IStatus.ERROR,
ID,
TeamException.NO_REMOTE_RESOURCE,
MessageFormat
..format(
"Resource \"{0}\" is not a ClearCase element!",
new Object[] { resource
..getFullPath().toString() }),
null);
}
IStatus result = OK_STATUS;
monitor.worked(40);
updateState(resource, IResource.DEPTH_INFINITE,
new SubProgressMonitor(monitor, 10));
return result;
} finally {
monitor.done();
}
}
}
 
B

blue indigo

Hi,

I have the following inner class that I need to test since it is an
essential part of the functionality.
Any suggestions on how I can test the public visit method?

You'll need an instance of the enclosing class, of course. It's probably
best to test the inner class as part of a test suite that also tests the
enclosing class.

For example, with a collection and iterator, the latter
implemented as an inner class, you might have the test suite first make
sure the collection can be instantiated, added to, retrieved from, and
then iterated. If the first three tests pass the iterator test failing
should be from the iterator itself having a problem. Of course if the
collection implements much of its functionality through its iterator (as a
linked list likely does) you will have to test the iterator earlier in the
suite.

In your case, you have something different from an iterator, and will have
to think for yourself to design an appropriate test suite for the
enclosing class and its inner classes.

If the inner class had a non-Object superclass you'd want to also test
that first; in this case, it doesn't, though it does implement an
interface.

P.S. your code lost all its indents somewhere along the line, making it
more difficult to read. I'd look into how this happened so as to avoid it
in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top