Skip to content

Commit

Permalink
test: improve code coverage
Browse files Browse the repository at this point in the history
Change-Id: I5ba6a0ffce9ba3fd1a4e02d97829220566600ad9
  • Loading branch information
ad548 committed Mar 13, 2021
1 parent 64da067 commit 332fb09
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Expand Up @@ -59,6 +59,9 @@ public static Code fromProto(com.google.rpc.Code proto) {

public static Code fromCodeNumber(int num) {
for (Code code : values()) {
if (code.proto == com.google.rpc.Code.UNRECOGNIZED) {
continue;
}
if (code.proto.getNumber() == num) {
return code;
}
Expand Down
Expand Up @@ -17,9 +17,6 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.common.collect.Lists;
import com.google.protobuf.Timestamp;
import com.google.protobuf.util.Timestamps;
import com.google.bigtable.admin.v2.Backup.State;
import com.google.bigtable.admin.v2.EncryptionInfo.EncryptionType;
import com.google.cloud.bigtable.common.Status;
Expand Down
Expand Up @@ -39,6 +39,12 @@ public void testAllTypes() {
.that(modelValue.toString())
.isEqualTo(protoValue.toString());
}

com.google.bigtable.admin.v2.EncryptionInfo randomEncryptionInfo =
com.google.bigtable.admin.v2.EncryptionInfo.newBuilder().setEncryptionTypeValue(14).build();
assertWithMessage("Unrecognized proto enum value should be wrapped")
.that(EncryptionInfo.Type.fromProto(randomEncryptionInfo.getEncryptionType()))
.isEqualTo(EncryptionInfo.Type.UNRECOGNIZED);
}

@Test
Expand Down
Expand Up @@ -35,6 +35,12 @@ public void testAllCodes() {
.that(modelValue.toString())
.isEqualTo(protoValue.toString());
}

com.google.rpc.Status randomProto =
com.google.rpc.Status.newBuilder().setCode(49).setMessage("some message").build();
assertWithMessage("Unrecognized proto value should be wrapped")
.that(Status.Code.fromProto(com.google.rpc.Code.forNumber(randomProto.getCode())))
.isEqualTo(Status.Code.UNRECOGNIZED);
}

@Test
Expand All @@ -49,6 +55,10 @@ public void testAllCodeNumbers() {
.that(modelValue.toString())
.isEqualTo(protoValue.toString());
}

assertWithMessage("Unrecognized proto enum value should be wrapped")
.that(Status.Code.fromCodeNumber(-1))
.isEqualTo(Status.Code.UNRECOGNIZED);
}

@Test
Expand Down

0 comments on commit 332fb09

Please sign in to comment.