Skip to content

Commit

Permalink
Migrate ProtoTruthDelegatedVerb.java from old *Verb* classes to new *…
Browse files Browse the repository at this point in the history
…SubjectBuilder* classes.

This migration does not change any behavior.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167729956
  • Loading branch information
JiangJi authored and cpovirk committed Sep 6, 2017
1 parent 62228cd commit 3c8eaca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
Expand Up @@ -16,82 +16,78 @@


package com.google.common.truth.extensions.proto; package com.google.common.truth.extensions.proto;


import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap; import com.google.common.collect.SetMultimap;
import com.google.common.truth.AbstractDelegatedVerb; import com.google.common.truth.CustomSubjectBuilder;
import com.google.common.truth.DelegatedVerbFactory; import com.google.common.truth.CustomSubjectBuilderFactory;
import com.google.common.truth.FailureStrategy; import com.google.common.truth.FailureStrategy;
import com.google.protobuf.Message; import com.google.protobuf.Message;
import com.google.protobuf.MessageLite; import com.google.protobuf.MessageLite;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;


/** /**
* Custom {@link AbstractDelegatedVerb} which aggregates all Proto-related {@link * {@link CustomSubjectBuilder} which aggregates all Proto-related {@link
* com.google.common.truth.Subject} classes into a single place. * com.google.common.truth.Subject} classes into a single place.
* *
* <p>To obtain an instance, call {@code assertAbout(ProtoTruth.protos())}. * <p>To obtain an instance, call {@code assertAbout(ProtoTruth.protos())}.
*/ */
public final class ProtoTruthDelegatedVerb extends AbstractDelegatedVerb { public final class ProtoSubjectBuilder extends CustomSubjectBuilder {


/** Factory for ProtoTruthDelegatedVerb. */ /** Factory for ProtoSubjectBuilder. */
private static class Factory implements DelegatedVerbFactory<ProtoTruthDelegatedVerb> { private static class Factory implements CustomSubjectBuilderFactory<ProtoSubjectBuilder> {
private static final Factory INSTANCE = new Factory(); private static final Factory INSTANCE = new Factory();


@Override @Override
public ProtoTruthDelegatedVerb createVerb(FailureStrategy failureStrategy) { public ProtoSubjectBuilder createSubjectBuilder(FailureStrategy failureStrategy) {
return new ProtoTruthDelegatedVerb(failureStrategy); return new ProtoSubjectBuilder(failureStrategy);
} }
} }


static DelegatedVerbFactory<ProtoTruthDelegatedVerb> factory() { static CustomSubjectBuilderFactory<ProtoSubjectBuilder> factory() {
return Factory.INSTANCE; return Factory.INSTANCE;
} }


private final FailureStrategy failureStrategy; private ProtoSubjectBuilder(FailureStrategy failureStrategy) {

super(failureStrategy);
private ProtoTruthDelegatedVerb(FailureStrategy failureStrategy) {
this.failureStrategy = checkNotNull(failureStrategy);
} }


public LiteProtoSubject<?, MessageLite> that(@Nullable MessageLite messageLite) { public LiteProtoSubject<?, MessageLite> that(@Nullable MessageLite messageLite) {
return new LiteProtoSubject.MessageLiteSubject(failureStrategy, messageLite); return new LiteProtoSubject.MessageLiteSubject(failureStrategy(), messageLite);
} }


public ProtoSubject<?, Message> that(@Nullable Message message) { public ProtoSubject<?, Message> that(@Nullable Message message) {
return new ProtoSubject.MessageSubject(failureStrategy, message); return new ProtoSubject.MessageSubject(failureStrategy(), message);
} }


public <M extends Message> IterableOfProtosSubject<?, M, Iterable<M>> that( public <M extends Message> IterableOfProtosSubject<?, M, Iterable<M>> that(
@Nullable Iterable<M> messages) { @Nullable Iterable<M> messages) {
return new IterableOfProtosSubject.IterableOfMessagesSubject<M>(failureStrategy, messages); return new IterableOfProtosSubject.IterableOfMessagesSubject<M>(failureStrategy(), messages);
} }


public <K, M extends Message> MapWithProtoValuesSubject<?, K, M, Map<K, M>> that( public <K, M extends Message> MapWithProtoValuesSubject<?, K, M, Map<K, M>> that(
@Nullable Map<K, M> map) { @Nullable Map<K, M> map) {
return new MapWithProtoValuesSubject.MapWithMessageValuesSubject<K, M>(failureStrategy, map); return new MapWithProtoValuesSubject.MapWithMessageValuesSubject<K, M>(failureStrategy(), map);
} }


public <K, M extends Message> MultimapWithProtoValuesSubject<?, K, M, Multimap<K, M>> that( public <K, M extends Message> MultimapWithProtoValuesSubject<?, K, M, Multimap<K, M>> that(
@Nullable Multimap<K, M> map) { @Nullable Multimap<K, M> map) {
return new MultimapWithProtoValuesSubject.MultimapWithMessageValuesSubject<K, M>( return new MultimapWithProtoValuesSubject.MultimapWithMessageValuesSubject<K, M>(
failureStrategy, map); failureStrategy(), map);
} }


public <K, M extends Message> public <K, M extends Message>
ListMultimapWithProtoValuesSubject<?, K, M, ListMultimap<K, M>> that( ListMultimapWithProtoValuesSubject<?, K, M, ListMultimap<K, M>> that(
@Nullable ListMultimap<K, M> map) { @Nullable ListMultimap<K, M> map) {
return new ListMultimapWithProtoValuesSubject.ListMultimapWithMessageValuesSubject<K, M>( return new ListMultimapWithProtoValuesSubject.ListMultimapWithMessageValuesSubject<K, M>(
failureStrategy, map); failureStrategy(), map);
} }


public <K, M extends Message> SetMultimapWithProtoValuesSubject<?, K, M, SetMultimap<K, M>> that( public <K, M extends Message> SetMultimapWithProtoValuesSubject<?, K, M, SetMultimap<K, M>> that(
@Nullable SetMultimap<K, M> map) { @Nullable SetMultimap<K, M> map) {
return new SetMultimapWithProtoValuesSubject.SetMultimapWithMessageValuesSubject<K, M>( return new SetMultimapWithProtoValuesSubject.SetMultimapWithMessageValuesSubject<K, M>(
failureStrategy, map); failureStrategy(), map);
} }


} }
Expand Up @@ -21,12 +21,10 @@
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap; import com.google.common.collect.SetMultimap;
import com.google.common.truth.AbstractVerb; import com.google.common.truth.CustomSubjectBuilderFactory;
import com.google.common.truth.DelegatedVerbFactory;
import com.google.common.truth.IterableSubject; import com.google.common.truth.IterableSubject;
import com.google.common.truth.MapSubject; import com.google.common.truth.MapSubject;
import com.google.common.truth.MultimapSubject; import com.google.common.truth.MultimapSubject;
import com.google.common.truth.SubjectFactory;
import com.google.protobuf.Message; import com.google.protobuf.Message;
import com.google.protobuf.MessageLite; import com.google.protobuf.MessageLite;
import java.util.Map; import java.util.Map;
Expand All @@ -36,18 +34,18 @@
* A set of static methods to begin a Truth assertion chain for protocol buffers. * A set of static methods to begin a Truth assertion chain for protocol buffers.
* *
* <p>Note: Usage of different failure strategies such as <em>assume</em> and <em>expect</em> should * <p>Note: Usage of different failure strategies such as <em>assume</em> and <em>expect</em> should
* rely on {@link AbstractVerb#about(SubjectFactory)} to begin a chain with those alternative * rely on {@link CustomSubjectBuilderFactory#about(CustomSubjectBuilderFactory)} to begin a chain
* behaviors. * with those alternative behaviors.
*/ */
public final class ProtoTruth { public final class ProtoTruth {


/** /**
* Returns a {@link DelegatedVerbFactory}, akin to a {@link * Returns a {@link CustomSubjectBuilderFactory}, akin to a {@link
* com.google.common.truth.SubjectFactory}, which can be used to assert on multiple types of * com.google.common.truth.SubjectFactory}, which can be used to assert on multiple types of
* Protos and collections containing them. * Protos and collections containing them.
*/ */
public static DelegatedVerbFactory<ProtoTruthDelegatedVerb> protos() { public static CustomSubjectBuilderFactory<ProtoSubjectBuilder> protos() {
return ProtoTruthDelegatedVerb.factory(); return ProtoSubjectBuilder.factory();
} }


/** Assert on a single {@link MessageLite} instance. */ /** Assert on a single {@link MessageLite} instance. */
Expand Down

0 comments on commit 3c8eaca

Please sign in to comment.