@Test public void testIsReservedWithDeviceNotReserved() { 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.isReserved()).andReturn(false); EasyMock.replay(mockMongoTemplate,persistableDev); Assert.assertNull(dawgPoundService.isReserved(TestConstants.DEVICE_ID)); EasyMock.verify(mockMongoTemplate,persistableDev); }
@Override public Map<String, String> isReserved(String id) { PersistableDevice device = getById(id); if(null != device && device.isReserved()) { Map<String, String> map = new HashMap<String, String>(); map.put("reserver", device.getReserver()); map.put("expiration", String.valueOf(device.getExpiration())); return map; } else { return null; } }
DawgPoundMongoService implements IDawgPoundService { @Override public Map<String, String> isReserved(String id) { PersistableDevice device = getById(id); if(null != device && device.isReserved()) { Map<String, String> map = new HashMap<String, String>(); map.put("reserver", device.getReserver()); map.put("expiration", String.valueOf(device.getExpiration())); return map; } else { return null; } } }
DawgPoundMongoService implements IDawgPoundService { @Override public Map<String, String> isReserved(String id) { PersistableDevice device = getById(id); if(null != device && device.isReserved()) { Map<String, String> map = new HashMap<String, String>(); map.put("reserver", device.getReserver()); map.put("expiration", String.valueOf(device.getExpiration())); return map; } else { return null; } }  }
DawgPoundMongoService implements IDawgPoundService { @Override public Map<String, String> isReserved(String id) { PersistableDevice device = getById(id); if(null != device && device.isReserved()) { Map<String, String> map = new HashMap<String, String>(); map.put("reserver", device.getReserver()); map.put("expiration", String.valueOf(device.getExpiration())); return map; } else { return null; } }  @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 Map<String, String> isReserved(String id) { PersistableDevice device = getById(id); if(null != device && device.isReserved()) { Map<String, String> map = new HashMap<String, String>(); map.put("reserver", device.getReserver()); map.put("expiration", String.valueOf(device.getExpiration())); return map; } else { return null; } }  @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();  }