public abstract class

SingleActivityFactory<T extends Activity>

extends java.lang.Object

implements InterceptingActivityFactory

 java.lang.Object

↳androidx.test.runner.intercepting.SingleActivityFactory<T>

Gradle dependencies

compile group: 'androidx.test', name: 'runner', version: '1.5.0-alpha03'

  • groupId: androidx.test
  • artifactId: runner
  • version: 1.5.0-alpha03

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

Androidx artifact mapping:

androidx.test:runner com.android.support.test:runner

Androidx class mapping:

androidx.test.runner.intercepting.SingleActivityFactory android.support.test.runner.intercepting.SingleActivityFactory

Overview

Abstract implementation of InterceptingActivityFactory which allows to intercept only one activity at a time. Child classes are responsible for creating activity object.

Summary

Constructors
publicSingleActivityFactory(java.lang.Class<Activity> activityClassToIntercept)

Methods
public final Activitycreate(java.lang.ClassLoader classLoader, java.lang.String className, Intent intent)

protected abstract Activitycreate(Intent intent)

This method needs to be implemented by child class to create activity object for the given intent that specified the activity class being instantiated.

public final java.lang.Class<Activity>getActivityClassToIntercept()

This method can be used to get the Class of activity being instantiated by this factory.

public final booleanshouldIntercept(java.lang.ClassLoader classLoader, java.lang.String className, Intent intent)

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

Constructors

public SingleActivityFactory(java.lang.Class<Activity> activityClassToIntercept)

Methods

public final boolean shouldIntercept(java.lang.ClassLoader classLoader, java.lang.String className, Intent intent)

public final Activity create(java.lang.ClassLoader classLoader, java.lang.String className, Intent intent)

public final java.lang.Class<Activity> getActivityClassToIntercept()

This method can be used to get the Class of activity being instantiated by this factory.

Returns:

Class of the activity object being instantiated

protected abstract Activity create(Intent intent)

This method needs to be implemented by child class to create activity object for the given intent that specified the activity class being instantiated.

Parameters:

intent: The Intent object that specified the activity class being instantiated.

Returns:

The newly instantiated Activity object.

Source

/*
 * Copyright (C) 2016 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.runner.intercepting;

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

import android.app.Activity;
import android.content.Intent;

/**
 * Abstract implementation of {@link InterceptingActivityFactory} which allows to intercept only one
 * activity at a time. Child classes are responsible for creating activity object.
 */
public abstract class SingleActivityFactory<T extends Activity>
    implements InterceptingActivityFactory {

  private final Class<T> activityClassToIntercept;

  public SingleActivityFactory(Class<T> activityClassToIntercept) {
    checkNotNull(activityClassToIntercept);
    this.activityClassToIntercept = checkNotNull(activityClassToIntercept);
  }

  @Override
  public final boolean shouldIntercept(ClassLoader classLoader, String className, Intent intent) {
    return activityClassToIntercept.getName().equals(className);
  }

  @Override
  public final Activity create(ClassLoader classLoader, String className, Intent intent) {
    if (!shouldIntercept(classLoader, className, intent))
      throw new UnsupportedOperationException(
          String.format("Can't create instance of %s", className));
    return create(intent);
  }

  /**
   * This method can be used to get the Class of activity being instantiated by this factory.
   *
   * @return Class of the activity object being instantiated
   */
  public final Class<T> getActivityClassToIntercept() {
    return activityClassToIntercept;
  }

  /**
   * This method needs to be implemented by child class to create activity object for the given
   * intent that specified the activity class being instantiated.
   *
   * @param intent The Intent object that specified the activity class being instantiated.
   * @return The newly instantiated Activity object.
   */
  protected abstract T create(Intent intent);
}