Java Code Examples for com.google.common.truth.StringSubject

The following examples show how to use com.google.common.truth.StringSubject. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void compile_withNestedAutoValueInSamePackage_shouldRegisterGeneratedSubclass() {
  Compilation result =
      javac()
          .withProcessors(new AutoValueProcessor(), new EncodableProcessor())
          .compile(
              JavaFileObjects.forSourceLines(
                  "Foo",
                  "import com.google.firebase.encoders.annotations.Encodable;",
                  "import com.google.auto.value.AutoValue;",
                  "@Encodable @AutoValue public abstract class Foo {",
                  "public abstract Bar getBar();",
                  "@AutoValue public abstract static class Bar {",
                  "public abstract Baz getBaz();",
                  "@AutoValue public abstract static class Baz {",
                  "public abstract String getField();",
                  "}",
                  "}",
                  "}"));

  StringSubject compiled =
      assertThat(result).generatedSourceFile("AutoFooEncoder").contentsAsUtf8String();

  compiled.contains("cfg.registerEncoder(AutoValue_Foo.class");
  compiled.contains("cfg.registerEncoder(AutoValue_Foo_Bar.class");
  compiled.contains("cfg.registerEncoder(AutoValue_Foo_Bar_Baz.class");
}
 
Example 2
Source Project: nomulus   Source File: LogsSubject.java    License: Apache License 2.0 5 votes vote down vote up
public Which<StringSubject> hasLogAtLevelWithMessage(Level level, String message) {
  List<String> messagesAtLevel = getMessagesAtLevel(level);
  check("atLevel(%s)", level)
      .that(messagesAtLevel)
      .comparingElementsUsing(CONTAINS_CORRESPONDENCE)
      .contains(message);
  for (String messageCandidate : messagesAtLevel) {
    if (messageCandidate.contains(message)) {
      return new Which<>(
          assertWithMessage(String.format("log message at %s matching '%s'", level, message))
              .that(messageCandidate));
    }
  }
  throw new AssertionError("Message check passed yet matching message not found");
}
 
Example 3
Source Project: js-dossier   Source File: ModuleSubject.java    License: Apache License 2.0 5 votes vote down vote up
public StringSubject hasJsdocCommentThat() {
  Truth.assertThat(actual()).isNotNull();
  JSDocInfo info = actual().getJsDoc().getInfo();
  assertWithMessage("%s does not have jsdoc", actual()).that(info).isNotNull();
  return Truth.assertThat(info.getOriginalCommentString())
      .named("%s jsdoc comment", internalCustomName());
}
 
Example 4
Source Project: compile-testing   Source File: JavaFileObjectSubject.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link StringSubject} that makes assertions about the contents of the actual file as
 * a string.
 */
public StringSubject contentsAsString(Charset charset) {
  try {
    return check("contents()")
        .that(JavaFileObjects.asByteSource(actual).asCharSource(charset).read());
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 5
Source Project: coteafs-selenium   Source File: VerifyElement.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StringSubject verifyAttribute(final String attribute) {
    return assertThat(attribute(attribute));
}
 
Example 6
Source Project: coteafs-selenium   Source File: VerifyElement.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StringSubject verifyText() {
    return assertThat(text());
}
 
Example 7
Source Project: coteafs-selenium   Source File: AlertAction.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StringSubject verifyAlertMessage(final AlertDecision decision) {
    final String actual = alert(decision);
    return assertThat(actual);
}
 
Example 8
Source Project: coteafs-selenium   Source File: ScreenAction.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StringSubject verifyTitle () {
    return assertThat (title ());
}
 
Example 9
Source Project: flogger   Source File: GoogleLoggerTest.java    License: Apache License 2.0 4 votes vote down vote up
StringSubject assertOnlyLog() {
  assertThat(logRecords).hasSize(1);
  LogRecord logRecord = logRecords.get(0);
  flush();
  return assertThat(logRecordToString(logRecord));
}
 
Example 10
Source Project: clutz   Source File: ProgramSubject.java    License: MIT License 4 votes vote down vote up
StringSubject diagnosticStream() {
  String[] parseResult = parse();
  return assertThat(parseResult[1]);
}
 
Example 11
Source Project: android-test   Source File: BundleSubject.java    License: Apache License 2.0 4 votes vote down vote up
public StringSubject string(String key) {
  return check("getString(%s)", key).that(actual.getString(key));
}
 
Example 12
Source Project: android-test   Source File: NotificationSubject.java    License: Apache License 2.0 4 votes vote down vote up
public final StringSubject tickerText() {
  return check("tickerText")
      .that(actual.tickerText != null ? actual.tickerText.toString() : null);
}
 
Example 13
Source Project: android-test   Source File: NotificationActionSubject.java    License: Apache License 2.0 4 votes vote down vote up
public final StringSubject title() {
  return check("title").that(actual.title != null ? actual.title.toString() : null);
}
 
Example 14
Source Project: bazel   Source File: AndroidDataConverterTest.java    License: Apache License 2.0 4 votes vote down vote up
private static StringSubject assertMap(AndroidDataConverter<String> converter) {
  return assertThat(converter.map(TO_MAP));
}
 
Example 15
Source Project: coteafs-selenium   Source File: IVerifyElement.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * @author Wasiq Bhamla
 * @since 07-Jun-2019
 * @param attribute element attribute
 * @return subject
 */
StringSubject verifyAttribute (final String attribute);
 
Example 16
Source Project: coteafs-selenium   Source File: IVerifyElement.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * @author Wasiq Bhamla
 * @since 07-Jun-2019
 * @return subject
 */
StringSubject verifyText ();
 
Example 17
Source Project: coteafs-selenium   Source File: IAlertAction.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * @author Wasiq Bhamla
 * @since 06-Jun-2019
 * @param decision alert decision
 * @return string subject
 */
StringSubject verifyAlertMessage (AlertDecision decision);
 
Example 18
Source Project: coteafs-selenium   Source File: IDriverActions.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * @return string subject
 * @author Wasiq Bhamla
 * @since 08-Jun-2019
 */
StringSubject verifyTitle();
 
Example 19
Source Project: compile-testing   Source File: JavaFileObjectSubject.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns a {@link StringSubject} that makes assertions about the contents of the actual file as
 * a UTF-8 string.
 */
public StringSubject contentsAsUtf8String() {
  return contentsAsString(UTF_8);
}