W1Master { public void checkDeviceChanges() { final List<W1Device> refreshedDevices = new ArrayList<>(); final List<W1Device> removedDevices = new ArrayList<>(); refreshedDevices.addAll(readDevices()); for (final W1Device device : devices) { if (!refreshedDevices.contains(device)) { removedDevices.add(device); } } refreshedDevices.removeAll(devices); final int newCount = refreshedDevices.size(); final int removedCount = removedDevices.size(); if (newCount > 0) { log.fine("found " + newCount + " new device(s): " + refreshedDevices); } if (removedCount > 0) { log.fine("removed " + removedCount + " device(s): " + removedDevices); } devices.addAll(refreshedDevices); devices.removeAll(removedDevices); } W1Master();  W1Master(final ClassLoader classloader);  W1Master(final String masterDir);  W1Master(final String masterDir, final ClassLoader classloader); void checkDeviceChanges(); Collection<W1DeviceType> getDeviceTypes(); Map<String, W1DeviceType> getDeviceTypeMap(); List<String> getDeviceIDs(); List<W1Device> getDevices(); @SuppressWarnings("unchecked") List<T> getDevices(final int deviceFamilyId); @SuppressWarnings("unchecked") List<T> getDevices(final Class<T> type); @SuppressWarnings("unchecked") List<T> getW1Devices(final Class<T> type); @Override String toString();  }
@Test public void testCheckDeviceChanges() throws URISyntaxException { W1MasterDummy master = new W1MasterDummy(); assertEquals(0, master.getDevices().size()); final DummyDevice d1 = new DummyDevice("1"); final DummyDevice d2 = new DummyDevice("2"); master.setReadDevices(Arrays.<W1Device>asList(d1, d2)); assertEquals(0, master.getDevices().size()); master.checkDeviceChanges(); assertEquals(2, master.getDevices().size()); final DummyDevice d3 = new DummyDevice("3"); final DummyDevice d4 = new DummyDevice("4"); master.setReadDevices(Arrays.<W1Device>asList(d1, d3, d4)); master.checkDeviceChanges(); List<W1Device> devices = master.getDevices(); assertEquals(3, devices.size()); assertTrue(devices.contains(d1)); assertTrue(devices.contains(d3)); assertTrue(devices.contains(d4)); master.checkDeviceChanges(); assertEquals(3, master.getDevices().size()); master.setReadDevices(Collections.<W1Device>emptyList()); master.checkDeviceChanges(); assertEquals(0, master.getDevices().size()); }