public final class

PlatformTestStorageRegistry

extends java.lang.Object

 java.lang.Object

↳androidx.test.platform.io.PlatformTestStorageRegistry

Gradle dependencies

compile group: 'androidx.test', name: 'orchestrator', version: '1.5.0'

  • groupId: androidx.test
  • artifactId: orchestrator
  • version: 1.5.0

Artifact androidx.test:orchestrator:1.5.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test:orchestrator com.android.support.test:orchestrator

Overview

A registry instance that holds a reference to an PlatformTestStorage instance.

Users should use this to retrieve the appropriate PlatformTestStorage for the current execution environment.

Summary

Methods
public static synchronized PlatformTestStoragegetInstance()

Returns the registered PlatformTestStorage instance.

public static synchronized voidregisterInstance(PlatformTestStorage instance)

Registers a new PlatformTestStorage instance.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static synchronized void registerInstance(PlatformTestStorage instance)

Registers a new PlatformTestStorage instance. This will override any previously set instance.

Users should not typically call this directly - it is intended for use by the test infrastructure.

Parameters:

instance: the instance to be registered. Cannot be null.

public static synchronized PlatformTestStorage getInstance()

Returns the registered PlatformTestStorage instance.

By default, a FileTestStorage implementation is used. The default implementation is currently recommended for users using android gradle plugins version 8.0 or greater which supports writing output files (only). Gradle users using versions 8.0 or greater can optionally also opt in the test services implementation by adding the following configuration to their build.gradle file:
defaultConfig { testInstrumentationRunnerArguments useTestStorageService: "true" } dependencies { androidTestUtil "androidx.test.services:test-services:$servicesVersion" }

This method returns the instance last registered by the PlatformTestStorageRegistry.registerInstance(PlatformTestStorage) method, or the default instance if none is ever registered. Advanced users can provide java.util.ServiceLoader metadata to provide an alternate implementation to load.

Source

/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.test.platform.io;

import static androidx.test.internal.util.Checks.checkNotNull;

import androidx.test.internal.platform.ServiceLoaderWrapper;

/**
 * A registry instance that holds a reference to an {@code PlatformTestStorage} instance.
 *
 * <p>Users should use this to retrieve the appropriate {@link PlatformTestStorage} for the current
 * execution environment.
 */
public final class PlatformTestStorageRegistry {
  private static PlatformTestStorage testStorageInstance;

  static {
    // By default, uses the instance loaded by the service loader if available; otherwise, uses a
    // default no_op implementation.
    testStorageInstance =
        ServiceLoaderWrapper.loadSingleService(PlatformTestStorage.class, FileTestStorage::new);
  }

  private PlatformTestStorageRegistry() {}

  /**
   * Registers a new {@code PlatformTestStorage} instance. This will override any previously set
   * instance.
   *
   * <p>Users should not typically call this directly - it is intended for use by the test
   * infrastructure.
   *
   * @param instance the instance to be registered. Cannot be null.
   */
  public static synchronized void registerInstance(PlatformTestStorage instance) {
    testStorageInstance = checkNotNull(instance);
  }

  /**
   * Returns the registered {@code PlatformTestStorage} instance.
   *
   * <p>By default, a {@link FileTestStorage} implementation is used. The default implementation is
   * currently recommended for users using android gradle plugins version 8.0 or greater which
   * supports writing output files (only). Gradle users using versions 8.0 or greater can optionally
   * also opt in the test services {@link TestStorage} implementation by adding the following
   * configuration to their build.gradle file: <br>
   * <code>
   * defaultConfig { testInstrumentationRunnerArguments useTestStorageService: "true" }
   * dependencies { androidTestUtil "androidx.test.services:test-services:$servicesVersion" }
   * </code> <br>
   *
   * <p>This method returns the instance last registered by the {@link
   * #registerInstance(PlatformTestStorage)} method, or the default instance if none is ever
   * registered. Advanced users can provide {@link java.util.ServiceLoader} metadata to provide an
   * alternate implementation to load.
   */
  public static synchronized PlatformTestStorage getInstance() {
    return testStorageInstance;
  }
}