public final class

BundleSubject

extends Subject

 java.lang.Object

↳Subject

↳androidx.test.ext.truth.os.BundleSubject

Gradle dependencies

compile group: 'androidx.test.ext', name: 'truth', version: '1.5.0-alpha06'

  • groupId: androidx.test.ext
  • artifactId: truth
  • version: 1.5.0-alpha06

Artifact androidx.test.ext:truth:1.5.0-alpha06 it located at Google repository (https://maven.google.com/)

Overview

Subject for making assertions about s.

Summary

Methods
public static BundleSubjectassertThat(Bundle bundle)

public BooleanSubjectbool(java.lang.String key)

public static <any>bundles()

public voidcontainsKey(java.lang.String key)

public voiddoesNotContainKey(java.lang.String key)

public DoubleSubjectdoubleFloat(java.lang.String key)

public voidhasSize(int size)

public IntegerSubjectinteger(java.lang.String key)

public voidisEmpty()

public voidisNotEmpty()

public LongSubjectlongInt(java.lang.String key)

public ParcelableSubject<Parcelable>parcelable(java.lang.String key)

public IterableSubjectparcelableArrayList(java.lang.String key)

public SubjectparcelableAsType(java.lang.String key, <any> subjectFactory)

public Subjectserializable(java.lang.String key)

Returns a truth subject for the value associated with the given key.

public StringSubjectstring(java.lang.String key)

public IterableSubjectstringArrayList(java.lang.String key)

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

Methods

public static BundleSubject assertThat(Bundle bundle)

public static <any> bundles()

public void hasSize(int size)

public void isEmpty()

public void isNotEmpty()

public StringSubject string(java.lang.String key)

public IntegerSubject integer(java.lang.String key)

public LongSubject longInt(java.lang.String key)

public DoubleSubject doubleFloat(java.lang.String key)

public BooleanSubject bool(java.lang.String key)

public ParcelableSubject<Parcelable> parcelable(java.lang.String key)

public Subject parcelableAsType(java.lang.String key, <any> subjectFactory)

public IterableSubject stringArrayList(java.lang.String key)

public IterableSubject parcelableArrayList(java.lang.String key)

public Subject serializable(java.lang.String key)

Returns a truth subject for the value associated with the given key.

public void containsKey(java.lang.String key)

public void doesNotContainKey(java.lang.String key)

Source

/*
 * Copyright (C) 2018 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.ext.truth.os;

import static com.google.common.truth.Fact.simpleFact;

import android.os.Bundle;
import android.os.Parcelable;
import com.google.common.truth.BooleanSubject;
import com.google.common.truth.DoubleSubject;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.IntegerSubject;
import com.google.common.truth.IterableSubject;
import com.google.common.truth.LongSubject;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;

/** Subject for making assertions about {@link Bundle}s. */
public final class BundleSubject extends Subject {

  public static BundleSubject assertThat(Bundle bundle) {
    return Truth.assertAbout(bundles()).that(bundle);
  }

  public static Subject.Factory<BundleSubject, Bundle> bundles() {
    return BundleSubject::new;
  }

  private final Bundle actual;

  BundleSubject(FailureMetadata failureMetadata, Bundle subject) {
    super(failureMetadata, subject);
    this.actual = subject;
  }

  public void hasSize(int size) {
    check("size()").that(actual.size()).isEqualTo(size);
  }

  public void isEmpty() {
    if (!actual.isEmpty()) {
      failWithActual(simpleFact("expected to be empty"));
    }
  }

  public void isNotEmpty() {
    if (actual.isEmpty()) {
      failWithActual(simpleFact("expected to be non-empty"));
    }
  }

  public StringSubject string(String key) {
    return check("getString(%s)", key).that(actual.getString(key));
  }

  public IntegerSubject integer(String key) {
    return check("getInt(%s)", key).that(actual.getInt(key));
  }

  public LongSubject longInt(String key) {
    return check("getLong(%s)", key).that(actual.getLong(key));
  }

  public DoubleSubject doubleFloat(String key) {
    return check("getDouble(%s)", key).that(actual.getDouble(key));
  }

  public BooleanSubject bool(String key) {
    return check("getBoolean(%s)", key).that(actual.getBoolean(key));
  }

  public <T extends Parcelable> ParcelableSubject<T> parcelable(String key) {
    return check("getParcelable(%s)", key)
        .about(ParcelableSubject.<T>parcelables())
        .that(actual.<T>getParcelable(key));
  }

  public <T extends Parcelable, SubjectT extends Subject> SubjectT parcelableAsType(
      String key, Subject.Factory<SubjectT, T> subjectFactory) {
    return check("getParcelable(%s)", key).about(subjectFactory).that(actual.<T>getParcelable(key));
  }

  public IterableSubject stringArrayList(String key) {
    return check("getStringArrayList(%s)", key).that(actual.getStringArrayList(key));
  }

  public IterableSubject parcelableArrayList(String key) {
    return check("getParcelableArrayList(%s)", key).that(actual.getParcelableArrayList(key));
  }

  /** Returns a truth subject for the value associated with the given key. */
  public Subject serializable(String key) {
    return check("getSerializable(%s)", key).that(actual.getSerializable(key));
  }

  public void containsKey(String key) {
    if (!actual.containsKey(key)) {
      failWithActual(simpleFact("expected to contain key " + key));
    }
  }

  public void doesNotContainKey(String key) {
    if (actual.containsKey(key)) {
      failWithActual(simpleFact("expected to not contain key " + key));
    }
  }
}