@Test public void testListAllDevices() { MongoTemplate mockMongoTemplate = EasyMock.createMock(MongoTemplate.class); DawgPoundMongoService dawgPoundService = new DawgPoundMongoService(); ReflectionTestUtils.setField(dawgPoundService, "mongoTemplate", mockMongoTemplate); List<PersistableDevice> devices = new ArrayList<PersistableDevice>(); PersistableDevice device1 = EasyMock.createMock(PersistableDevice.class); PersistableDevice device2 = EasyMock.createMock(PersistableDevice.class); Map<String,Object> dev1Map = new HashMap<String,Object>(); Map<String,Object> dev2Map = new HashMap<String,Object>(); devices.add(device1); devices.add(device2); dev1Map.put("id", TestConstants.DEVICE_ID); dev2Map.put("id", "000000682A48"); EasyMock.expect(mockMongoTemplate.findAll(PersistableDevice.class, TestConstants.COLLECTION_NAME )).andReturn(devices); EasyMock.expect(device1.getData()).andReturn(dev1Map); EasyMock.expect(device2.getData()).andReturn(dev2Map); EasyMock.replay(mockMongoTemplate, device1, device2); Map<String,Object>[] list = dawgPoundService.list(); Assert.assertEquals(list.length, 2); Assert.assertEquals(list[0].get("id"), TestConstants.DEVICE_ID); Assert.assertEquals(list[1].get("id"), "000000682A48"); EasyMock.verify(mockMongoTemplate, device1, device2); }
@SuppressWarnings("unchecked") public Map<String,Object>[] list() { List<Map<String,Object>> list = new ArrayList<Map<String,Object>>(); Collection<? extends DawgDevice> col = mongoTemplate.findAll(PersistableDevice.class, COLLECTION_NAME); for(DawgDevice device : col) { list.add(device.getData()); } return list.toArray(new Map[list.size()]); }
DawgPoundMongoService implements IDawgPoundService { @SuppressWarnings("unchecked") public Map<String,Object>[] list() { List<Map<String,Object>> list = new ArrayList<Map<String,Object>>(); Collection<? extends DawgDevice> col = mongoTemplate.findAll(PersistableDevice.class, COLLECTION_NAME); for(DawgDevice device : col) { list.add(device.getData()); } return list.toArray(new Map[list.size()]); } }
DawgPoundMongoService implements IDawgPoundService { @SuppressWarnings("unchecked") public Map<String,Object>[] list() { List<Map<String,Object>> list = new ArrayList<Map<String,Object>>(); Collection<? extends DawgDevice> col = mongoTemplate.findAll(PersistableDevice.class, COLLECTION_NAME); for(DawgDevice device : col) { list.add(device.getData()); } return list.toArray(new Map[list.size()]); }  }
DawgPoundMongoService implements IDawgPoundService { @SuppressWarnings("unchecked") public Map<String,Object>[] list() { List<Map<String,Object>> list = new ArrayList<Map<String,Object>>(); Collection<? extends DawgDevice> col = mongoTemplate.findAll(PersistableDevice.class, COLLECTION_NAME); for(DawgDevice device : col) { list.add(device.getData()); } return list.toArray(new Map[list.size()]); }  @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 { @SuppressWarnings("unchecked") public Map<String,Object>[] list() { List<Map<String,Object>> list = new ArrayList<Map<String,Object>>(); Collection<? extends DawgDevice> col = mongoTemplate.findAll(PersistableDevice.class, COLLECTION_NAME); for(DawgDevice device : col) { list.add(device.getData()); } return list.toArray(new Map[list.size()]); }  @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();  }