android.support.annotation.VisibleForTesting Java Examples

The following examples show how to use android.support.annotation.VisibleForTesting. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BottomBarTab.java    From BottomBar with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
int getLayoutResource() {
    int layoutResource;
    switch (type) {
        case FIXED:
            layoutResource = R.layout.bb_bottom_bar_item_fixed;
            break;
        case SHIFTING:
            layoutResource = R.layout.bb_bottom_bar_item_shifting;
            break;
        case TABLET:
            layoutResource = R.layout.bb_bottom_bar_item_fixed_tablet;
            break;
        default:
            // should never happen
            throw new RuntimeException("Unknown BottomBarTab type.");
    }
    return layoutResource;
}
 
Example #2
Source File: AuthStateManager.java    From okta-sdk-appauth-android with Apache License 2.0 6 votes vote down vote up
@AnyThread
@VisibleForTesting
void writeState(@Nullable AuthState state) {
    mPrefsLock.lock();
    try {
        SharedPreferences.Editor editor = mPrefs.edit();
        if (state == null) {
            editor.remove(KEY_STATE);
        } else {
            editor.putString(KEY_STATE, state.jsonSerializeString());
        }

        if (!editor.commit()) {
            throw new IllegalStateException("Failed to write state to shared prefs");
        }
    } finally {
        mPrefsLock.unlock();
    }
}
 
Example #3
Source File: CronetEngine.java    From cronet with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Compares two strings that contain versions. The string should only contain
 * dot-separated segments that contain an arbitrary number of digits digits [0-9].
 *
 * @param s1 the first string.
 * @param s2 the second string.
 * @return -1 if s1<s2, +1 if s1>s2 and 0 if s1=s2. If two versions are equal, the
 *         version with the higher number of segments is considered to be higher.
 *
 * @throws IllegalArgumentException if any of the strings contains an illegal
 * version number.
 */
@VisibleForTesting
static int compareVersions(String s1, String s2) {
    if (s1 == null || s2 == null) {
        throw new IllegalArgumentException("The input values cannot be null");
    }
    String[] s1segments = s1.split("\\.");
    String[] s2segments = s2.split("\\.");
    for (int i = 0; i < s1segments.length && i < s2segments.length; i++) {
        try {
            int s1segment = Integer.parseInt(s1segments[i]);
            int s2segment = Integer.parseInt(s2segments[i]);
            if (s1segment != s2segment) {
                return Integer.signum(s1segment - s2segment);
            }
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Unable to convert version segments into"
                            + " integers: " + s1segments[i] + " & " + s2segments[i],
                    e);
        }
    }
    return Integer.signum(s1segments.length - s2segments.length);
}
 
Example #4
Source File: FooterPaymentResult.java    From px-android with MIT License 6 votes vote down vote up
@VisibleForTesting
Footer.Props getFooterProps(@NonNull final Context context) {
    Button.Props buttonAction = null;
    Button.Props linkAction = null;

    final PaymentResultViewModel paymentResultViewModel = PaymentResultViewModelFactory
        .createPaymentResultViewModel(props);

    if (paymentResultViewModel.getLinkAction() != null) {
        linkAction = new Button.Props(paymentResultViewModel.getLinkActionTitle(context),
            paymentResultViewModel.getLinkAction());
    }

    if (paymentResultViewModel.getMainAction() != null) {
        buttonAction = new Button.Props(paymentResultViewModel.getMainActionTitle(context),
            paymentResultViewModel.getMainAction());
    }

    return new Footer.Props(buttonAction, linkAction);
}
 
Example #5
Source File: Form.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("WeakerAccess")  // Visible for testing
@VisibleForTesting
InputStream openAssetInternal(String path) throws IOException {
  if (path.startsWith(ASSETS_PREFIX)) {
    final AssetManager am = getAssets();
    return am.open(path.substring(ASSETS_PREFIX.length()));
  } else if (path.startsWith("file:")) {
    return FileUtil.openFile(URI.create(path));
  } else {
    return FileUtil.openFile(path);
  }
}
 
