### Question:
Predicates { public static boolean isDeviceOffline(Model m, boolean hubOffline) { if(m == null) { return false; } if(!m.supports(DeviceConnectionCapability.NAMESPACE)) { return false; } if(hubOffline && isHubRequired(m)) { return true; } return Objects.equals(DeviceConnectionCapability.STATE_OFFLINE, DeviceConnectionModel.getState(m, DeviceConnectionCapability.STATE_ONLINE)); } private  Predicates(); static boolean isSupportedModel(Model m, boolean whitelisted, @Nullable ProductCatalogEntry pm); static boolean isHubOffline(Model m); static boolean isHubRequired(Model m); static boolean isDeviceOffline(Model m, boolean hubOffline);  }### Answer:
@Test public void testDeviceOfflineHubOnline() { assertFalse(Predicates.isDeviceOffline(null, false)); assertFalse(Predicates.isDeviceOffline(new SimpleModel(ModelFixtures.createPersonAttributes()), false)); Model m = ModelFixtures.buildDeviceAttributes(SwitchCapability.NAMESPACE).put(DeviceConnectionCapability.ATTR_STATE, DeviceConnectionCapability.STATE_ONLINE).toModel(); assertFalse(Predicates.isDeviceOffline(m, false)); m = ModelFixtures.buildDeviceAttributes(SwitchCapability.NAMESPACE).put(DeviceConnectionCapability.ATTR_STATE, DeviceConnectionCapability.STATE_OFFLINE).toModel(); assertTrue(Predicates.isDeviceOffline(m, false)); }
@Test public void testDeviceOfflineHubOffline() { assertFalse(Predicates.isDeviceOffline(null, true)); assertFalse(Predicates.isDeviceOffline(new SimpleModel(ModelFixtures.createPersonAttributes()), true)); Model m = ModelFixtures.buildDeviceAttributes(SwitchCapability.NAMESPACE) .put(DeviceConnectionCapability.ATTR_STATE, DeviceConnectionCapability.STATE_ONLINE) .put(DeviceAdvancedCapability.ATTR_PROTOCOL, Constants.Protocol.ZIGBEE) .toModel(); assertTrue(Predicates.isDeviceOffline(m,true )); m = ModelFixtures.buildDeviceAttributes(SwitchCapability.NAMESPACE) .put(DeviceConnectionCapability.ATTR_STATE, DeviceConnectionCapability.STATE_ONLINE) .put(DeviceAdvancedCapability.ATTR_PROTOCOL, "IPCD") .toModel(); assertFalse(Predicates.isDeviceOffline(m,true )); m = ModelFixtures.buildDeviceAttributes(SwitchCapability.NAMESPACE) .put(DeviceConnectionCapability.ATTR_STATE, DeviceConnectionCapability.STATE_OFFLINE) .put(DeviceAdvancedCapability.ATTR_PROTOCOL, "IPCD") .toModel(); assertTrue(Predicates.isDeviceOffline(m,true )); }