IdentityApi { public boolean aliasUsers(@NonNull AliasRequest aliasRequest) { if (aliasRequest.getDestinationMpid() == 0 || aliasRequest.getSourceMpid() == 0) { Logger.error("AliasRequest does not have a valid destinationMpid and a valid sourceMpid"); return false; } if (aliasRequest.getDestinationMpid() == aliasRequest.getSourceMpid()) { Logger.error("AliasRequest cannot have the same value for destinationMpid and sourceMpid"); return false; } if (aliasRequest.getEndTime() == 0 || aliasRequest.getStartTime() == 0) { Logger.error("AliasRequest must have both a startTime and an endTime"); return false; } if (aliasRequest.getEndTime() < aliasRequest.getStartTime()) { Logger.error("AliasRequest cannot have an startTime that is greater than its endTime"); return false; } mMessageManager.logAliasRequest(aliasRequest); return true; } protected  IdentityApi(); @SuppressLint("UnknownNullness")  IdentityApi(Context context, AppStateManager appStateManager, MessageManager messageManager, ConfigManager configManager, KitManager kitManager, MParticle.OperatingSystem operatingSystem); @Nullable MParticleUser getCurrentUser(); @Nullable MParticleUser getUser(@NonNull Long mpid); @NonNull List<MParticleUser> getUsers(); @NonNull String getDeviceApplicationStamp(); void addIdentityStateListener(@NonNull IdentityStateListener listener); void removeIdentityStateListener(@NonNull IdentityStateListener listener); @NonNull MParticleTask<IdentityApiResult> logout(); @NonNull MParticleTask<IdentityApiResult> logout(@Nullable final IdentityApiRequest logoutRequest); @NonNull MParticleTask<IdentityApiResult> login(); @NonNull MParticleTask<IdentityApiResult> login(@Nullable final IdentityApiRequest loginRequest); @NonNull MParticleTask<IdentityApiResult> identify(@Nullable final IdentityApiRequest identifyRequest); @NonNull BaseIdentityTask modify(@NonNull final IdentityApiRequest updateRequest); boolean aliasUsers(@NonNull AliasRequest aliasRequest); @NonNull Internal Internal(); static int UNKNOWN_ERROR; static int THROTTLE_ERROR; static int BAD_REQUEST; static int SERVER_ERROR; }
@Test public void testAliasUsersValidationRejection() { IdentityApi identityApi = new IdentityApi(); identityApi.mMessageManager = new MessageManager() { @Override public void logAliasRequest(AliasRequest aliasRequest) { fail("should not logged Alias Request:\n" + aliasRequest.toString()); } }; AliasRequest request = AliasRequest.builder() .destinationMpid(123) .startTime(1) .endTime(2) .build(); assertFalse(identityApi.aliasUsers(request)); request = AliasRequest.builder() .sourceMpid(123) .startTime(1) .endTime(2) .build(); assertFalse(identityApi.aliasUsers(request)); request = AliasRequest.builder() .destinationMpid(123) .sourceMpid(123) .startTime(1) .endTime(2) .build(); assertFalse(identityApi.aliasUsers(request)); request = AliasRequest.builder() .destinationMpid(123) .sourceMpid(456) .startTime(2) .endTime(1) .build(); assertFalse(identityApi.aliasUsers(request)); request = AliasRequest.builder() .destinationMpid(1) .sourceMpid(2) .build(); assertFalse(identityApi.aliasUsers(request)); request = AliasRequest.builder() .destinationMpid(1) .sourceMpid(2) .startTime(3) .build(); assertFalse(identityApi.aliasUsers(request)); request = AliasRequest.builder() .destinationMpid(1) .sourceMpid(2) .endTime(3).build(); assertFalse(identityApi.aliasUsers(request)); }
@Test public void testAliasUsersValidationAcceptance() { IdentityApi identityApi = new IdentityApi(); final AndroidUtils.Mutable<Boolean> requestMade = new AndroidUtils.Mutable(false); identityApi.mMessageManager = new MessageManager() { @Override public void logAliasRequest(AliasRequest aliasRequest) { requestMade.value = true; } }; AliasRequest request = AliasRequest.builder() .destinationMpid(1) .sourceMpid(2) .startTime(3) .endTime(4) .build(); assertTrue(identityApi.aliasUsers(request)); assertTrue(requestMade.value); }