Example #6
Source File: QueryUtil.java    From OpenYOLO-Android with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static String longAsHex(long val) {
    char[] result = new char[Long.SIZE / Byte.SIZE * 2];
    int index = result.length - 1;
    while (index >= 0) {
        result[index--] = HEX_DIGITS[(int)(val & HALF_BYTE_MASK)];
        val >>>= HALF_BYTE_WIDTH;
        result[index--] = HEX_DIGITS[(int)(val & HALF_BYTE_MASK)];
        val >>>= HALF_BYTE_WIDTH;
    }

    return new String(result);
}
 
Example #7
Source File: EmptyRecyclerView.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void showRecycler() {
    if (mEmptyView != null) {
        mEmptyView.setVisibility(GONE);
    }
    setVisibility(VISIBLE);
}
 
Example #8
Source File: Button.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke button event callback
 */
@VisibleForTesting
/*package*/ void performButtonEvent(boolean state) {
    if (mListener != null) {
        mListener.onButtonEvent(this, state);
    }
}
 
Example #9
Source File: EmptyRecyclerView.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void showRecycler() {
    if (mEmptyView != null) {
        mEmptyView.setVisibility(GONE);
    }
    setVisibility(VISIBLE);
}
 
Example #10
Source File: BottomBar.java    From BottomBar with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void restoreState(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        isComingFromRestoredState = true;
        ignoreTabReselectionListener = true;

        int restoredPosition = savedInstanceState.getInt(STATE_CURRENT_SELECTED_TAB, currentTabPosition);
        selectTabAtPosition(restoredPosition, false);
    }
}
 
Example #11
Source File: AttachmentDatabase.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@VisibleForTesting
@Nullable InputStream getDataStream(MasterSecret masterSecret, AttachmentId attachmentId, String dataType)
{
  File dataFile = getAttachmentDataFile(attachmentId, dataType);

  byte[] digest = (!dataType.equals(THUMBNAIL)) ? getAttachment(attachmentId).getDigest() : null;

  try {
    if (dataFile != null) return new DecryptingPartInputStream(dataFile, masterSecret, digest);
    else                  return null;
  } catch (FileNotFoundException e) {
    Log.w(TAG, e);
    return null;
  }
}
 
Example #12
Source File: EmptyRecyclerView.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void showRecycler() {
    if (mEmptyView != null) {
        mEmptyView.setVisibility(GONE);
    }
    setVisibility(VISIBLE);
}
 
Example #13
Source File: OAuthManager.java    From Auth0.Android with MIT License 5 votes vote down vote up
@VisibleForTesting
static void assertValidState(@NonNull String requestState, @Nullable String responseState) throws AuthenticationException {
    if (!requestState.equals(responseState)) {
        Log.e(TAG, String.format("Received state doesn't match. Received %s but expected %s", responseState, requestState));
        throw new AuthenticationException(ERROR_VALUE_ACCESS_DENIED, "The received state is invalid. Try again.");
    }
}
 
Example #14
Source File: GraphServiceController.java    From android-java-connect-sample with MIT License 5 votes vote down vote up
@VisibleForTesting

    /**
     * Creates a new Message object
     */
    Message createMessage(
            String subject,
            String body,
            String address) {

        if (address == null || address.isEmpty()) {
            throw new IllegalArgumentException("The address parameter can't be null or empty.");
        } else {
            // perform a simple validation of the email address
            String addressParts[] = address.split("@");
            if (addressParts.length != 2 || addressParts[0].length() == 0 || addressParts[1].indexOf('.') == -1) {
                throw new IllegalArgumentException(
                        String.format("The address parameter must be a valid email address {0}", address)
                );
            }
        }
        Message message = new Message();
        EmailAddress emailAddress = new EmailAddress();
        emailAddress.address = address;
        Recipient recipient = new Recipient();
        recipient.emailAddress = emailAddress;
        message.toRecipients = Collections.singletonList(recipient);
        ItemBody itemBody = new ItemBody();
        itemBody.content = body;
        itemBody.contentType = BodyType.HTML;
        message.body = itemBody;
        message.subject = subject;
        return message;
    }
 
Example #15
Source File: MainActivity.java    From testing-cin with MIT License 5 votes vote down vote up
/**
 * Only called from test, creates and returns a new {@link SimpleIdlingResource}.
 */
@VisibleForTesting
@NonNull
public IdlingResource getIdlingResource() {
    if (mIdlingResource == null) {
        mIdlingResource = new SimpleIdlingResource();
    }
    return mIdlingResource;
}
 
