NamedUser extends AirshipComponent { public void setId(@Nullable @Size(max = MAX_NAMED_USER_ID_LENGTH) String namedUserId) { if (namedUserId != null && !isDataCollectionEnabled()) { Logger.debug("NamedUser - Data collection is disabled, ignoring named user association."); return; } String id = null; if (!UAStringUtil.isEmpty(namedUserId)) { id = namedUserId.trim(); if (UAStringUtil.isEmpty(id) || id.length() > MAX_NAMED_USER_ID_LENGTH) { Logger.error("Failed to set named user ID. The named user ID must be composed" + "of non-whitespace characters and be less than 129 characters in length."); return; } } synchronized (idLock) { if (!UAStringUtil.equals(getId(), id)) { preferenceDataStore.put(NAMED_USER_ID_KEY, id); updateChangeToken(); attributeRegistrar.setId(getId(), true); tagGroupRegistrar.setId(getId(), true); dispatchNamedUserUpdateJob(); if (id != null) { airshipChannel.updateRegistration(); } } else { Logger.debug("NamedUser - Skipping update. Named user ID trimmed already matches existing named user: %s", getId()); } } } NamedUser(@NonNull Context context, @NonNull PreferenceDataStore preferenceDataStore,
                     @NonNull AirshipRuntimeConfig runtimeConfig, @NonNull AirshipChannel airshipChannel); @VisibleForTesting  NamedUser(@NonNull Context context, @NonNull PreferenceDataStore preferenceDataStore,
              @NonNull AirshipChannel airshipChannel, @NonNull JobDispatcher dispatcher,
              @NonNull Clock clock, @NonNull NamedUserApiClient namedUserApiClient,
              @NonNull AttributeRegistrar attributeRegistrar, @NonNull TagGroupRegistrar tagGroupRegistrar); @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @AirshipComponentGroups.Group int getComponentGroup(); @Override @WorkerThread @JobInfo.JobResult @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) int onPerformJob(@NonNull UAirship airship, @NonNull JobInfo jobInfo); @NonNull @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) List<TagGroupsMutation> getPendingTagUpdates(); @NonNull @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) List<AttributeMutation> getPendingAttributeUpdates(); @Nullable String getId(); void forceUpdate(); void setId(@Nullable @Size(max = MAX_NAMED_USER_ID_LENGTH) String namedUserId); @NonNull TagGroupsEditor editTagGroups(); @NonNull AttributeEditor editAttributes(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void addTagGroupListener(@NonNull TagGroupListener listener); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void addAttributeListener(@NonNull AttributeListener listener);  }
@Test public void testIdsMatchNoUpdate() { namedUser.setId(fakeNamedUserId); clearInvocations(mockDispatcher); namedUser.setId(fakeNamedUserId); verifyZeroInteractions(mockDispatcher); }
@Test public void testChangingIdUpdatesChannelRegistration() { namedUser.setId("namedUserId"); verify(mockChannel).updateRegistration(); }