### Question:
EnergyModellerQueueController implements InitializingBean { public static String generateKey(EnergyModellerMessage emMessage) { if(emMessage != null) { return generateKey(emMessage.getApplicationid(), emMessage.getEventid(), emMessage.getDeploymentid(), emMessage.getVms(), emMessage.getUnit()); } else { return null; } } EnergyModellerQueueController(); @Override void afterPropertiesSet(); void addMessage(EnergyModellerMessage emMessage, String type); EnergyModellerMessage getMeasurementMessage(String key); EnergyModellerMessage getPredictionMessage(String key); static Map<K, V> createLRUMap(final int maxEntries); static String generateKey(EnergyModellerMessage emMessage); static String generateKey(String applicationId, String eventId, String deploymentId, List<String> vmsId, String unit); static final String WATT; static final String WATTHOUR; static final String COUNT; static final String SEC; static final String APP_DURATION; static final String APP_COUNT; static final String MEASUREMENTS; static final String PREDICTIONS; }### Answer:
@Test public void generateKeyByParametersTest() { String applicationId = "appID"; String eventId = "eventId"; String deploymentId = "deploymentId"; String vm1 = "vm1"; String vm2 = "vm2"; String unit = "unit"; List<String> vms = new ArrayList<String>(); vms.add(vm1); vms.add(vm2); String key = EnergyModellerQueueController.generateKey(applicationId, eventId, deploymentId, vms, unit); assertEquals(applicationId + eventId + deploymentId + vm1 + vm2 + unit, key); key = EnergyModellerQueueController.generateKey(applicationId, eventId, deploymentId, null, unit); assertEquals(applicationId + eventId + deploymentId + unit, key); }
@Test public void generateKeyWithObjectTest() { EnergyModellerMessage emMessage = new EnergyModellerMessage(); emMessage.setApplicationid("appID"); emMessage.setEventid("eventId"); emMessage.setDeploymentid("deploymentId"); emMessage.setUnit("unit"); emMessage.setProvider("provider"); emMessage.setValue("0.0"); emMessage.setGenerattiontimestamp("generation"); emMessage.setReferredtimestamp("referal"); String vm1 = "vm1"; String vm2 = "vm2"; List<String> vms = new ArrayList<String>(); vms.add(vm1); vms.add(vm2); emMessage.setVms(vms); String key = EnergyModellerQueueController.generateKey(emMessage); assertEquals("appID" + "eventId" + "deploymentId" + "vm1" + "vm2" + "unit", key); emMessage.setVms(null); key = EnergyModellerQueueController.generateKey(emMessage); assertEquals("appID" + "eventId" + "deploymentId" + "unit", key); }