You can't have multiple instances of the same MockUp
subclass at the same time (each such mock-up would simply override the previous one when it got instantiated). Instead, add an Invocation
parameter to your @Mock
method, and then use the information it provides to distinguish between multiple data sets. For example:
@Test
public void testClientWithVariedDataFromFastScanners()
{
new MockUp<FastScanner>() {
// some data structure for test data
@Mock
int nextInt(Invocation inv) {
int idx = inv.getInvocationIndex();
FastScanner fs = inv.getInvokedInstance();
// Find the next value by using idx or fs as a lookup index
// into the data structures:
int i = ...
return i;
}
};
client.doSomethingUsingFastScanners();
}
Also, if you want to call whatever methods (including static
methods) on a mock-up subclass, just make it a named class rather than an anonymous one.