Example #16
Source File: RideRequestButtonController.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@VisibleForTesting
RideRequestButtonController(
        @NonNull RideRequestButtonView rideRequestButtonView,
        @NonNull RidesService ridesService,
        @Nullable RideRequestButtonCallback callback) {
    this.rideRequestButtonView = rideRequestButtonView;
    this.rideRequestButtonCallback = callback;
    this.ridesService = ridesService;
    this.pendingDelegate = new TimeDelegate(rideRequestButtonView, callback);
}
 
Example #17
Source File: MobileMessagingCloudHandler.java    From mobile-messaging-sdk-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("WeakerAccess")
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void handleWork(Context context, Intent intent) {
    String action = intent.getAction();
    if (action == null) {
        return;
    }

    switch (action) {
        case ACTION_CLOUD_MESSAGE_RECEIVE:
            handleMessage(context, intent);
            break;

        case ACTION_NEW_TOKEN:
            handleNewToken(context, intent);
            break;

        case ACTION_TOKEN_CLEANUP:
            handleTokenCleanup(context, intent);
            break;

        case ACTION_TOKEN_RESET:
            handleTokenReset(context, intent);
            break;

        case ACTION_TOKEN_ACQUIRE:
            handleTokenAcquire(context, intent);
            break;
    }
}
 
Example #18
Source File: ContinuousWeightedSort.java    From spruce-android with MIT License 5 votes vote down vote up
@VisibleForTesting
double calculateMaxDistance(double leftHorizontalDistance, double rightHorizontalDistance, double maximum) {
    if (leftHorizontalDistance > rightHorizontalDistance && leftHorizontalDistance > maximum) {
        maximum = leftHorizontalDistance;
    } else if (rightHorizontalDistance > leftHorizontalDistance && rightHorizontalDistance > maximum) {
        maximum = rightHorizontalDistance;
    }
    return maximum;
}
 
Example #19
Source File: RideRequestView.java    From rides-android-sdk with MIT License 5 votes vote down vote up
/**
 * Builds a URL with necessary query parameters to load in the {@link WebView}.
 *
 * @param rideParameters the {@link RideParameters} to build into the query
 * @return the URL {@link String} to load in the {@link WebView}
 */
@NonNull
@VisibleForTesting
static String buildUrlFromRideParameters(@NonNull Context context,
                                         @NonNull RideParameters rideParameters,
                                         @NonNull SessionConfiguration loginConfiguration) {
    final String ENDPOINT = "components";
    final String ENVIRONMENT_KEY = "env";
    final String HTTPS = "https";
    final String PATH = "rides/";
    final String SANDBOX = "sandbox";

    Uri.Builder builder = new Uri.Builder();
    builder.scheme(HTTPS)
            .authority(ENDPOINT + "." + loginConfiguration.getEndpointRegion().getDomain())
            .appendEncodedPath(PATH);

    if (rideParameters.getUserAgent() == null) {
        rideParameters.setUserAgent(USER_AGENT_RIDE_VIEW);
    }

    RideRequestDeeplink deeplink = new RideRequestDeeplink.Builder(context)
            .setSessionConfiguration(loginConfiguration)
            .setRideParameters(rideParameters).build();
    Uri uri = deeplink.getUri();
    builder.encodedQuery(uri.getEncodedQuery());

    if (loginConfiguration.getEnvironment() == SessionConfiguration.Environment.SANDBOX) {
        builder.appendQueryParameter(ENVIRONMENT_KEY, SANDBOX);
    }

    return builder.build().toString();
}
 
Example #20
Source File: NestedRadioGroupManager.java    From NestedRadioButton with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected void setCheckedId(@IdRes int id) {
    checkedId = id;
    if (onCheckedChangeListener != null) {
        onCheckedChangeListener.onCheckedChanged(this, checkedId);
    }
    //TODO
    /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final AutofillManager afm = mContext.getSystemService(AutofillManager.class);
        if (afm != null) {
            afm.notifyValueChanged(this);
        }
    }*/
}
 
Example #21
Source File: LoginButton.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@NonNull
@VisibleForTesting
protected synchronized LoginManager getOrCreateLoginManager() {
    if (loginManager == null) {
        loginManager = new LoginManager(getOrCreateAccessTokenStorage(),
                callback,
                getOrCreateSessionConfiguration(),
                requestCode);
    }
    return loginManager;
}
 
