com.google.common.truth.StringSubject Java Examples

The following examples show how to use com.google.common.truth.StringSubject. 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
Source File: JavaFileObjectSubject.java    From compile-testing with 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 #2
Source File: ModuleSubject.java    From js-dossier with 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 #3
Source File: EncodableProcessorTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@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 #4
Source File: LogsSubject.java    From nomulus with 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 #5
Source File: VerifyElement.java    From coteafs-selenium with Apache License 2.0 4 votes vote down vote up
@Override
public StringSubject verifyText() {
    return assertThat(text());
}
 
Example #6
Source File: AndroidDataConverterTest.java    From bazel with Apache License 2.0 4 votes vote down vote up
private static StringSubject assertMap(AndroidDataConverter<String> converter) {
  return assertThat(converter.map(TO_MAP));
}
 
Example #7
Source File: NotificationActionSubject.java    From android-test with 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 #8
Source File: NotificationSubject.java    From android-test with 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 #9
Source File: BundleSubject.java    From android-test with 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 #10
Source File: ProgramSubject.java    From clutz with MIT License 4 votes vote down vote up
StringSubject diagnosticStream() {
  String[] parseResult = parse();
  return assertThat(parseResult[1]);
}
 
Example #11
Source File: GoogleLoggerTest.java    From flogger with 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 #12
Source File: ScreenAction.java    From coteafs-selenium with Apache License 2.0 4 votes vote down vote up
@Override
public StringSubject verifyTitle () {
    return assertThat (title ());
}
 
Example #13
Source File: AlertAction.java    From coteafs-selenium with 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 #14
Source File: VerifyElement.java    From coteafs-selenium with Apache License 2.0 4 votes vote down vote up
@Override
public StringSubject verifyAttribute(final String attribute) {
    return assertThat(attribute(attribute));
}
 
Example #15
Source File: IDriverActions.java    From coteafs-selenium with Apache License 2.0 2 votes vote down vote up
/**
 * @return string subject
 * @author Wasiq Bhamla
 * @since 08-Jun-2019
 */
StringSubject verifyTitle();
 
Example #16
Source File: IAlertAction.java    From coteafs-selenium with 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 #17
Source File: IVerifyElement.java    From coteafs-selenium with Apache License 2.0 2 votes vote down vote up
/**
 * @author Wasiq Bhamla
 * @since 07-Jun-2019
 * @return subject
 */
StringSubject verifyText ();
 
Example #18
Source File: IVerifyElement.java    From coteafs-selenium with 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 #19
Source File: JavaFileObjectSubject.java    From compile-testing with 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);
}