// create an image to be returned by the mock WMSSourceHelper
final byte[] fakeWMSResponse = createFakeSourceImage(tl);
// WMSSourceHelper that on makeRequest() returns always the saqme fake image
WMSSourceHelper mockSourceHelper = EasyMock.createMock(WMSSourceHelper.class);
final AtomicInteger wmsRequestsCounter = new AtomicInteger();
Capture<WMSMetaTile> wmsRequestsCapturer = new Capture<WMSMetaTile>() {
/**
* Override because setValue with anyTimes() resets the list of values
*/
@Override
public void setValue(WMSMetaTile o) {
wmsRequestsCounter.incrementAndGet();
}
};
Capture<Resource> resourceCapturer = new Capture<Resource>() {
@Override
public void setValue(Resource target) {
try {
target.transferFrom(Channels.newChannel(new ByteArrayInputStream(
fakeWMSResponse)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
mockSourceHelper.makeRequest(capture(wmsRequestsCapturer), capture(resourceCapturer));
mockSourceHelper.makeRequest(capture(wmsRequestsCapturer), capture(resourceCapturer));
mockSourceHelper.makeRequest(capture(wmsRequestsCapturer), capture(resourceCapturer));
mockSourceHelper.setConcurrency(32);
mockSourceHelper.setBackendTimeout(120);
replay(mockSourceHelper);
tl.setSourceHelper(mockSourceHelper);
final int zoomLevel = 4;