public final class

ErrorInfo

extends java.lang.Object

 java.lang.Object

↳androidx.test.services.events.ErrorInfo

Gradle dependencies

compile group: 'androidx.test', name: 'runner', version: '1.6.2'

  • groupId: androidx.test
  • artifactId: runner
  • version: 1.6.2

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

Androidx artifact mapping:

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

Overview

Denotes an android test error. Has details of the error including stack trace, type, and message.

Summary

Fields
public static final <any>CREATOR

public final java.lang.StringerrorMessage

The message associated with the error.

public final java.lang.StringerrorType

The type of error.

public final java.lang.StringstackTrace

The stack trace associated with the error.

Constructors
publicErrorInfo(Parcel source)

Creates a ErrorInfo from android .

publicErrorInfo(java.lang.String errorMessage, java.lang.String errorType, java.lang.String stackTrace)

Constructor to create a ErrorInfo.

Methods
public static ErrorInfocreateFromFailure(Failure failure)

public intdescribeContents()

public voidwriteToParcel(Parcel parcel, int i)

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

Fields

public final java.lang.String errorMessage

The message associated with the error.

public final java.lang.String errorType

The type of error. E.g NullPointerException.

public final java.lang.String stackTrace

The stack trace associated with the error.

public static final <any> CREATOR

Constructors

public ErrorInfo(java.lang.String errorMessage, java.lang.String errorType, java.lang.String stackTrace)

Constructor to create a ErrorInfo.

public ErrorInfo(Parcel source)

Creates a ErrorInfo from android .

Parameters:

source: the android Parcel.

Methods

public int describeContents()

public void writeToParcel(Parcel parcel, int i)

public static ErrorInfo createFromFailure(Failure failure)

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.services.events;

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

import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.test.services.events.internal.StackTrimmer;
import org.junit.runner.notification.Failure;

/**
 * Denotes an android test error. Has details of the error including stack trace, type, and message.
 *
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public final class ErrorInfo implements Parcelable {

  /** The message associated with the error. */
  @Nullable public final String errorMessage;

  /** The type of error. E.g {@code NullPointerException}. */
  @Nullable public final String errorType;

  /** The stack trace associated with the error. */
  @NonNull public final String stackTrace;

  /** Constructor to create a {@link ErrorInfo}. */
  public ErrorInfo(
      @Nullable String errorMessage, @Nullable String errorType, @NonNull String stackTrace) {
    this.errorMessage = errorMessage;
    this.errorType = errorType;
    this.stackTrace = checkNotNull(stackTrace, "stackTrace cannot be null");
  }

  /**
   * Creates a {@link ErrorInfo} from android {@link Parcel}.
   *
   * @param source the android Parcel.
   */
  public ErrorInfo(@NonNull Parcel source) {
    checkNotNull(source, "source cannot be null");
    errorMessage = source.readString();
    errorType = source.readString();
    stackTrace = checkNotNull(source.readString(), "stackTrace cannot be null");
  }

  @Override
  public int describeContents() {
    return 0;
  }

  @Override
  public void writeToParcel(Parcel parcel, int i) {
    parcel.writeString(errorMessage);
    parcel.writeString(errorType);
    parcel.writeString(stackTrace);
  }

  public static final Parcelable.Creator<ErrorInfo> CREATOR =
      new Parcelable.Creator<ErrorInfo>() {
        @Override
        public ErrorInfo createFromParcel(Parcel source) {
          return new ErrorInfo(source);
        }

        @Override
        public ErrorInfo[] newArray(int size) {
          return new ErrorInfo[size];
        }
      };

  public static ErrorInfo createFromFailure(Failure failure) {
    return new ErrorInfo(
        StackTrimmer.getTrimmedMessage(failure),
        failure.getException().getClass().getName(),
        StackTrimmer.getTrimmedStackTrace(failure));
  }
}