### Question:
SnmpSender extends AlertSender { @Override public SenderResult send(Alert alert) { SnmpInfo info = SnmpInfo.load(alertParameters, preferences); if (info.error != null) { return SenderResult.getSimpleFailure(info.error); } if (LOG.isDebugEnabled()) { LOG.debug("Sending SNMP trap to: " + info); } try { SnmpTrapSender snmpTrapSender = new SnmpTrapSender(preferences); List<Resource> lineage = resourceManager.getResourceLineage(alert.getAlertDefinition().getResource() .getId()); String platformName = lineage.get(0).getName(); String conditions = alertManager.prettyPrintAlertConditions(alert, false); String alertUrl = alertManager.prettyPrintAlertURL(alert); String hierarchy = getResourceHierarchyAsString(lineage); Date bootTime = new Date(); String result = snmpTrapSender.sendSnmpTrap(alert, alertParameters, platformName, conditions, bootTime, alertUrl, hierarchy); return SenderResult.getSimpleSuccess(result); } catch (Throwable t) { LOG.error("Could not send SNMP trap to " + info, t); return SenderResult.getSimpleFailure("failed - cause: " + t); } } SnmpSender();  SnmpSender(ResourceManagerLocal resourceManager, AlertManagerLocal alertManager); @Override SenderResult send(Alert alert); @Override String previewConfiguration();  }### Answer:
@Test public void shouldReturnSimpleFailureForInvalidNotificationParameters() { Configuration alertParameters = new Configuration(); snmpSender.setAlertParameters(alertParameters); SenderResult result = snmpSender.send(createAlertForResourceWithId(13004, "", "", HIGH)); assertNotNull(result); assertEquals(result.getState(), FAILURE); assertEquals(result.getFailureMessages().size(), 1); String expectedError = SnmpInfo.load(alertParameters,pluginConfiguration).error; assertNotNull(expectedError); assertEquals(result.getFailureMessages().get(0), expectedError); }
@Test public void shouldReturnSimpleFailureWhenErrorOccurs() { Configuration alertParameters = new Configuration(); alertParameters.setSimpleValue(PARAM_HOST, TEST_HOST); alertParameters.setSimpleValue(PARAM_VARIABLE_BINDING_PREFIX, TEST_VARIABLE_BINDING_PREFIX); alertParameters.setSimpleValue(PARAM_PORT, String.valueOf(getTestPort())); snmpSender.setAlertParameters(alertParameters); int resourceId = 13004; Alert alert = createAlertForResourceWithId(resourceId, "", "", HIGH); String exceptionMessage = "Test Error"; when(resourceManager.getResourceLineage(eq(resourceId))).thenThrow(new RuntimeException(exceptionMessage)); SenderResult result = snmpSender.send(alert); assertNotNull(result); assertEquals(result.getState(), FAILURE); assertEquals(result.getFailureMessages().size(), 1); String actualErrorMessage = result.getFailureMessages().get(0); assertTrue(actualErrorMessage.endsWith(exceptionMessage), "Unexpected error message: " + actualErrorMessage); }