Skip to content

Commit

Permalink
Migrate usages of Truth8.assertThat to equivalent usages of `Truth.…
Browse files Browse the repository at this point in the history
…assertThat`.

The `Truth8` methods will be deprecated (or hidden) in the future. Callers should move to `Truth`.

Some (but not all) of the CLs in this batch require Truth [1.4.0](https://github.com/google/truth/releases/tag/v1.4.0). I submitted a CL earlier today to (I hope) perform that upgrade for your project.

PiperOrigin-RevId: 604739382
  • Loading branch information
cpovirk authored and copybara-github committed Feb 6, 2024
1 parent 5957b55 commit 8f51c97
Show file tree
Hide file tree
Showing 23 changed files with 234 additions and 289 deletions.
7 changes: 3 additions & 4 deletions checker/src/test/java/dev/cel/checker/CelIdentDeclTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import dev.cel.expr.Decl.IdentDecl;
import dev.cel.expr.Type;
import dev.cel.expr.Type.PrimitiveType;
import com.google.common.truth.Truth8;
import dev.cel.common.ast.CelConstant;
import dev.cel.common.types.SimpleType;
import org.junit.Test;
Expand All @@ -45,7 +44,7 @@ public void celIdentBuilder_success() {
assertThat(stringIdent.name()).isEqualTo("ident");
assertThat(stringIdent.type()).isEqualTo(SimpleType.STRING);
assertThat(stringIdent.doc()).isEqualTo("doc");
Truth8.assertThat(stringIdent.constant()).hasValue(CelConstant.ofValue("str"));
assertThat(stringIdent.constant()).hasValue(CelConstant.ofValue("str"));
}

@Test
Expand All @@ -58,7 +57,7 @@ public void celIdentBuilder_clearConstant() {

builder.clearConstant();

Truth8.assertThat(builder.build().constant()).isEmpty();
assertThat(builder.build().constant()).isEmpty();
}

@Test
Expand All @@ -68,7 +67,7 @@ public void newIdentDeclaration_success() {
assertThat(intIdent.name()).isEqualTo("ident");
assertThat(intIdent.type()).isEqualTo(SimpleType.INT);
assertThat(intIdent.doc()).isEmpty();
Truth8.assertThat(intIdent.constant()).isEmpty();
assertThat(intIdent.constant()).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.truth.Truth8;
import com.google.protobuf.FieldMask;
import com.google.rpc.context.AttributeContext;
import dev.cel.common.types.CelType;
Expand Down Expand Up @@ -64,7 +63,7 @@ public void lookupFieldNames_undeclaredMessageType() {
CelTypeProvider celTypeProvider = new ProtoMessageTypeProvider();
ProtoTypeMaskTypeProvider protoTypeMaskProvider =
new ProtoTypeMaskTypeProvider(celTypeProvider, ImmutableList.of());
Truth8.assertThat(protoTypeMaskProvider.findType(ATTRIBUTE_CONTEXT_TYPE)).isEmpty();
assertThat(protoTypeMaskProvider.findType(ATTRIBUTE_CONTEXT_TYPE)).isEmpty();
}

@Test
Expand Down Expand Up @@ -206,7 +205,7 @@ public void lookupFieldType() {
.addPaths("request.auth.*")
.build())));
ProtoMessageType ctxType = assertTypeFound(protoTypeMaskProvider, ATTRIBUTE_CONTEXT_TYPE);
Truth8.assertThat(ctxType.findField("resource")).isPresent();
assertThat(ctxType.findField("resource")).isPresent();
assertTypeHasFieldWithType(ctxType, "resource", RESOURCE_TYPE);
assertTypeHasFieldWithType(ctxType, "request", REQUEST_TYPE);

Expand Down Expand Up @@ -238,7 +237,7 @@ public void lookupFieldType_notExposedField() {
"google.rpc.context.AttributeContext",
FieldMask.newBuilder().addPaths("resource.name").build())));
ProtoMessageType resourceType = assertTypeFound(protoTypeMaskProvider, RESOURCE_TYPE);
Truth8.assertThat(resourceType.findField("type")).isEmpty();
assertThat(resourceType.findField("type")).isEmpty();
}

@Test
Expand All @@ -252,12 +251,12 @@ public void lookupType_notExposed() {
ProtoTypeMask.of(
"google.rpc.context.AttributeContext",
FieldMask.newBuilder().addPaths("resource.name").build())));
Truth8.assertThat(protoTypeMaskProvider.findType(REQUEST_TYPE)).isPresent();
assertThat(protoTypeMaskProvider.findType(REQUEST_TYPE)).isPresent();
}

private ProtoMessageType assertTypeFound(CelTypeProvider celTypeProvider, String typeName) {
Optional<CelType> foundType = celTypeProvider.findType(typeName);
Truth8.assertThat(foundType).isPresent();
assertThat(foundType).isPresent();
CelType celType = foundType.get();
assertThat(celType).isInstanceOf(ProtoMessageType.class);
return (ProtoMessageType) celType;
Expand All @@ -271,7 +270,7 @@ private void assertTypeHasFields(ProtoMessageType protoType, ImmutableSet<String

private void assertTypeHasFieldWithType(
ProtoMessageType protoType, String fieldName, String typeName) {
Truth8.assertThat(protoType.findField(fieldName)).isPresent();
assertThat(protoType.findField(fieldName)).isPresent();
assertThat(protoType.findField(fieldName).get().type().name()).isEqualTo(typeName);
}
}
Loading

0 comments on commit 8f51c97

Please sign in to comment.