### Question:
StandardServiceAgent extends AbstractServiceAgent implements ServiceAgent { public static StandardServiceAgent newInstance(Settings settings) { UDPConnector.Factory udpFactory = Factories.newInstance(settings, UDP_CONNECTOR_FACTORY_KEY); TCPConnector.Factory tcpFactory = Factories.newInstance(settings, TCP_CONNECTOR_FACTORY_KEY); UDPConnectorServer.Factory udpServerFactory = Factories.newInstance(settings, UDP_CONNECTOR_SERVER_FACTORY_KEY); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); return new StandardServiceAgent(udpFactory.newUDPConnector(settings), tcpFactory.newTCPConnector(settings), udpServerFactory.newUDPConnectorServer(settings), scheduledExecutorService, settings); } StandardServiceAgent(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, ScheduledExecutorService scheduledExecutorService);  StandardServiceAgent(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, ScheduledExecutorService scheduledExecutorService, Settings settings); static StandardServiceAgent newInstance(Settings settings); boolean isPeriodicServiceRenewalEnabled(); void setPeriodicServiceRenewalEnabled(boolean periodicServiceRenewalEnabled); void register(ServiceInfo service); void addAttributes(ServiceURL serviceURL, String language, Attributes attributes); void removeAttributes(ServiceURL serviceURL, String language, Attributes attributes); void deregister(ServiceURL serviceURL, String language);  }### Answer:
@Test public void testStartStop() throws Exception { StandardServiceAgent sa = StandardServiceAgent.newInstance(newSettings()); assert !sa.isRunning(); sa.start(); assert sa.isRunning(); sa.stop(); assert !sa.isRunning(); }
@Test public void testListenForDirectoryAgents() throws Exception { StandardServiceAgent sa = StandardServiceAgent.newInstance(newSettings()); sa.start(); assert sa.getDirectoryAgents().size() == 0; try { StandardDirectoryAgentServer da = StandardDirectoryAgentServer.newInstance(newSettings()); da.start(); try { Thread.sleep(500); assert sa.getDirectoryAgents().size() == 1; } finally { da.stop(); } } finally { sa.stop(); } }
@Test public void testDADiscoveryOnStartup() throws Exception { StandardDirectoryAgentServer da = StandardDirectoryAgentServer.newInstance(newSettings()); da.start(); try { StandardServiceAgent sa = StandardServiceAgent.newInstance(newSettings()); sa.start(); try { List<DirectoryAgentInfo> das = sa.getDirectoryAgents(); assert das != null; assert das.size() == 1; } finally { sa.stop(); } } finally { da.stop(); } }