SNMPImpl implements SnmpService, AutoCloseable { @Override public ListenableFuture<RpcResult<SnmpSetOutput>> snmpSet(SnmpSetInput input) { return new AsyncSetHandler(input, snmp).getRpcResponse(); } SNMPImpl();   SNMPImpl(Snmp snmp); @Override ListenableFuture<RpcResult<SnmpGetOutput>> snmpGet(SnmpGetInput input); @Override ListenableFuture<RpcResult<SnmpSetOutput>> snmpSet(SnmpSetInput input); @Override ListenableFuture<RpcResult<GetInterfacesOutput>> getInterfaces(final GetInterfacesInput getInterfacesInput); @Override void close(); @Override @SuppressWarnings("checkstyle:IllegalCatch") ListenableFuture<RpcResult<GetNodePropertiesOutput>> getNodeProperties(final GetNodePropertiesInput input);  }
@Test public void testSet() throws IOException, InterruptedException, ExecutionException { final ResponseEvent event = createResponseEvent(); doAnswer(invocation -> { ResponseListener callback = (ResponseListener) invocation.getArguments()[3]; callback.onResponse(event); return null; }).when(mockSnmp).set(argThat(argument -> { if (argument instanceof PDU) { PDU pdu = (PDU) argument; assertEquals("Checking SET PDU type", pdu.getType(), PDU.SET); assertEquals("Checking Value of SET", pdu.getVariableBindings().get(0).toValueString(), VALUE); assertEquals("Checking OID of SET", pdu.getVariableBindings().get(0).getOid().toString(), LOCATION_OID); return true; } return false; }), argThat(argument -> { if (argument instanceof Target) { Target target = (Target) argument; assertEquals("Checking community of SET", target.getSecurityName().toString(), COMMUNITY); assertEquals("Checking target IP", target.getAddress().toString(), SET_IP_ADDRESS + "/" + SNMP_LISTEN_PORT.toString()); assertEquals("Checking timeout", target.getTimeout(), TIMEOUT); assertEquals("Checking retries", target.getRetries(), RETRIES); assertEquals("Checking version", target.getVersion(), SnmpConstants.version2c); return true; } return false; }), any(), (ResponseListener) any()); Ipv4Address ip = new Ipv4Address(SET_IP_ADDRESS); SnmpSetInputBuilder input = new SnmpSetInputBuilder(); input.setCommunity(COMMUNITY); input.setIpAddress(ip); input.setOid(LOCATION_OID); input.setValue(VALUE); RpcResult<SnmpSetOutput> result = snmpImpl.snmpSet(input.build()).get(); assertTrue(result.isSuccessful()); }