UserIdContext { public static boolean checkUserIdValidForOneCollector(String userId) { if (userId == null) { return true; } if (userId.isEmpty()) { AppCenterLog.error(LOG_TAG, "userId must not be empty."); return false; } int prefixIndex = userId.indexOf(COMMON_SCHEMA_PREFIX_SEPARATOR); if (prefixIndex >= 0) { String prefix = userId.substring(0, prefixIndex); if (!prefix.equals(CUSTOM_PREFIX)) { AppCenterLog.error(LOG_TAG, String.format("userId prefix must be '%s%s', '%s%s' is not supported.", CUSTOM_PREFIX, COMMON_SCHEMA_PREFIX_SEPARATOR, prefix, COMMON_SCHEMA_PREFIX_SEPARATOR)); return false; } else if (prefixIndex == userId.length() - 1) { AppCenterLog.error(LOG_TAG, "userId must not be empty."); return false; } } return true; }  static synchronized UserIdContext getInstance(); @VisibleForTesting static synchronized void unsetInstance(); static boolean checkUserIdValidForOneCollector(String userId); static boolean checkUserIdValidForAppCenter(String userId); static String getPrefixedUserId(String userId); void addListener(@NonNull Listener listener); void removeListener(@NonNull Listener listener); synchronized String getUserId(); void setUserId(String userId); @VisibleForTesting
    static final int USER_ID_APP_CENTER_MAX_LENGTH; }
@Test public void userIdInvalidForOneCollector() { assertFalse(UserIdContext.checkUserIdValidForOneCollector("")); assertFalse(UserIdContext.checkUserIdValidForOneCollector(":alice")); assertFalse(UserIdContext.checkUserIdValidForOneCollector("c:")); assertFalse(UserIdContext.checkUserIdValidForOneCollector("x:")); assertFalse(UserIdContext.checkUserIdValidForOneCollector("x:alice")); }
@Test public void userIdValidForOneCollector() { assertTrue(UserIdContext.checkUserIdValidForOneCollector(null)); assertTrue(UserIdContext.checkUserIdValidForOneCollector("c:alice")); assertTrue(UserIdContext.checkUserIdValidForOneCollector("alice")); }