### Question:
ButtonInternalImpl implements ButtonInternal { @Override public void trackIncomingIntent(ButtonRepository buttonRepository, DeviceManager deviceManager, Features features, Intent intent) { Uri data = intent.getData(); if (data == null) { return; } String sourceToken = data.getQueryParameter("btn_ref"); if (sourceToken != null && !sourceToken.isEmpty()) { setAttributionToken(buttonRepository, sourceToken); hasReceivedDirectDeeplink.set(true); } reportDeeplinkOpenEvent(buttonRepository, deviceManager, features, data); } ButtonInternalImpl(Executor executor); void configure(ButtonRepository buttonRepository, String applicationId); @Nullable @Override String getApplicationId(ButtonRepository buttonRepository); @Override void trackIncomingIntent(ButtonRepository buttonRepository, DeviceManager deviceManager,
            Features features, Intent intent); @Nullable @Override String getAttributionToken(ButtonRepository buttonRepository); @Override void addAttributionTokenListener(ButtonRepository buttonRepository,
            @NonNull ButtonMerchant.AttributionTokenListener listener); @Override void removeAttributionTokenListener(ButtonRepository buttonRepository,
            @NonNull ButtonMerchant.AttributionTokenListener listener); @Override void clearAllData(ButtonRepository buttonRepository); @Override void handlePostInstallIntent(final ButtonRepository buttonRepository,
            final DeviceManager deviceManager, final Features features, final String packageName,
            final PostInstallIntentListener listener); @Override void reportOrder(ButtonRepository buttonRepository, DeviceManager deviceManager,
            Features features, Order order, @Nullable final OrderListener orderListener);  }### Answer:
@Test public void trackIncomingIntent_withValidData_persistUrl() { ButtonRepository buttonRepository = mock(ButtonRepository.class); Intent intent = mock(Intent.class); Uri uri = mock(Uri.class); Uri.Builder builder = mock(Uri.Builder.class); when(intent.getData()).thenReturn(uri); when(uri.buildUpon()).thenReturn(builder); when(uri.buildUpon().clearQuery()).thenReturn(builder); when(builder.build()).thenReturn(uri); when(uri.getQueryParameter("btn_ref")).thenReturn("valid_source_token"); buttonInternal.trackIncomingIntent(buttonRepository, mock(DeviceManager.class), mock(Features.class), intent); verify(buttonRepository).setSourceToken("valid_source_token"); }
@Test public void trackIncomingIntent_withNullIntentData_doNotPersist() { ButtonRepository buttonRepository = mock(ButtonRepository.class); Intent intent = mock(Intent.class); when(intent.getData()).thenReturn(null); buttonInternal.trackIncomingIntent(buttonRepository, mock(DeviceManager.class), mock(Features.class), intent); verify(buttonRepository, never()).setSourceToken(anyString()); }