本文整理汇总了Java中com.google.common.truth.StringSubject类的典型用法代码示例。如果您正苦于以下问题:Java StringSubject类的具体用法?Java StringSubject怎么用?Java StringSubject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringSubject类属于com.google.common.truth包,在下文中一共展示了StringSubject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generatesTemplateThat
import com.google.common.truth.StringSubject; //导入依赖的package包/类
StringSubject generatesTemplateThat() {
generateCode();
if (fileNode.numChildren() != 1) {
fail("expected to only have 1 template: " + fileNode.getChildren());
}
TemplateNode template = fileNode.getChild(0);
// we know that 'file' contains exactly one template. so find it.
int functionIndex = file.indexOf("function(");
int startOfFunction = file.substring(0, functionIndex).lastIndexOf('\n') + 1;
int endOfFunction = file.lastIndexOf("}\n") + 2; // +2 to capture the \n
// if it is a delegate function we want to include the registration code which is a single
// statement after the end of the template
if (template instanceof TemplateDelegateNode) {
endOfFunction = file.indexOf(";\n", endOfFunction) + 2;
}
// if we are generating jsdoc we want to capture that too
String templateBody;
int startOfJsDoc = file.substring(0, startOfFunction).lastIndexOf("/**");
templateBody = file.substring(startOfJsDoc, endOfFunction);
return check()
.withMessage("Unexpected template body generated for %s:", actual())
.that(templateBody);
}
示例2: testToString
import com.google.common.truth.StringSubject; //导入依赖的package包/类
@Test
void testToString() {
Error objectUnderTest = new Error();
objectUnderTest.setSourceIdentifier("sourceID");
objectUnderTest.setDetails(Collections.singletonList(Detail.forErrorCode(ErrorCode.UNEXPECTED_ERROR)));
objectUnderTest.setType("aType");
objectUnderTest.setMessage("coolMessage");
StringSubject subject = assertWithMessage("Must contain formatted string")
.that(objectUnderTest.toString());
subject.contains(String.valueOf(objectUnderTest.getSourceIdentifier()));
subject.contains(String.valueOf(objectUnderTest.getDetails()));
subject.contains(String.valueOf(objectUnderTest.getType()));
subject.contains(String.valueOf(objectUnderTest.getMessage()));
}
示例3: is_used_as_default_applicationClass
import com.google.common.truth.StringSubject; //导入依赖的package包/类
@Test public void is_used_as_default_applicationClass() throws Exception {
project.named("test").buildWithArguments("assemble");
Execution original = ExecutableJar.at(project.file("build/libs/test.jar")).run();
Execution capsule = CapsuleJar.at(project.file("build/libs/test-capsule.jar")).run();
assertThat(original).succeeded();
StringSubject capsuleOutput = assertThat(capsule).succeededAnd().standardOutput();
capsuleOutput.isNotEmpty();
capsuleOutput.isEqualTo(original.output);
}
示例4: hasLogAtLevelWithMessage
import com.google.common.truth.StringSubject; //导入依赖的package包/类
public Which<StringSubject> hasLogAtLevelWithMessage(Level level, String message) {
List<String> messagesAtLevel = getMessagesAtLevel(level);
check()
.withMessage("Logs at level %s", level)
.that(messagesAtLevel)
.comparingElementsUsing(CONTAINS_CORRESPONDENCE)
.contains(message);
for (String messageCandidate : messagesAtLevel) {
if (messageCandidate.contains(message)) {
return new Which<>(assertThat(messageCandidate)
.named(String.format("log message at %s matching '%s'", level, message)));
}
}
throw new AssertionError("Message check passed yet matching message not found");
}
示例5: textSymbolFile
import com.google.common.truth.StringSubject; //导入依赖的package包/类
@NonNull
public StringSubject textSymbolFile() throws IOException {
InputStream stream = getInputStream("R.txt");
return new StringSubject(failureStrategy,
CharStreams.toString(new InputStreamReader(stream, Charsets.UTF_8)));
}
示例6: asString
import com.google.common.truth.StringSubject; //导入依赖的package包/类
public StringSubject asString() throws IOException {
isNotNull();
// We shouldn't close the BinaryResult within this method as it might still
// be used afterwards. Besides, closing it doesn't have an effect for most
// implementations of a BinaryResult.
BinaryResult binaryResult = actual();
return Truth.assertThat(binaryResult.asString());
}
示例7: checkTopic
import com.google.common.truth.StringSubject; //导入依赖的package包/类
private void checkTopic(Result change, @Nullable String topic) throws RestApiException {
ChangeInfo info = gApi.changes().id(change.getChangeId()).get();
StringSubject t = assertThat(info.topic).named("topic");
if (topic != null) {
t.isEqualTo(topic);
} else {
t.isNull();
}
}
示例8: assertThatSourceString
import com.google.common.truth.StringSubject; //导入依赖的package包/类
private static StringSubject assertThatSourceString(TemplateNode node) {
SoyFileNode parent = node.getParent().copy(new CopyState());
new DesugarHtmlNodesPass().run(parent, new IncrementingIdGenerator());
StringBuilder sb = new StringBuilder();
parent.getChild(0).appendSourceStringForChildren(sb);
return assertThat(sb.toString());
}
示例9: contentsAsString
import com.google.common.truth.StringSubject; //导入依赖的package包/类
/**
* 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()
.that(JavaFileObjects.asByteSource(actual()).asCharSource(charset).read())
.named("the contents of " + actualAsString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例10: standardError
import com.google.common.truth.StringSubject; //导入依赖的package包/类
public StringSubject standardError() {
return Truth.assertThat(actual().error);
}
示例11: standardOutput
import com.google.common.truth.StringSubject; //导入依赖的package包/类
public StringSubject standardOutput() {
return Truth.assertThat(actual().output);
}
示例12: assertThat
import com.google.common.truth.StringSubject; //导入依赖的package包/类
public static StringSubject assertThat(@Nullable String target) {
return assert_().that(target);
}
示例13: diagnosticStream
import com.google.common.truth.StringSubject; //导入依赖的package包/类
StringSubject diagnosticStream() {
String[] parseResult = parse();
return assertThat(parseResult[1]);
}
示例14: commonLines
import com.google.common.truth.StringSubject; //导入依赖的package包/类
public ListSubject<StringSubject, String> commonLines() {
isNotNull();
ContentEntry contentEntry = actual();
return ListSubject.assertThat(contentEntry.ab, Truth::assertThat).named("common lines");
}
示例15: linesOfA
import com.google.common.truth.StringSubject; //导入依赖的package包/类
public ListSubject<StringSubject, String> linesOfA() {
isNotNull();
ContentEntry contentEntry = actual();
return ListSubject.assertThat(contentEntry.a, Truth::assertThat).named("lines of 'a'");
}