Skip to content

Commit e1b9481

Browse files
Add byteArray() method to BundleSubject that allows to assert things about a bundle element typed at byte[].
PiperOrigin-RevId: 606745916
1 parent 32acafb commit e1b9481

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

ext/truth/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
**New Features**
1010

11+
* Added `byteArray()` method to `BundleSubject`.
12+
1113
**Breaking Changes**
1214

1315
**API Changes**

ext/truth/java/androidx/test/ext/truth/api/current_public.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ package androidx.test.ext.truth.os {
107107
method public static androidx.test.ext.truth.os.BundleSubject! assertThat(android.os.Bundle!);
108108
method public com.google.common.truth.BooleanSubject! bool(String!);
109109
method public static com.google.common.truth.Subject.Factory<androidx.test.ext.truth.os.BundleSubject!,android.os.Bundle!>! bundles();
110+
method public com.google.common.truth.PrimitiveByteArraySubject! byteArray(String!);
110111
method public void containsKey(String!);
111112
method public void doesNotContainKey(String!);
112113
method public com.google.common.truth.DoubleSubject doubleFloat(String);

ext/truth/java/androidx/test/ext/truth/os/BundleSubject.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.common.truth.IterableSubject;
2828
import com.google.common.truth.LongSubject;
2929
import com.google.common.truth.ObjectArraySubject;
30+
import com.google.common.truth.PrimitiveByteArraySubject;
3031
import com.google.common.truth.StringSubject;
3132
import com.google.common.truth.Subject;
3233
import com.google.common.truth.Truth;
@@ -93,6 +94,10 @@ public BooleanSubject bool(String key) {
9394
return check("getBoolean(%s)", key).that(actual.getBoolean(key));
9495
}
9596

97+
public PrimitiveByteArraySubject byteArray(String key) {
98+
return check("getByteArray(%s)", key).that(actual.getByteArray(key));
99+
}
100+
96101
public <T extends Parcelable> ParcelableSubject<T> parcelable(String key) {
97102
return check("getParcelable(%s)", key)
98103
.about(ParcelableSubject.<T>parcelables())

ext/truth/javatests/androidx/test/ext/truth/os/BundleSubjectTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ public void bool() {
9696
assertThat(bundle).bool("foo").isTrue();
9797
}
9898

99+
@Test
100+
public void byteArray() {
101+
Bundle bundle = new Bundle();
102+
bundle.putByteArray("foo", new byte[] {1, 2, 3});
103+
104+
assertThat(bundle).byteArray("foo").isEqualTo(new byte[] {1, 2, 3});
105+
}
106+
99107
@Test
100108
public void parcelable() {
101109
Bundle bundle = new Bundle();

0 commit comments

Comments
 (0)