/** * Given a factory for some {@code Subject} class, returns a builder whose {@code that(actual)} * method creates instances of that class. */ public static <S extends Subject<S, T>, T> SimpleSubjectBuilder<S, T> assertAbout( Subject.Factory<S, T> factory) { return assert_().about(factory); }
/** * A generic, advanced method of extension of Truth to new types, which is documented on {@link * CustomSubjectBuilder}. Extension creators should prefer {@link Subject.Factory} if possible. */ public static <CustomSubjectBuilderT extends CustomSubjectBuilder> CustomSubjectBuilderT assertAbout( CustomSubjectBuilder.Factory<CustomSubjectBuilderT> factory) { return assert_().about(factory); }
@Override public void invokeAssertion(StandardSubjectBuilder whenTesting) { assertionCallback.invokeAssertion(whenTesting.about(factory)); } });
/** Fails if the multimap is not empty. */ @CanIgnoreReturnValue public Ordered containsExactly() { return check().about(iterableEntries()).that(actual().entries()).containsExactly(); }
private IterableSubject iterableSubject() { return checkNoNeedToDisplayBothValues("asList()") .about(iterablesWithCustomFloatToString()) .that(Floats.asList(actual())); }
private IterableSubject iterableSubject() { return checkNoNeedToDisplayBothValues("asList()") .about(iterablesWithCustomDoubleToString()) .that(Doubles.asList(actual())); }
/** * Returns a context-aware {@link Subject} for making assertions about the values for the given * key within the {@link Multimap}. * * <p>This method performs no checks on its own and cannot cause test failures. Subsequent * assertions must be chained onto this method call to test properties of the {@link Multimap}. */ public IterableOfProtosSubject<?, M, Iterable<M>> valuesForKey(@NullableDecl Object key) { Subject.Factory<IterableValuesForKey<M>, Iterable<M>> factory = iterableOfProtos( "Values for key <" + key + "> (<" + actual() + ">) in " + actualAsString()); return check().about(factory).that(((Multimap<Object, M>) actual()).get(key)); }
/** * Fails if the map does not contain exactly the keys in the given multimap, mapping to values * that correspond to the values of the given multimap. * * <p>A subsequent call to {@link Ordered#inOrder} may be made if the caller wishes to verify * that the two Multimaps iterate fully in the same order. That is, their key sets iterate in * the same order, and the corresponding value collections for each key iterate in the same * order. */ @CanIgnoreReturnValue public <K, V extends E> Ordered containsExactlyEntriesIn(Multimap<K, V> expectedMultimap) { // Note: The non-fuzzy MultimapSubject.containsExactlyEntriesIn has a custom implementation // and produces somewhat better failure messages simply asserting about the iterables of // entries would: it formats the expected values as k=[v1, v2] rather than k=v1, k=v2; and in // the case where inOrder() fails it says the keys and/or the values for some keys are out of // order. We don't bother with that here. It would be nice, but it would be a lot of added // complexity for little gain. return check() .about(iterableEntries()) .that(actual().entries()) .comparingElementsUsing(new EntryCorrespondence<K, A, V>(correspondence)) .containsExactlyElementsIn(expectedMultimap.entries()); }
ProtoSubject<?, Message> usingConfig(FluentEqualityConfig newConfig) { MessageSubject newSubject = check().about(MessageSubject.messages(newConfig)).that(actual()); if (internalCustomName() != null) { newSubject = newSubject.named(internalCustomName()); } return newSubject; }
MultimapWithProtoValuesFluentAssertion<M> usingConfig(FluentEqualityConfig newConfig) { Subject.Factory<MultimapWithMessageValuesSubject<K, M>, Multimap<K, M>> factory = multimapWithMessageValues(newConfig); MultimapWithMessageValuesSubject<K, M> newSubject = check().about(factory).that(actual()); if (internalCustomName() != null) { newSubject = newSubject.named(internalCustomName()); } return new MultimapWithProtoValuesFluentAssertionImpl<>(newSubject); }
MapWithProtoValuesFluentAssertion<M> usingConfig(FluentEqualityConfig newConfig) { Subject.Factory<MapWithMessageValuesSubject<K, M>, Map<K, M>> factory = mapWithProtoValues(newConfig); MapWithMessageValuesSubject<K, M> newSubject = check().about(factory).that(actual()); if (internalCustomName() != null) { newSubject = newSubject.named(internalCustomName()); } return new MapWithProtoValuesFluentAssertionImpl<>(newSubject); }
IterableOfProtosFluentAssertion<M> usingConfig(FluentEqualityConfig newConfig) { Subject.Factory<IterableOfMessagesSubject<M>, Iterable<M>> factory = iterableOfMessages(newConfig); IterableOfMessagesSubject<M> newSubject = check().about(factory).that(actual()); if (internalCustomName() != null) { newSubject = newSubject.named(internalCustomName()); } return new IterableOfProtosFluentAssertionImpl<M>(newSubject); }
public PointerCoordsEqualitySubject historicalPointerCoords(int pointerIndex, int pos) { PointerCoords outPointerCoords = new PointerCoords(); actual().getHistoricalPointerCoords(pointerIndex, pos, outPointerCoords); return check("getHistoricalPointerCoords(%s, %s)", pointerIndex, pos) .about(PointerCoordsEqualitySubject.pointerCoords()) .that(outPointerCoords); }
public PointerCoordsEqualitySubject pointerCoords(int pointerIndex) { PointerCoords outPointerCoords = new PointerCoords(); actual().getPointerCoords(pointerIndex, outPointerCoords); return check("getPointerCoords(%s)", pointerIndex) .about(PointerCoordsEqualitySubject.pointerCoords()) .that(outPointerCoords); }
public ZipEntrySubject hasFile(String filePath) { ZipEntry zipEntry = actual().getEntry(filePath); if (zipEntry == null) { failWithoutActual("contains a file with path \"" + filePath + "\""); } return check().about(ZipEntrySubject.zipEntries(actual())).that(zipEntry); }
private void doCompile(TestProcessor processor) throws Exception { assert_().about(javaSources()).that(testSourceFiles()).withCompilerOptions("-Aextension.version=1.0.0-dev") .processedWith(processor).compilesWithoutError(); }
@CanIgnoreReturnValue @Override public T withWarningCount(int warningCount) { check().about(compilations()).that(compilation).hadWarningCount(warningCount); return thisObject(); }
@CanIgnoreReturnValue public T withErrorCount(int errorCount) { check().about(compilations()).that(compilation).hadErrorCount(errorCount); return thisObject(); }
@CanIgnoreReturnValue @Override public FileClause<T> withNoteContaining(String messageFragment) { return new FileBuilder( check().about(compilations()).that(compilation).hadNoteContaining(messageFragment)); }
@CanIgnoreReturnValue @Override public UnsuccessfulCompilationClause failsToCompile() { Compilation compilation = compilation(); check().about(compilations()).that(compilation).failed(); return new UnsuccessfulCompilationBuilder(compilation); }