I have the following code:
public void someMethod() {
Set<Foo> fooSet = bar.getFoos();
for(Foo foo: fooSet) {
foo.doSomething();
}
}
and I want to test this using JMockit but am unsure how to get to return a collection of a certain type and size.
The following test for my code throws a null pointer exception for hashcode when trying to add foo to the set of foos.
@Test
public void someTestMethod()
{
new Expectations()
{
@Mocked Bar bar;
@Mocked Foo foo;
Set<Foo> foos = new HashSet<Foo>();
foos.add(foo);
bar.getFoos(); returns(foos);
foo.doSomething();
};
new SomeClass().someMethod();
}
How should this be done?