Example #22
Source File: LoginButton.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@VisibleForTesting
void login() {
    final Activity activity = getActivity();

    checkNotNull(callback, "Callback has not been set, call setCallback to assign value.");
    if ((scopes == null || scopes.isEmpty()) && (sessionConfiguration.getScopes() == null ||
            sessionConfiguration.getScopes().isEmpty())) {
        throw new IllegalStateException("Scopes are not yet set.");
    }

    getOrCreateLoginManager().login(activity);
}
 
Example #23
Source File: SpanEZ.java    From SpanEZ with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given {@code span} to the specified range from
 *
 * @param targetRange the range were the span will be applied to
 * @param span        the span to be applied
 */
@SuppressWarnings("WeakerAccess")
@VisibleForTesting
protected void addSpan(@NonNull TargetRange targetRange, @NonNull Object span) {
    final int start = targetRange.getStart();
    final int end = targetRange.getEnd();
    // Added 1 to the span, because it seems that internally it does exclusive range
    spannableContent.setSpan(span, start, end + 1, spanFlags);
}
 
Example #24
Source File: OAuthClientConfiguration.java    From okta-sdk-appauth-android with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void readConfiguration(@NonNull final JSONObject jsonObject)
        throws InvalidJsonDocumentException {
    JsonParser jsonParser = JsonParser.forJson(jsonObject);


    mClientId = jsonParser.getRequiredString("client_id");
    mRedirectUri = jsonParser.getRequiredUri("redirect_uri");
    mEndSessionRedirectUri = jsonParser.getRequiredUri("end_session_redirect_uri");
    mDiscoveryUri = jsonParser.getRequiredHttpsUri("issuer_uri")
            .buildUpon().appendEncodedPath(OIDC_DISCOVERY).build();

    if (!isRedirectUrisRegistered()) {
        throw new InvalidJsonDocumentException(
                "redirect_uri and end_session_redirect_uri is not handled by any activity "
                        + "in this app! "
                        + "Ensure that the appAuthRedirectScheme in your build.gradle file "
                        + "is correctly configured, or that an appropriate intent filter "
                        + "exists in your app manifest.");
    }


    mScopes = new LinkedHashSet<>(jsonParser.getRequiredStringArray("scopes"));

    //We can not take hash code directly from JSONObject
    //because JSONObject does not follow java has code contract
    mConfigHash = jsonObject.toString().hashCode();

    Log.d(TAG, String.format("Configuration loaded with: \n%s", this.toString()));
}
 
Example #25
Source File: SecureCredentialsManager.java    From Auth0.Android with MIT License 5 votes vote down vote up
@VisibleForTesting
SecureCredentialsManager(@NonNull AuthenticationAPIClient apiClient, @NonNull Storage storage, @NonNull CryptoUtil crypto, @NonNull JWTDecoder jwtDecoder) {
    this.apiClient = apiClient;
    this.storage = storage;
    this.crypto = crypto;
    this.gson = GsonProvider.buildGson();
    this.authenticateBeforeDecrypt = false;
    this.jwtDecoder = jwtDecoder;
}
 
Example #26
Source File: ExecutionDelegator.java    From firebase-jobdispatcher-android with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static JobServiceConnection getJobServiceConnection(String serviceName) {
  synchronized (serviceConnections) {
    return serviceConnections.get(serviceName);
  }
}
 
Example #27
Source File: HistoryManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
HistoryAdapter getAdapterForTests() {
    return mHistoryAdapter;
}
 
Example #28
Source File: AddNewItemViewModel.java    From Building-Professional-Android-Applications with MIT License 4 votes vote down vote up
@VisibleForTesting
public void setPortfolioRepository(PortfolioRepository portfolioRepository) {
    this.portfolioRepository = portfolioRepository;
}
 
Example #29
Source File: SuperHeroesApplication.java    From KataSuperHeroesAndroid with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting public void setComponent(MainComponent mainComponent) {
  this.mainComponent = mainComponent;
}
 
Example #30
Source File: Negated.java    From cortado with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
final Cortado getCortado() {
    return cortado;
}