RequestSecurityManager securityManager = mockRequestSecurityManager();
Request request = mockRequest();
Response response = mockResponse();
ComponentInvocationMap invocationMap = new NoOpComponentInvocationMap();
RequestPathOptimizer optimizer = mockRequestPathOptimizer();
Capture<Link> linkCapture = new Capture();
LinkFactoryListener listener = mockLinkFactoryListener();
String optimizedURL = "optimized:" + expectedURL;
String encodedURL = "encoded:" + expectedURL;
train_getRenderingPage(queue, null);
train_getLogicalName(primaryPage, logicalName);
train_collectPageActivationContext(collector, primaryPage, "a", "b");
train_getBaseURL(securityManager, activePage, null);
train_getContextPath(request, "/context");
train_optimizePath(optimizer, expectedURL, optimizedURL);
train_encodeURL(response, optimizedURL, encodedURL);
listener.createdComponentEventLink(capture(linkCapture));
replay();
LinkFactory factory = new LinkFactoryImpl(request, response, invocationMap, null, optimizer, queue,
securityManager, contextPathEncoder, collector);
factory.addListener(listener);
Link link = factory.createComponentEventLink(primaryPage, nestedId, eventType, forForm, context);
// Make sure the same link is returned.
assertSame(linkCapture.getValue(), link);
assertEquals(link.toURI(), encodedURL);
verify();