@Test public void testUnReserveWithValidDevice() { MongoTemplate mockMongoTemplate = EasyMock.createMock(MongoTemplate.class); PersistableDevice persistableDev = EasyMock.createMock(PersistableDevice.class); DawgPoundMongoService dawgPoundService = new DawgPoundMongoService(); ReflectionTestUtils.setField(dawgPoundService, "mongoTemplate", mockMongoTemplate); EasyMock.expect(mockMongoTemplate.findById(TestConstants.DEVICE_ID, PersistableDevice.class, TestConstants.COLLECTION_NAME )).andReturn(persistableDev); EasyMock.expect(persistableDev.unreserve()).andReturn(TestConstants.TOKEN); mockMongoTemplate.save(persistableDev, TestConstants.COLLECTION_NAME); EasyMock.replay(mockMongoTemplate, persistableDev); Assert.assertEquals(dawgPoundService.unreserve(TestConstants.DEVICE_ID), TestConstants.TOKEN); EasyMock.verify(mockMongoTemplate, persistableDev); }
@Override public synchronized String unreserve(String id) { PersistableDevice device = getById(id); if (null == device) { LOGGER.info("Attempted to unreserve a non-existing device. deviceId="+id); return null; } else { String previous = device.unreserve(); mongoTemplate.save(device,COLLECTION_NAME); LOGGER.info("Device unreserved. deviceId=" + id + ", previous reserver="+previous); return previous; } }
DawgPoundMongoService implements IDawgPoundService { @Override public synchronized String unreserve(String id) { PersistableDevice device = getById(id); if (null == device) { LOGGER.info("Attempted to unreserve a non-existing device. deviceId="+id); return null; } else { String previous = device.unreserve(); mongoTemplate.save(device,COLLECTION_NAME); LOGGER.info("Device unreserved. deviceId=" + id + ", previous reserver="+previous); return previous; } } }
DawgPoundMongoService implements IDawgPoundService { @Override public synchronized String unreserve(String id) { PersistableDevice device = getById(id); if (null == device) { LOGGER.info("Attempted to unreserve a non-existing device. deviceId="+id); return null; } else { String previous = device.unreserve(); mongoTemplate.save(device,COLLECTION_NAME); LOGGER.info("Device unreserved. deviceId=" + id + ", previous reserver="+previous); return previous; } }  }
DawgPoundMongoService implements IDawgPoundService { @Override public synchronized String unreserve(String id) { PersistableDevice device = getById(id); if (null == device) { LOGGER.info("Attempted to unreserve a non-existing device. deviceId="+id); return null; } else { String previous = device.unreserve(); mongoTemplate.save(device,COLLECTION_NAME); LOGGER.info("Device unreserved. deviceId=" + id + ", previous reserver="+previous); return previous; } }  @PostConstruct void init(); @Override synchronized String unreserve(String id); @Override synchronized boolean overrideReserve(String id, String token, long expiration); @SuppressWarnings("unchecked") @Override Map<String,Object>[] getByReserver(String token); @Override synchronized String reserve(String id, String token, long expiration); @Override PersistableDevice getById(String id); @Override Map<String, String> isReserved(String id); @SuppressWarnings("unchecked") Map<String,Object>[] list(); }
DawgPoundMongoService implements IDawgPoundService { @Override public synchronized String unreserve(String id) { PersistableDevice device = getById(id); if (null == device) { LOGGER.info("Attempted to unreserve a non-existing device. deviceId="+id); return null; } else { String previous = device.unreserve(); mongoTemplate.save(device,COLLECTION_NAME); LOGGER.info("Device unreserved. deviceId=" + id + ", previous reserver="+previous); return previous; } }  @PostConstruct void init(); @Override synchronized String unreserve(String id); @Override synchronized boolean overrideReserve(String id, String token, long expiration); @SuppressWarnings("unchecked") @Override Map<String,Object>[] getByReserver(String token); @Override synchronized String reserve(String id, String token, long expiration); @Override PersistableDevice getById(String id); @Override Map<String, String> isReserved(String id); @SuppressWarnings("unchecked") Map<String,Object>[] list();  }