-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/MetadataSubject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.google.cloud.bigtable.data.v2.stub; | ||
|
||
import static com.google.common.truth.Truth.assertAbout; | ||
|
||
import com.google.common.truth.FailureMetadata; | ||
import com.google.common.truth.Subject; | ||
import io.grpc.Metadata; | ||
import javax.annotation.Nullable; | ||
|
||
/** Utility class to test key-value pairs in {@link io.grpc.Metadata}. */ | ||
final class MetadataSubject extends Subject { | ||
|
||
@Nullable private final Metadata actual; | ||
|
||
public static Factory<MetadataSubject, Metadata> metadata() { | ||
return MetadataSubject::new; | ||
} | ||
|
||
private MetadataSubject(FailureMetadata metadata, @Nullable Metadata actual) { | ||
super(metadata, actual); | ||
this.actual = actual; | ||
} | ||
|
||
public static MetadataSubject assertThat(@Nullable Metadata actual) { | ||
return assertAbout(metadata()).that(actual); | ||
} | ||
|
||
public void containsAtLeast(String... keyValuePairs) { | ||
assert actual != null; | ||
for (int i = 0; i < keyValuePairs.length; i += 2) { | ||
check("containsAtLeast()") | ||
.that(actual.get(Metadata.Key.of(keyValuePairs[i], Metadata.ASCII_STRING_MARSHALLER))) | ||
.isEqualTo(keyValuePairs[i + 1]); | ||
} | ||
} | ||
|
||
public void doesNotContainKeys(String... keys) { | ||
assert actual != null; | ||
for (String key : keys) { | ||
check("doesNotContainKeys()") | ||
.that(actual.containsKey(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER))) | ||
.isFalse(); | ||
} | ||
} | ||
} |