### Question:
NsclientMonitor extends AbstractServiceMonitor { public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { String reason = null; int serviceStatus = PollStatus.SERVICE_UNRESPONSIVE; NsclientPacket response = null; Double responseTime = null; NetworkInterface<InetAddress> iface = svc.getNetInterface(); ThreadCategory log = ThreadCategory.getInstance(getClass()); if (iface.getType() != NetworkInterface.TYPE_INET) { throw new NetworkInterfaceNotSupportedException( "Unsupported interface type, only TYPE_INET currently supported"); } String command = ParameterMap.getKeyedString( parameters, "command", NsclientManager.convertTypeToString(NsclientManager.CHECK_CLIENTVERSION)); int port = ParameterMap.getKeyedInteger(parameters, "port", NsclientManager.DEFAULT_PORT); String password = ParameterMap.getKeyedString(parameters, "password", NSClientAgentConfig.DEFAULT_PASSWORD); String params = ParameterMap.getKeyedString(parameters, "parameter", null); int critPerc = ParameterMap.getKeyedInteger(parameters, "criticalPercent", 0); int warnPerc = ParameterMap.getKeyedInteger(parameters, "warningPercent", 0); TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT); InetAddress ipv4Addr = (InetAddress) iface.getAddress(); for (tracker.reset(); tracker.shouldRetry() && serviceStatus != PollStatus.SERVICE_AVAILABLE; tracker.nextAttempt()) { try { tracker.startAttempt(); NsclientManager client = new NsclientManager(InetAddressUtils.str(ipv4Addr), port, password); client.setTimeout(tracker.getSoTimeout()); client.setPassword(password); client.init(); NsclientCheckParams clientParams = new NsclientCheckParams( critPerc, warnPerc, params); response = client.processCheckCommand( NsclientManager.convertStringToType(command), clientParams); responseTime = tracker.elapsedTimeInMillis(); if (response == null) { continue; } if (response.getResultCode() == NsclientPacket.RES_STATE_OK) { serviceStatus = PollStatus.SERVICE_AVAILABLE; reason = response.getResponse(); } else if (response.getResultCode() == NsclientPacket.RES_STATE_CRIT) { serviceStatus = PollStatus.SERVICE_UNAVAILABLE; reason = response.getResponse(); responseTime = null; } } catch (NsclientException e) { log.debug("Nsclient Poller received exception from client: " + e.getMessage()); reason = "NsclientException: " + e.getMessage(); } } return PollStatus.get(serviceStatus, reason, responseTime); }  PollStatus poll(MonitoredService svc, Map<String, Object> parameters);  }### Answer:
@Test public void testMonitorSuccess() throws Exception { startServer("None&1", "NSClient++ 0.3.8.75 2010-05-27"); NsclientMonitor monitor = new NsclientMonitor(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("port", getServer().getLocalPort()); PollStatus status = monitor.poll(createMonitoredService(), parameters); Assert.assertTrue(status.isAvailable()); stopServer(); }
@Test public void testMonitorFail() throws Exception { startServer("None&1", "ERROR: I don't know what you mean"); NsclientMonitor monitor = new NsclientMonitor(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("port", getServer().getLocalPort()); PollStatus status = monitor.poll(createMonitoredService(), parameters); Assert.assertFalse(status.isAvailable()); stopServer(); }