### Question:
OSMServerSourceController extends UrlServerSourceController { @Override protected boolean handleActivateSource(IDataSource source) { boolean pingSuccess = false; try (TaskActivity activity = TaskActivity.createActive(source.getName() + " is loading...")) { getToolbox().getUIRegistry().getMenuBarRegistry().addTaskActivity(activity); DataModelCategory category = XYZTileUtils.newLayersCategory(((UrlDataSource)source).getURL(), OSMUtil.PROVIDER); XYZServerInfo serverInfo = new XYZServerInfo(source.getName(), ((UrlDataSource)source).getURL()); XYZTileLayerInfo layerInfo = null; if (serverInfo.getServerUrl().contains("osm_tiles_pc")) { layerInfo = new XYZTileLayerInfo(OSMUtil.PROVIDER, source.getName(), Projection.EPSG_4326, 2, false, 2, serverInfo); } else { layerInfo = new XYZTileLayerInfo(OSMUtil.PROVIDER, source.getName(), Projection.EPSG_3857, 1, false, 5, serverInfo); } pingSuccess = new OSMTileEnvoy(getToolbox()).ping(category); if (pingSuccess) { getToolbox().getDataRegistry().addModels( new SimpleSessionOnlyCacheDeposit<>(category, XYZTileUtils.LAYERS_DESCRIPTOR, New.list(layerInfo))); } } return pingSuccess; }  @Override IDataSource createNewSource(String typeName);  }### Answer:
@Test @SuppressWarnings("unchecked") public void testHandleActivateSource() { EasyMockSupport support = new EasyMockSupport(); DataRegistry registry = createDataRegistry(support); Toolbox toolbox = createToolbox(support, registry); createTaskActivity(support, toolbox); try { createServerPing(support, toolbox, true); } catch (IOException | URISyntaxException e) { fail("Unexpected exception during simulated server ping mock setup"); } EasyMock.expect(toolbox.getDataRegistry()).andReturn(registry); EasyMock.expect(registry.addModels(EasyMock.isA(SimpleSessionOnlyCacheDeposit.class))).andAnswer(this::addModelAnswer); support.replayAll(); OSMServerSourceController controller = new OSMServerSourceController(); controller.open(toolbox, OSMPlugin.class); UrlDataSource source = new UrlDataSource("Open Street Map", OUR_SERVER); controller.handleActivateSource(source); support.verifyAll(); }
@Test public void testActivationWhileDisconnected() { EasyMockSupport support = new EasyMockSupport(); DataRegistry registry = createDataRegistry(support); Toolbox toolbox = createToolbox(support, registry); createTaskActivity(support, toolbox); try { createServerPing(support, toolbox, false); } catch (IOException | URISyntaxException e) { fail("Unexpected exception during simulated server ping mock setup"); } support.replayAll(); OSMServerSourceController controller = new OSMServerSourceController(); controller.open(toolbox, OSMPlugin.class); UrlDataSource source = new UrlDataSource("Open Street Map", OUR_SERVER); controller.handleActivateSource(source); support.verifyAll(); }