ThingManagerImpl implements ThingManager, ThingTracker, ThingTypeMigrationService, ReadyService.ReadyTracker { @Override public void setEnabled(ThingUID thingUID, boolean enabled) { Thing thing = getThing(thingUID); persistThingEnableStatus(thingUID, enabled); if (thing == null) { logger.debug("Thing with the UID {} is unknown, cannot set its enabled status.", thingUID); return; } if (enabled) { if (thing.isEnabled()) { logger.debug("Thing {} is already enabled.", thingUID); return; } logger.debug("Thing {} will be enabled.", thingUID); if (isHandlerRegistered(thing)) { initializeHandler(thing); } else { registerAndInitializeHandler(thing, findThingHandlerFactory(thing.getThingTypeUID())); if (!hasBridge(thing) && !isHandlerRegistered(thing)) { setThingStatus(thing, buildStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_MISSING_ERROR)); } } } else { if (!thing.isEnabled()) { logger.debug("Thing {} is already disabled.", thingUID); return; } logger.debug("Thing {} will be disabled.", thingUID); boolean disposed = false; if (isHandlerRegistered(thing)) { ThingHandler thingHandler = thing.getHandler(); ThingHandlerFactory thingHandlerFactory = findThingHandlerFactory(thing.getThingTypeUID()); if (thingHandler != null && thingHandlerFactory != null) { unregisterAndDisposeHandler(thingHandlerFactory, thing, thingHandler); disposed = true; } } if (!disposed) { setThingStatus(thing, buildStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.DISABLED)); } if (isBridge(thing)) { updateChildThingStatusForDisabledBridges((Bridge) thing); } } } @Activate  ThingManagerImpl( //
            final @Reference BundleResolver bundleResolver,
            final @Reference ChannelGroupTypeRegistry channelGroupTypeRegistry,
            final @Reference ChannelTypeRegistry channelTypeRegistry,
            final @Reference CommunicationManager communicationManager,
            final @Reference ConfigDescriptionRegistry configDescriptionRegistry,
            final @Reference ConfigDescriptionValidator configDescriptionValidator,
            final @Reference EventPublisher eventPublisher,
            final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry,
            final @Reference ReadyService readyService, //
            final @Reference SafeCaller safeCaller, //
            final @Reference StorageService storageService, //
            final @Reference ThingRegistry thingRegistry,
            final @Reference ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService,
            final @Reference ThingTypeRegistry thingTypeRegistry); @Override void migrateThingType(final Thing thing, final ThingTypeUID thingTypeUID,
            final @Nullable Configuration configuration); @Override void thingAdded(Thing thing, ThingTrackerEvent thingTrackerEvent); @Override void thingRemoving(Thing thing, ThingTrackerEvent thingTrackerEvent); @Override void thingRemoved(final Thing thing, ThingTrackerEvent thingTrackerEvent); @Override void thingUpdated(final Thing thing, ThingTrackerEvent thingTrackerEvent); @Override void onReadyMarkerAdded(ReadyMarker readyMarker); @Override void onReadyMarkerRemoved(ReadyMarker readyMarker); @Override void setEnabled(ThingUID thingUID, boolean enabled); @Override boolean isEnabled(ThingUID thingUID);  }
@Test public void setEnabledWithUnknownThingUID() throws Exception { ThingUID unknownUID = new ThingUID("someBundle", "someType", "someID"); when(storageServiceMock.getStorage(eq("thing_status_storage"), any(ClassLoader.class))).thenReturn(storageMock); ThingManagerImpl thingManager = createThingManager(); thingManager.setEnabled(unknownUID, true); verify(storageMock).remove(eq(unknownUID.getAsString())); thingManager.setEnabled(unknownUID, false); verify(storageMock).put(eq(unknownUID.getAsString()), eq("")); }